123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /**
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: BI
- *
- * Copyright IBM Corp. 2017, 2019
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * @file Controller to handle lasso related logic such as: lasso activation,
- * lasso co-oridinate provision etc.
- */
- 'use strict';
- define(['../../../lib/@waca/core-client/js/core-client/ui/core/Events', './LassoSelectView', 'dashboard-analytics/DynamicFileLoader'], function (Events, LassoSelectView, DynamicFileLoader) {
- var LassoController = Events.extend({
- /**
- * @param {Object} options.targetElement element (jquery)
- */
- init: function init(options) {
- var _views;
- LassoController.inherited('init', this, arguments);
- this.targetElement = options.targetElement;
- this.cordinateResolver = options.cordinateResolver;
- this.isDragging = options.isDragging;
- this._views = (_views = {}, _views[LassoController.DEFAULT_VIEW_ID] = { promise: Promise.resolve([LassoSelectView]), id: LassoController.DEFAULT_VIEW_ID }, _views); //Default view
- this.dashboard = options.dashboard;
- this._loadViewExts();
- },
- _loadViewExts: function _loadViewExts() {
- var _this = this;
- this.dashboard && this.dashboard.getCollectionExtension('com.ibm.bi.dashboard.live-lassoView').then(function (views) {
- return views.forEach(function (view) {
- return _this._views[view.id] = { promise: DynamicFileLoader.load([view.class]), css: view.css, id: view.id };
- });
- });
- },
- _loadCss: function _loadCss(href) {
- var head = document.getElementsByTagName('head')[0];
- var stylesheet = head.querySelectorAll('[href=\'' + href + '\']');
- if (!stylesheet.length) {
- var link = document.createElement('link');
- link.rel = 'stylesheet';
- link.type = 'text/css';
- link.href = href;
- link.media = 'all';
- head.appendChild(link);
- }
- },
- /**
- * Activate/Deactivate lasso selection mode
- * @param {boolean} [state=false] - state of lasso mode. True activates and
- * false deactivates the lasso mode. Defaults to false.
- */
- activateLassoMode: function activateLassoMode(state, viewId) {
- var _this2 = this;
- var _state = state || false;
- if (_state) {
- var _ref = this._views[viewId] || this._views[LassoController.DEFAULT_VIEW_ID],
- promise = _ref.promise,
- css = _ref.css,
- id = _ref.id;
- this.viewId = id;
- if (css) {
- this._loadCss(css);
- }
- return promise.then(function (modules) {
- _this2.view = new modules[0](_this2.targetElement, _this2.cordinateResolver, _this2.isDragging);
- _this2.view.on('all', _this2._handleViewEvent, _this2);
- });
- } else if (this.isLassoMode()) {
- this.view.off('all', this._handleViewEvent, this);
- this.view.remove();
- this.view = null;
- this.viewId = '';
- }
- return Promise.resolve();
- },
- /**
- * @return True if lasso mode is active, false otherwise.
- */
- isLassoMode: function isLassoMode() {
- return !!this.viewId;
- },
- /**
- * Handler view event
- */
- _handleViewEvent: function _handleViewEvent(payload, eventName) {
- this.trigger(eventName, payload);
- },
- getCoordinates: function getCoordinates() {
- return this.view && this.view.getCoordinates();
- },
- getCurrentViewId: function getCurrentViewId() {
- return this.viewId;
- },
- remove: function remove() {
- this.activateLassoMode(false);
- LassoController.inherited('remove', this, arguments);
- this.targetElement = null;
- }
- });
- LassoController.DEFAULT_VIEW_ID = 'lw-lasso-select';
- return LassoController;
- });
- //# sourceMappingURL=LassoController.js.map
|