/* * (c) Copyright Ascensio System SIA 2010-2024 * * 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-6 Ernesta Birznieka-Upish * 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 * */ /** * Date: 17.05.16 */ define([ 'core', 'common/main/lib/collection/Plugins', 'common/main/lib/view/Plugins', 'common/main/lib/component/Switcher' ], function () { 'use strict'; Common.Controllers.Plugins = Backbone.Controller.extend(_.extend({ models: [], appOptions: {}, configPlugins: {autostart:[]},// {config: 'from editor config', plugins: 'loaded plugins', UIplugins: 'loaded customization plugins', autostart: 'autostart guids'} serverPlugins: {autostart:[]},// {config: 'from editor config', plugins: 'loaded plugins', autostart: 'autostart guids'} collections: [ 'Common.Collections.Plugins' ], views: [ 'Common.Views.Plugins' ], initialize: function() { var me = this; this.addListeners({ 'Toolbar': { 'render:before' : function (toolbar) { var appOptions = me.getApplication().getController('Main').appOptions; if ( !appOptions.isEditMailMerge && !appOptions.isEditDiagram && !appOptions.isEditOle ) { var tab = {action: 'plugins', caption: me.viewPlugins.groupCaption, dataHintTitle: 'E', layoutname: 'toolbar-plugins'}; me.$toolbarPanelPlugins = me.viewPlugins.getPanel(); me.toolbar = toolbar; toolbar.addTab(tab, me.$toolbarPanelPlugins, Common.UI.LayoutManager.lastTabIdx); // TODO: clear plugins list in left panel } }, 'tab:active': this.onActiveTab }, 'Common.Views.Plugins': { 'plugin:select': function(guid, type, isRun, closePanel) { if (!this.viewPlugins.pluginPanels[guid] || (this.viewPlugins.pluginPanels[guid] && type > 0)) { !isRun || type > 0 ? me.api.asc_pluginRun(guid, type, '') : me.api.asc_pluginStop(guid); } else { closePanel ? me.onToolClose(this.viewPlugins.pluginPanels[guid]) : me.openUIPlugin(guid); } } }, 'LeftMenu': { 'plugins:showpanel': function (guid) { me.viewPlugins.showPluginPanel(true, guid); }, 'plugins:hidepanel': function (guid) { me.viewPlugins.showPluginPanel(false, guid); } }, 'RightMenu': { 'plugins:showpanel': function (guid) { me.viewPlugins.showPluginPanel(true, guid); }, 'plugins:hidepanel': function (guid) { me.viewPlugins.showPluginPanel(false, guid); } } }); }, onLaunch: function() { var store = this.getApplication().getCollection('Common.Collections.Plugins'); this.viewPlugins= this.createView('Common.Views.Plugins', { storePlugins: store }); store.on({ add: this.onAddPlugin.bind(this), reset: this.onResetPlugins.bind(this) }); this.autostart = []; this.pluginsWinToShow = []; this.startOnPostLoad = false; this.customPluginsDlg = []; this.newInstalledBackgroundPlugins = []; this.customButtonsArr = []; Common.Gateway.on('init', this.loadConfig.bind(this)); Common.NotificationCenter.on('app:face', this.onAppShowed.bind(this)); Common.NotificationCenter.on('uitheme:changed', this.updatePluginsButtons.bind(this)); Common.NotificationCenter.on('window:resize', this.updatePluginsButtons.bind(this)); Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); Common.NotificationCenter.on('doc:mode-changed', this.onChangeDocMode.bind(this)); Common.NotificationCenter.on('modal:close', this.onModalClose.bind(this)); Common.NotificationCenter.on('script:loaded', this.onPostLoadComplete.bind(this)); }, loadConfig: function(data) { var me = this; me.configPlugins.config = data.config.plugins; me.editor = !!window.PDFE ? 'pdf' : !!window.DE ? 'word' : !!window.PE ? 'slide' : !!window.VE ? 'diagram' : 'cell'; me.isPDFEditor = !!window.PDFE; }, loadPlugins: function() { this.configPlugins.plugins = this.serverPlugins.plugins = undefined; if (this.configPlugins.config) { this.getPlugins(this.configPlugins.config.pluginsData) .then(function(loaded) { me.configPlugins.plugins = loaded; me.mergePlugins(); }) .catch(function(err) { me.configPlugins.plugins = false; }); if (this.configPlugins.config.options) this.api.setPluginsOptions(this.configPlugins.config.options); } else this.configPlugins.plugins = false; if ( !Common.Controllers.Desktop.isActive() || !Common.Controllers.Desktop.isOffline() ) { var server_plugins_url = '../../../../plugins.json', me = this; Common.Utils.loadConfig(server_plugins_url, function (obj) { if (obj != 'error') { me.serverPlugins.config = obj; me.getPlugins(me.serverPlugins.config.pluginsData) .then(function (loaded) { me.serverPlugins.plugins = loaded; me.mergePlugins(); }) .catch(function (err) { me.serverPlugins.plugins = false; }); } else me.serverPlugins.plugins = false; }); } }, onAppShowed: function (config) { }, onAppReady: function (config) { var me = this; (new Promise(function (accept, reject) { accept(); })).then(function(){ me.onChangeProtectDocument(); Common.NotificationCenter.on('protect:doclock', _.bind(me.onChangeProtectDocument, me)); }); }, setApi: function(api) { this.api = api; if (!this.appOptions.customization || (this.appOptions.customization.plugins!==false)) { this.api.asc_registerCallback("asc_onPluginShow", _.bind(this.onPluginShow, this)); this.api.asc_registerCallback("asc_onPluginClose", _.bind(this.onPluginClose, this)); this.api.asc_registerCallback("asc_onPluginResize", _.bind(this.onPluginResize, this)); this.api.asc_registerCallback('asc_onPluginsReset', _.bind(this.resetPluginsList, this)); this.api.asc_registerCallback('asc_onPluginsInit', _.bind(this.onPluginsInit, this)); this.api.asc_registerCallback('asc_onPluginShowButton', _.bind(this.onPluginShowButton, this)); this.api.asc_registerCallback('asc_onPluginHideButton', _.bind(this.onPluginHideButton, this)); this.api.asc_registerCallback("asc_onPluginWindowShow", _.bind(this.onApiPluginWindowShow, this)); this.api.asc_registerCallback("asc_onPluginWindowClose", _.bind(this.onPluginWindowClose, this)); this.api.asc_registerCallback("asc_onPluginWindowResize", _.bind(this.onPluginWindowResize, this)); this.api.asc_registerCallback("asc_onPluginWindowActivate", _.bind(this.openUIPlugin, this)); this.loadPlugins(); } return this; }, setMode: function(mode, api) { this.appOptions = mode; this.api = api; this.customPluginsComplete = !this.appOptions.canBrandingExt; if (this.appOptions.canBrandingExt) this.getAppCustomPlugins(this.configPlugins); return this; }, onAfterRender: function(panel, guid, isActivated) { var me = this; isActivated && this.openUIPlugin(guid); panel.pluginClose.on('click', _.bind(this.onToolClose, this, panel)); panel.pluginHide && panel.pluginHide.on('click', _.bind(this.onToolHide, this, panel)); Common.NotificationCenter.on({ 'layout:resizestart': function(e) { if (panel) { panel.enablePointerEvents && panel.enablePointerEvents(false); me.api.asc_pluginEnableMouseEvents(true); } }, 'layout:resizestop': function(e){ if (panel) { panel.enablePointerEvents && panel.enablePointerEvents(true); me.api.asc_pluginEnableMouseEvents(false); } } }); }, refreshPluginsList: function() { var me = this; var storePlugins = this.getApplication().getCollection('Common.Collections.Plugins'), arr = []; storePlugins.each(function(item){ var plugin = new Asc.CPlugin(); plugin.deserialize(item.get('original')); item.set('pluginObj', plugin); arr.push(plugin); }); this.api.asc_pluginsRegister('', arr); if (storePlugins.hasVisible()) Common.NotificationCenter.trigger('tab:visible', 'plugins', Common.UI.LayoutManager.isElementVisible('toolbar-plugins')); Common.Gateway.pluginsReady(); }, onAddPlugin: function (model) { var me = this; if ( me.$toolbarPanelPlugins ) { var btn = me.viewPlugins.createPluginButton(model); if (!btn) return; var _group = $('> .group', me.$toolbarPanelPlugins); var $slot = $('').appendTo(_group); btn.render($slot); var docProtection = me.viewPlugins._state.docProtection; Common.Utils.lockControls(Common.enumLock.docLockView, docProtection.isReadOnly, {array: btn}); Common.Utils.lockControls(Common.enumLock.docLockForms, docProtection.isFormsOnly, {array: btn}); Common.Utils.lockControls(Common.enumLock.docLockComments, docProtection.isCommentsOnly, {array: btn}); } }, addBackgroundPluginsButton: function (group) { group.appendTo(this.$toolbarPanelPlugins); // append previous button (Plugin Manager) //$('
').appendTo(me.$toolbarPanelPlugins); group = $(''); this.viewPlugins.backgroundBtn = this.viewPlugins.createBackgroundPluginsButton(); var $backgroundSlot = $('').appendTo(group); this.viewPlugins.backgroundBtn.render($backgroundSlot); this.viewPlugins.backgroundBtn.hide(); return group; }, turnOffBackgroundPlugin: function (guid) { if (this.backgroundPluginsSwitchers) { var switcher; this.backgroundPluginsSwitchers.forEach(function (item) { if (item.options.pluginGuid === guid) { switcher = item; } }); if (switcher) { switcher.updateHint(this.viewPlugins.textStart); switcher.setValue(false); return true; } return false; } }, onShowBeforeBackgroundPlugins: function (menu) { var me = this; me.clickInsideMenu = false; var hideActiveMenu = function () { var activeMenu = menu.cmpEl.find('.dropdown-toggle.active'); for (var i=0; i