'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: Dashboard *| (C) Copyright IBM Corp. 2018, 2019 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['underscore', '../lib/@waca/dashboard-common/dist/ui/AuthoringToolbar', 'jquery'], function (_, Toolbar, $) { var ToolbarHelper = function () { /** * The ToolbarHelper is is designed to hide common jquery authoring toolbar code * for things like the filter dialog or the slot action menu. */ function ToolbarHelper(attributes) { _classCallCheck(this, ToolbarHelper); attributes = attributes || {}; this._cbOnRemove = attributes.cbOnRemove || this._cbOnRemove; } ToolbarHelper.prototype.getToolbar = function getToolbar() { return this._actionMenuToolbar; }; /** * build an action toolbar based on dashboard authoring toolbar class. * @param aActions - the actions to be added to the toolbarRoot * @param parentNode - the parentNode that contains the toolbar. * @param label - a label for the toolbar * @param userOptions - options such as placement and the attachPoint (class of the node where the toolbar will live) */ ToolbarHelper.prototype.buildActionToolbar = function buildActionToolbar(aActions, parentNode, sLabel, userOptions) { var toolbarOptions = _.clone(userOptions); toolbarOptions.textOnly = true; toolbarOptions.container = $('body'); toolbarOptions.notCentered = true; toolbarOptions.popoverClass = 'popover actionToolbarPopover text'; //We expect to find a div with this class under the parent to root the menu at (by default, the className is menuroot ) parentNode = $(parentNode).find(userOptions.attachPoint || '.toolbarRoot'); var toolbar = new Toolbar(toolbarOptions); toolbar.setName(sLabel); toolbar.addItems(aActions); toolbar.setSelectionContext([parentNode]); toolbar.show(toolbarOptions.placement); parentNode.addClass('selected'); var hideToolbar = function hideToolbar() { this._clearToolbar(); setTimeout(this._cbOnRemove.bind(this), 100); }; // This event is triggered only when user clicks away or press Escape to hide the toolbar. // We refresh the UI after that. // Other events like onPopupClose and bspopover.hidden are called when toolbar is changed. toolbar.on('flyout:hide', hideToolbar, this); toolbar.on('toolbar:remove', this._cbOnRemove.bind(this)); this._actionMenuToolbar = toolbar; }; //Default implementation when the toolbar is removed, do nothing. //A user can override this to perform some specific action at remove time in the arguments. ToolbarHelper.prototype._cbOnRemove = function _cbOnRemove() {}; ToolbarHelper.prototype._clearToolbar = function _clearToolbar() { if (this._actionMenuToolbar) { _.each(this._actionMenuToolbar.selectionNodes, function (node) { $(node).removeClass('selected'); }); this._actionMenuToolbar.hide(); this._actionMenuToolbar.remove(); this._actionMenuToolbar = null; } }; return ToolbarHelper; }(); return ToolbarHelper; }); //# sourceMappingURL=ToolbarHelper.js.map