diff --git a/apps/common/main/lib/component/LayoutManager.js b/apps/common/main/lib/component/LayoutManager.js new file mode 100644 index 000000000..599903aea --- /dev/null +++ b/apps/common/main/lib/component/LayoutManager.js @@ -0,0 +1,97 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2021 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ +/** + * LayoutManager.js + * + * Created by Julia Radzhabova on 06.10.2021 + * Copyright (c) 2021 Ascensio System SIA. All rights reserved. + * + */ + + +if (Common === undefined) + var Common = {}; + +if (Common.UI === undefined) { + Common.UI = {}; +} + +Common.UI.LayoutManager = new(function() { + var _config; + var _init = function(config) { + _config = config; + }; + + var _applyCustomization = function(config, el, prefix) { + !config && (config = _config); + if (!config) return; + + for (var name in config) { + if(config.hasOwnProperty(name)) { + if(typeof config[name] === 'object') + _applyCustomization(config[name], el, name + '-'); + else if (config[name] === false) { + var selector = '[data-layout-name=' + (prefix || '') + name + ']', + cmp = el ? el.find(selector) : $(selector); + cmp && cmp.hide && cmp.hide(); + } + } + } + }; + + var _isElementVisible = function(value, config, prefix) { + !config && (config = _config); + if (!config) return true; + + var res = true; + for (var name in config) { + if(config.hasOwnProperty(name)) { + if(typeof config[name] === 'object') + res = _isElementVisible(value, config[name], (prefix || '') + name + '-'); + else { + if (value === (prefix || '') + name) { // checked value is in config + res = config[name]; + } + } + if (res===false) return res; + } + } + return res; + }; + + return { + init: _init, + applyCustomization: _applyCustomization, + isElementVisible: _isElementVisible + } +})(); \ No newline at end of file diff --git a/apps/common/main/lib/controller/Plugins.js b/apps/common/main/lib/controller/Plugins.js index 1513fc2cd..d53ad2b73 100644 --- a/apps/common/main/lib/controller/Plugins.js +++ b/apps/common/main/lib/controller/Plugins.js @@ -63,7 +63,7 @@ define([ var appOptions = me.getApplication().getController('Main').appOptions; if ( !appOptions.isEditMailMerge && !appOptions.isEditDiagram ) { - var tab = {action: 'plugins', caption: me.panelPlugins.groupCaption}; + var tab = {action: 'plugins', caption: me.panelPlugins.groupCaption, layoutname: 'toolbar-plugins'}; me.$toolbarPanelPlugins = me.panelPlugins.getPanel(); toolbar.addTab(tab, me.$toolbarPanelPlugins, 10); // TODO: clear plugins list in left panel @@ -219,7 +219,7 @@ define([ }); this.api.asc_pluginsRegister('', arr); if (storePlugins.hasVisible()) - Common.NotificationCenter.trigger('tab:visible', 'plugins', true); + Common.NotificationCenter.trigger('tab:visible', 'plugins', Common.UI.LayoutManager.isElementVisible('toolbar-plugins')); Common.Gateway.pluginsReady(); }, diff --git a/apps/common/main/lib/view/Protection.js b/apps/common/main/lib/view/Protection.js index 603d5bf13..f9b22360a 100644 --- a/apps/common/main/lib/view/Protection.js +++ b/apps/common/main/lib/view/Protection.js @@ -207,7 +207,7 @@ define([ }) ); } - Common.NotificationCenter.trigger('tab:visible', 'protect', true); + Common.NotificationCenter.trigger('tab:visible', 'protect', Common.UI.LayoutManager.isElementVisible('toolbar-protect')); } setEvents.call(me); diff --git a/apps/common/main/lib/view/ReviewChanges.js b/apps/common/main/lib/view/ReviewChanges.js index 0ca680301..39ecfd081 100644 --- a/apps/common/main/lib/view/ReviewChanges.js +++ b/apps/common/main/lib/view/ReviewChanges.js @@ -646,7 +646,7 @@ define([ if (!me.btnHistory && separator_last) me.$el.find(separator_last).hide(); - Common.NotificationCenter.trigger('tab:visible', 'review', config.isEdit || config.canViewReview || config.canCoAuthoring && config.canComments); + Common.NotificationCenter.trigger('tab:visible', 'review', (config.isEdit || config.canViewReview || config.canCoAuthoring && config.canComments) && Common.UI.LayoutManager.isElementVisible('toolbar-collaboration')); setEvents.call(me); }); diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 4c076978e..f3af140bf 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -53,7 +53,8 @@ define([ 'common/main/lib/util/LocalStorage', 'documenteditor/main/app/collection/ShapeGroups', 'documenteditor/main/app/collection/EquationGroups', - 'common/main/lib/component/HintManager' + 'common/main/lib/component/HintManager', + 'common/main/lib/component/LayoutManager' ], function () { 'use strict'; @@ -1459,6 +1460,7 @@ define([ this.appOptions.canRename && appHeader.setCanRename(true); this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins); this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions, this.api); + this.appOptions.canBrandingExt && this.appOptions.customization && Common.UI.LayoutManager.init(this.appOptions.customization.layout); if (this.appOptions.canComments) Common.NotificationCenter.on('comments:cleardummy', _.bind(this.onClearDummyComment, this)); @@ -2047,6 +2049,7 @@ define([ Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationElements); if (this.appOptions.canBrandingExt) { Common.Utils.applyCustomization(this.appOptions.customization, mapCustomizationExtElements); + Common.UI.LayoutManager.applyCustomization(); promise = this.getApplication().getController('Common.Controllers.Plugins').applyUICustomization(); } } diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 55f5eaef6..0f928307e 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -3184,7 +3184,7 @@ define([ me.toolbar.render(_.extend({isCompactView: compactview}, config)); - var tab = {action: 'review', caption: me.toolbar.textTabCollaboration, layoutname: 'collaboration'}; + var tab = {action: 'review', caption: me.toolbar.textTabCollaboration, layoutname: 'toolbar-collaboration'}; var $panel = me.application.getController('Common.Controllers.ReviewChanges').createToolbarPanel(); if ( $panel ) { me.toolbar.addTab(tab, $panel, 5); @@ -3210,7 +3210,7 @@ define([ if ( config.isDesktopApp ) { if ( config.canProtect ) { - tab = {action: 'protect', caption: me.toolbar.textTabProtect}; + tab = {action: 'protect', caption: me.toolbar.textTabProtect, layoutname: 'toolbar-protect'}; $panel = me.getApplication().getController('Common.Controllers.Protection').createToolbarPanel(); if ($panel) me.toolbar.addTab(tab, $panel, 6); diff --git a/apps/documenteditor/main/app/template/Toolbar.template b/apps/documenteditor/main/app/template/Toolbar.template index f58295e4f..0fab9448c 100644 --- a/apps/documenteditor/main/app/template/Toolbar.template +++ b/apps/documenteditor/main/app/template/Toolbar.template @@ -80,7 +80,7 @@
-
+
@@ -124,7 +124,7 @@
-
+
@@ -146,7 +146,7 @@
-
+
diff --git a/apps/documenteditor/main/app/view/Toolbar.js b/apps/documenteditor/main/app/view/Toolbar.js index 02d7b0212..d7238664b 100644 --- a/apps/documenteditor/main/app/view/Toolbar.js +++ b/apps/documenteditor/main/app/view/Toolbar.js @@ -109,11 +109,11 @@ define([ Common.UI.Mixtbar.prototype.initialize.call(this, { template: _.template(template), tabs: [ - {caption: me.textTabFile, action: 'file', extcls: 'canedit', layoutname: 'file', haspanel:false}, {caption: me.textTabHome, action: 'home', extcls: 'canedit', layoutname: 'home'}, - {caption: me.textTabInsert, action: 'ins', extcls: 'canedit', layoutname: 'insert'}, - {caption: me.textTabLayout, action: 'layout', extcls: 'canedit', layoutname: 'layout'}, - {caption: me.textTabLinks, action: 'links', extcls: 'canedit', layoutname: 'references'} + {caption: me.textTabFile, action: 'file', extcls: 'canedit', layoutname: 'toolbar-file', haspanel:false}, + {caption: me.textTabInsert, action: 'ins', extcls: 'canedit', layoutname: 'toolbar-insert'}, + {caption: me.textTabLayout, action: 'layout', extcls: 'canedit', layoutname: 'toolbar-layout'}, + {caption: me.textTabLinks, action: 'links', extcls: 'canedit', layoutname: 'toolbar-references'} ] } ); diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index f8d1bbb61..5c47c891d 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -2434,11 +2434,11 @@ define([ } me.toolbar.render(_.extend({compactview: compactview}, config)); - var tab = {action: 'review', caption: me.toolbar.textTabCollaboration}; + var tab = {action: 'review', caption: me.toolbar.textTabCollaboration, layoutname: 'toolbar-collaboration'}; var $panel = me.getApplication().getController('Common.Controllers.ReviewChanges').createToolbarPanel(); if ( $panel ) { me.toolbar.addTab(tab, $panel, 4); - me.toolbar.setVisible('review', config.isEdit || config.canViewReview || config.canCoAuthoring && config.canComments); + me.toolbar.setVisible('review', (config.isEdit || config.canViewReview || config.canCoAuthoring && config.canComments) && Common.UI.LayoutManager.isElementVisible('toolbar-collaboration')); } if ( config.isEdit ) { @@ -2465,7 +2465,7 @@ define([ if ( config.isDesktopApp ) { if ( config.canProtect ) { // don't add protect panel to toolbar - tab = {action: 'protect', caption: me.toolbar.textTabProtect}; + tab = {action: 'protect', caption: me.toolbar.textTabProtect, layoutname: 'toolbar-protect'}; $panel = me.getApplication().getController('Common.Controllers.Protection').createToolbarPanel(); if ($panel) me.toolbar.addTab(tab, $panel, 4); diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 9b29a6259..6b9c4a6f4 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -3706,11 +3706,11 @@ define([ me.toolbar.render(_.extend({isCompactView: compactview}, config)); if ( !config.isEditDiagram && !config.isEditMailMerge ) { - var tab = {action: 'review', caption: me.toolbar.textTabCollaboration}; + var tab = {action: 'review', caption: me.toolbar.textTabCollaboration, layoutname: 'toolbar-collaboration'}; var $panel = me.getApplication().getController('Common.Controllers.ReviewChanges').createToolbarPanel(); if ($panel) { me.toolbar.addTab(tab, $panel, 6); - me.toolbar.setVisible('review', config.isEdit || config.canViewReview || config.canCoAuthoring && config.canComments); + me.toolbar.setVisible('review', (config.isEdit || config.canViewReview || config.canCoAuthoring && config.canComments) && Common.UI.LayoutManager.isElementVisible('toolbar-collaboration')); } } @@ -3746,13 +3746,13 @@ define([ Array.prototype.push.apply(me.toolbar.lockControls, formulatab.getButtons()); if ( config.canFeaturePivot ) { - tab = {action: 'pivot', caption: me.textPivot}; + tab = {action: 'pivot', caption: me.textPivot, layoutname: 'toolbar-pivot'}; var pivottab = me.getApplication().getController('PivotTable'); pivottab.setApi(me.api).setConfig({toolbar: me}); $panel = pivottab.createToolbarPanel(); if ($panel) { me.toolbar.addTab(tab, $panel, 5); - me.toolbar.setVisible('pivot', true); + me.toolbar.setVisible('pivot', Common.UI.LayoutManager.isElementVisible('toolbar-pivot')); Array.prototype.push.apply(me.toolbar.lockControls, pivottab.getView('PivotTable').getButtons()); } } @@ -3769,7 +3769,7 @@ define([ me.toolbar.btnCopy.$el.removeClass('split'); } - var tab = {action: 'protect', caption: me.toolbar.textTabProtect}; + var tab = {action: 'protect', caption: me.toolbar.textTabProtect, layoutname: 'toolbar-protect'}; var $panel = me.getApplication().getController('Common.Controllers.Protection').createToolbarPanel(); if ($panel) { config.canProtect && $panel.append($('
'));