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 @@
-