123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Content Explorer
- *| (C) Copyright IBM Corp. 2015, 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../../lib/@waca/core-client/js/core-client/ui/core/Class', 'underscore', '../../app/util/ErrorUtils'], function (BaseClass, _, ErrorUtils) {
- var defaultEmbeddedUIConfiguration = {
- buttons: {
- 'com.ibm.bi.dashboard.pin': false,
- 'com.ibm.bi.dashboard.customWidget': false,
- 'com.ibm.bi.dashboard.saveMenu': false
- }
- };
- var uiParts = [{
- id: 'navbar'
- }, {
- id: 'appbar'
- }];
- var ButtonHideHelper = BaseClass.extend({
- /**
- Used when changing the mode in which the dashboard
- @param glassContext {object} - the glass context
- @param mode {string} - one of three possible modes: 'authoring', 'consume', 'eventGroups', 'translation'
- **/
- changeMode: function changeMode(glassContext, mode, options) {
- if (this._buttonCollection) {
- this._changeMode(glassContext, mode);
- } else {
- glassContext.appController.findCollection(this._getButtonsCollection(glassContext)).then(function (buttonCollection) {
- this._buttonCollection = buttonCollection;
- this._applyContainerAppButtonConfig(options && options.containerAppOptions);
- this._applyContainerUIPartConfig(options && options.containerAppOptions);
- this._changeMode(glassContext, mode);
- }.bind(this));
- }
- },
- _applyContainerAppButtonConfig: function _applyContainerAppButtonConfig(options) {
- var uiOptions = ((options || {}).configuration || {}).ui || null;
- if (uiOptions) {
- // default non-dashboard buttons added to the dashboard
- var nonDashboardButtons = ['com.ibm.bi.glass.common.home', 'com.ibm.bi.admin.admin', 'com.ibm.bi.glass.common.createMenu', 'com.ibm.bi.share.notifications', 'com.ibm.bi.glass.common.viewSwitcher', 'com.ibm.bi.glass.common.personalMenu', 'com.ibm.bi.dashboard.saveMenu', 'com.ibm.bi.contentApps.myContentFoldersSlideout', 'com.ibm.bi.search.search', 'com.ibm.bi.contentApps.teamFoldersSlideout', 'com.ibm.bi.contentApps.mruSlideout', 'com.ibm.bi.contentApps.myPortalPages'];
- nonDashboardButtons.forEach(function (id) {
- this._buttonCollection.push({
- id: id
- });
- }.bind(this));
- _.each(this._buttonCollection, function (button) {
- // extend any buttons that are configured or needs to hidden by default
- _.extend(button, {
- modes: {
- authoring: {
- visible: this._getButtonVisibility(uiOptions, button, 'authoring', true)
- },
- consume: {
- visible: this._getButtonVisibility(uiOptions, button, 'consume', true)
- },
- eventGroups: {
- visible: this._getButtonVisibility(uiOptions, button, 'eventGroups', true)
- },
- widgetMaximized: {
- visible: this._getButtonVisibility(uiOptions, button, 'widgetMaximized', false)
- },
- translation: {
- visible: this._getButtonVisibility(uiOptions, button, 'translation', true)
- }
- }
- });
- }.bind(this));
- }
- },
- _applyContainerUIPartConfig: function _applyContainerUIPartConfig(options) {
- var uiOptions = ((options || {}).configuration || {}).ui || null;
- if (uiOptions) {
- uiParts.forEach(function (part) {
- _.extend(part, {
- modes: {
- authoring: {
- visible: this._getUISectionVisibility(uiOptions, part.id, 'authoring', true)
- },
- consume: {
- visible: this._getUISectionVisibility(uiOptions, part.id, 'consume', part.id !== 'navbar')
- },
- eventGroups: {
- visible: this._getUISectionVisibility(uiOptions, part.id, 'eventGroups', true)
- },
- translation: {
- visible: this._getUISectionVisibility(uiOptions, part.id, 'translation', true)
- }
- }
- });
- }.bind(this));
- }
- },
- _getUISectionVisibility: function _getUISectionVisibility(uiOptions, id, mode, defaultValue) {
- if (!uiOptions) {
- return {};
- }
- var uiModeProperty = ((uiOptions.modes || {})[mode] || {})[id];
- if (uiModeProperty !== undefined) {
- return uiModeProperty;
- } else if (uiOptions[id] !== undefined) {
- return uiOptions[id];
- }
- return defaultValue;
- },
- _getButtonVisibility: function _getButtonVisibility(uiOptions, button, mode, hideByDefault) {
- var visible = this._getButtonVisibilityFromOptions(uiOptions, button.id, mode);
- if (visible !== null) {
- return visible;
- }
- visible = this._getButtonVisibilityFromOptions(defaultEmbeddedUIConfiguration, button.id, mode);
- if (visible !== null) {
- return visible;
- }
- // If we shouldn't hide by default then set it to undefined and our hide code will ignore this button
- var defaultValue = hideByDefault === true ? false : undefined;
- return ((button.modes || {})[mode] || {}).visible || defaultValue;
- },
- _getButtonVisibilityFromOptions: function _getButtonVisibilityFromOptions(uiOptions, id, mode) {
- if (!uiOptions) {
- return {};
- }
- var modeButtonConfig = (((uiOptions.modes || {})[mode] || {}).buttons || {})[id];
- if (modeButtonConfig !== undefined) {
- return modeButtonConfig;
- }
- var buttonConfig = (uiOptions.buttons || {})[id];
- if (buttonConfig !== undefined) {
- return buttonConfig;
- }
- return null;
- },
- _handleUIPartModeChange: function _handleUIPartModeChange(glassContext, mode) {
- uiParts.forEach(function (part) {
- if (part.modes && part.modes[mode]) {
- glassContext.appController.currentAppView.$('.' + part.id).css('display', part.modes[mode].visible ? '' : 'none');
- }
- });
- },
- _changeMode: function _changeMode(glassContext, mode) {
- if (!this._buttonCollection) {
- console.log('Could not fix the contributed button collection.');
- return;
- }
- if (!glassContext.appController.currentAppView.$('.navbar').hasClass('narrow')) {
- glassContext.appController.currentAppView.$('.navbar').addClass('narrow');
- }
- this._handleUIPartModeChange(glassContext, mode);
- this._buttonCollection.forEach(function (button) {
- var plugin = glassContext.appController.findPlugin(button.id);
- if (!plugin) {
- return;
- }
- if (!this._isDevMode(glassContext) && button.development === true) {
- this._hidePlugin(plugin);
- return;
- }
- if (this._isHideForConsumerMode(glassContext, button.id)) {
- this._hidePlugin(plugin);
- return;
- }
- if (this._isDisabledForConsumerMode(glassContext, button.id)) {
- this._disablePlugin(plugin);
- return;
- }
- var modeInfo = button.modes ? button.modes[mode] : null;
- if (modeInfo) {
- var visible = plugin.hideForever === true ? false : modeInfo.visible;
- this._handleVisibleProperty(visible, plugin);
- this._handleDisabledProperty(modeInfo.disabled, plugin);
- this._handlePressedProperty(modeInfo.pressed, plugin);
- }
- }.bind(this));
- },
- _isHideForConsumerMode: function _isHideForConsumerMode(glassContext, buttonId) {
- // explore and dashboard shares the save button, but dashboard capability should not affect explore user to save exploration
- // TODO: clean this up once explore has their own button contribution
- var appViewType = glassContext.appController.getCurrentContentView().getDashboardApi().getType().toUpperCase();
- var hiddenButtons = ['com.ibm.bi.dashboard.saveMenu', 'com.ibm.bi.dashboard.mode'];
- return hiddenButtons.indexOf(buttonId) !== -1 && appViewType !== 'EXPLORE' ? !ErrorUtils.hasCapability(glassContext, 'canAuthorDashboard') : false;
- },
- _isDisabledForConsumerMode: function _isDisabledForConsumerMode(glassContext, buttonId) {
- var disabledButtons = ['com.ibm.bi.dashboard.mode'];
- return disabledButtons.indexOf(buttonId) !== -1 ? ErrorUtils.hasCapability(glassContext, 'canAuthorDashboard') && !glassContext.appController.getCurrentContentView().canAuthor() && !glassContext.appController.getCurrentContentView().isNew() : false;
- },
- _isDevMode: function _isDevMode(glassContext) {
- if (glassContext.isDevInstall) {
- return glassContext.isDevInstall();
- }
- return false;
- },
- _handleVisibleProperty: function _handleVisibleProperty(visible, plugin) {
- if (visible === true) {
- this._showPlugin(plugin);
- } else if (visible === false) {
- this._hidePlugin(plugin);
- }
- },
- _handleDisabledProperty: function _handleDisabledProperty(disabled, plugin) {
- if (disabled === true) {
- this._disablePlugin(plugin);
- } else if (disabled === false) {
- plugin.enable();
- }
- },
- _handlePressedProperty: function _handlePressedProperty(pressed, plugin) {
- if (pressed === true) {
- plugin.setPressed();
- } else if (pressed === false) {
- plugin.setUnpressed();
- }
- },
- _disablePlugin: function _disablePlugin(plugin) {
- if (plugin) {
- // Make sure any slideouts for the common plugins are hidden when switching modes
- this._actionControllerOnHide(plugin);
- plugin.disable();
- }
- },
- _hidePlugin: function _hidePlugin(plugin) {
- if (plugin) {
- this._actionControllerOnHide(plugin);
- plugin.hide();
- }
- },
- _showPlugin: function _showPlugin(plugin) {
- if (plugin) {
- plugin.enable();
- plugin.show();
- }
- },
- _actionControllerOnHide: function _actionControllerOnHide(plugin) {
- // TODO : the glass should be able to notify the action controller when there is a hide/show/enable/disable
- // Currently there is not way to do that, so we manually call hide on the controller.
- if (plugin && plugin.actionController && plugin.actionController.onHide) {
- plugin.actionController.onHide();
- }
- },
- _getButtonsCollection: function _getButtonsCollection(glassContext) {
- var content = glassContext.appController.currentAppView.getContent();
- return content.options.collections.buttons.id;
- }
- });
- return new ButtonHideHelper();
- });
- //# sourceMappingURL=ButtonHideHelper.js.map
|