123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../../app/nls/StringResources', '../../../../lib/@waca/dashboard-common/dist/ui/interaction/Utils', 'jquery', 'underscore', '../../../../lib/@waca/dashboard-common/dist/utils/DialogBlocker', '../../../../dashboard/glass/util/InstrumentationUtil', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', './api/DeleteActionAPI'], function (stringResources, Utils, $, _, DialogBlocker, InstrumentationUtil, APIFactory, ContentActionsProviderAPI, DeleteActionAPI) {
- var DeleteAction = function () {
- function DeleteAction(_ref) {
- var _this = this;
- var features = _ref.features;
- _classCallCheck(this, DeleteAction);
- if (features) {
- this.dashboard = features.API;
- this._icons = features.Icons;
- features.ContentActions.registerProvider('delete', this.getAPI());
- }
- this.id = _.uniqueId('id');
- this.dashboard.getCanvasWhenReady().then(function (canvas) {
- _this.canvas = canvas;
- canvas.on('change:selections:select', _this.onContentSelectionChange, _this);
- canvas.on('change:selections:deselect', _this.onContentSelectionChange, _this);
- });
- }
- DeleteAction.prototype.getAPI = function getAPI() {
- if (!this._api) {
- this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI, DeleteActionAPI]);
- }
- return this._api;
- };
- DeleteAction.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
- return [{
- name: 'post:dashboard.initialize',
- action: this.postDashboardInitialize.bind(this)
- }];
- };
- DeleteAction.prototype.postDashboardInitialize = function postDashboardInitialize() {
- if (this.dashboard) {
- this.transactionApi = this.dashboard.getFeature('Transaction');
- this.controller = this.dashboard.getFeature('InteractionController.internal');
- }
- return Promise.resolve();
- };
- DeleteAction.prototype.destroy = function destroy() {
- if (this.canvas) {
- this.canvas.off('change:selections:select', this.onContentSelectionChange, this);
- this.canvas.off('change:selections:deselect', this.onContentSelectionChange, this);
- this.canvas = null;
- }
- this._deRegisterEvent();
- this.dashboard = null;
- this.controller = null;
- this.id = null;
- };
- DeleteAction.prototype.getNodes = function getNodes(idList) {
- return Utils.getNodes(this.controller, idList);
- };
- DeleteAction.prototype._isEnabled = function _isEnabled(idList) {
- return idList.length && this.dashboard.getMode() === this.dashboard.MODES.EDIT;
- };
- DeleteAction.prototype.getContentActionList = function getContentActionList(idList) {
- if (this._isEnabled(idList)) {
- return [{
- name: 'delete',
- label: stringResources.get('toolbarActionDelete'),
- icon: this._icons.getIcon('dashboard-delete').id,
- type: 'Button',
- actions: {
- apply: this.deleteContent.bind(this, idList)
- }
- }];
- }
- return [];
- };
- DeleteAction.prototype.onContentSelectionChange = function onContentSelectionChange() {
- var idList = this.canvas.getSelectedContentList().map(function (content) {
- return content.getId();
- });
- // TODO: The fix is temporary until we have an API to allow disabling features.
- var applyInteraction = this.dashboard.getAppConfig('interactions');
- if (applyInteraction && applyInteraction.delete === false) {
- return;
- }
- this._deRegisterEvent();
- if (this._isEnabled(idList)) {
- $('html').on('keyup.interactionDeleteKey' + this.id, this.deleteKeyPress.bind(this, idList));
- }
- };
- DeleteAction.prototype._deRegisterEvent = function _deRegisterEvent() {
- $('html').off('keyup.interactionDeleteKey' + this.id);
- };
- DeleteAction.prototype.deleteKeyPress = function deleteKeyPress(idList, e) {
- var target = e.srcElement || e.target;
- // If the event is triggered in an input/text area do not delete items i.e. Filter dialogue on widgets
- if (target.tagName.toLowerCase().match(/input|textarea|select/igm)) {
- return;
- }
- // If the event is triggered on the element within slot editor, we do not handle it
- if (this._elementIsInSlotEditor(target)) {
- return;
- }
- if (!e.ctrlKey && (e.keyCode === 46 || e.keyCode === 8) && !DialogBlocker.isShowingDialogBlocker()) {
- return this.deleteContent(idList);
- }
- };
- DeleteAction.prototype._elementIsInSlotEditor = function _elementIsInSlotEditor(e) {
- // All of the elements in slot editor have the common parent of SlotEditor
- return e.closest('.slotEditor');
- };
- DeleteAction.prototype.setOnBeforeDeleteCallback = function setOnBeforeDeleteCallback(callback) {
- this.onBeforeDeleteCallback = callback;
- };
- /**
- * Delete the selected items for the board layout
- * @param {String[]} idList Array of model id list.
- */
- DeleteAction.prototype.deleteContent = function deleteContent(idList) {
- var _this2 = this;
- // it is possible that we are receiving the delete key from a different view.
- // make sure that we only delete if the view element is visible.
- if (this.controller.$el.is(':visible')) {
- var widgetId = void 0;
- var deleteIDs = [];
- var ungroupedNodesList = [];
- var transactionToken = this.transactionApi.startTransaction();
- var undoRedoTransactionId = transactionToken.transactionId;
- // A delete operation might include ungrouping an item if we are delete an item that is part of a group.
- // In order to group all these in one undo action, we need to create a transaction id and pass it along.
- if (this.onBeforeDeleteCallback) {
- ungroupedNodesList = this.onBeforeDeleteCallback({ 'currentSelection': idList, 'undoRedoTransactionId': undoRedoTransactionId, 'transactionToken': transactionToken });
- } else {
- ungroupedNodesList = this.getNodes(idList);
- }
- for (var i = 0; i < ungroupedNodesList.length; i++) {
- widgetId = this.controller.layoutController.nodeIdToModelId(ungroupedNodesList[i].id);
- deleteIDs.push(widgetId);
- InstrumentationUtil.trackWidget('deleted', this.dashboard, null, widgetId);
- if (ungroupedNodesList[i]._layout && ungroupedNodesList[i]._layout.widgetChromeEventRouter) {
- ungroupedNodesList[i]._layout.widgetChromeEventRouter.trigger('widget:onDeleteAction', { 'data': { 'undoRedoTransactionId': undoRedoTransactionId, 'transactionToken': transactionToken } });
- }
- }
- this.controller.selectionHandler.deselectAll();
- deleteIDs.forEach(function (id) {
- _this2.dashboard.getCanvas().removeContent(id, transactionToken);
- });
- return this._deleteAfter({ ids: deleteIDs, undoRedoTransactionId: undoRedoTransactionId }, transactionToken);
- }
- };
- DeleteAction.prototype._deleteAfter = function _deleteAfter(payload, transactionToken) {
- var _this3 = this;
- return this.dashboard.getFeature('.LifeCycleManager').invokeLifeCycleHandlers('post:widget.delete', payload).then(function () {
- _this3.transactionApi.endTransaction(transactionToken);
- return _this3.controller.onSelectionDelete();
- });
- };
- return DeleteAction;
- }();
- return DeleteAction;
- });
- //# sourceMappingURL=DeleteAction.js.map
|