From 0d6ab2808cdddf91423df461d279c653ff1c9d65 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 22 May 2020 17:55:35 +0300 Subject: [PATCH] [PE][SSE] Add parameters to api customization: macros, plugins, macrosMode --- .../main/app/controller/Main.js | 1 - .../main/app/controller/Main.js | 48 ++++++++++++++++++- .../main/app/view/FileMenuPanels.js | 38 ++++++++++++++- .../main/app/controller/Main.js | 48 ++++++++++++++++++- .../main/app/view/FileMenuPanels.js | 38 ++++++++++++++- 5 files changed, 168 insertions(+), 5 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 0ce06a80a..bc6e3a90f 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -2276,7 +2276,6 @@ define([ } } }); - } } }, diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index ca3c069e6..791ad1feb 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -342,6 +342,14 @@ define([ $('#editor-container').append('
'); } + var value = Common.localStorage.getItem("pe-macros-mode"); + if (value === null) { + value = this.editorConfig.customization ? this.editorConfig.customization.macrosMode : 'warn'; + value = (value == 'enable') ? 1 : (value == 'disable' ? 2 : 0); + } else + value = parseInt(value); + Common.Utils.InternalSettings.set("pe-macros-mode", value); + Common.Controllers.Desktop.init(this.appOptions); }, @@ -373,10 +381,16 @@ define([ docInfo.put_Token(data.doc.token); docInfo.put_Permissions(_permissions); docInfo.put_EncryptedInfo(this.editorConfig.encryptionKeys); + + var enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); + docInfo.asc_putIsEnabledMacroses(!!enable); + enable = !this.editorConfig.customization || (this.editorConfig.customization.plugins!==false); + docInfo.asc_putIsEnabledPlugins(!!enable); } this.api.asc_registerCallback('asc_onGetEditorPermissions', _.bind(this.onEditorPermissions, this)); this.api.asc_registerCallback('asc_onLicenseChanged', _.bind(this.onLicenseChanged, this)); + this.api.asc_registerCallback('asc_onRunAutostartMacroses', _.bind(this.onRunAutostartMacroses, this)); this.api.asc_setDocInfo(docInfo); this.api.asc_getEditorPermissions(this.editorConfig.licenseUrl, this.editorConfig.customerId); @@ -1883,6 +1897,36 @@ define([ }}); }, + onRunAutostartMacroses: function() { + var me = this, + enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); + if (enable) { + var value = Common.Utils.InternalSettings.get("pe-macros-mode"); + if (value==1) + this.api.asc_runAutostartMacroses(); + else if (value === 0) { + Common.UI.warning({ + msg: this.textHasMacros + '
', + buttons: ['yes', 'no'], + primary: 'yes', + dontshow: true, + textDontShow: this.textRemember, + callback: function(btn, dontshow){ + if (dontshow) { + Common.Utils.InternalSettings.set("pe-macros-mode", (btn == 'yes') ? 1 : 2); + Common.localStorage.setItem("pe-macros-mode", (btn == 'yes') ? 1 : 2); + } + if (btn == 'yes') { + setTimeout(function() { + me.api.asc_runAutostartMacroses(); + }, 1); + } + } + }); + } + } + }, + // Translation leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', criticalErrorTitle: 'Error', @@ -2234,7 +2278,9 @@ define([ textCustomLoader: 'Please note that according to the terms of the license you are not entitled to change the loader.
Please contact our Sales Department to get a quote.', waitText: 'Please, wait...', errorFileSizeExceed: 'The file size exceeds the limitation set for your server.
Please contact your Document Server administrator for details.', - errorUpdateVersionOnDisconnect: 'Internet connection has been restored, and the file version has been changed.
Before you can continue working, you need to download the file or copy its content to make sure nothing is lost, and then reload this page.' + errorUpdateVersionOnDisconnect: 'Internet connection has been restored, and the file version has been changed.
Before you can continue working, you need to download the file or copy its content to make sure nothing is lost, and then reload this page.', + textHasMacros: 'The file contains automatic macros.
Do you want to run macros?', + textRemember: 'Remember my choice' } })(), PE.Controllers.Main || {})) }); diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index 1a9277247..870f34df9 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -208,6 +208,12 @@ define([ '', '', '','', + '', + '', + '', + '
', + '
', + '','', '', '', '', @@ -331,6 +337,21 @@ define([ ] }); + this.cmbMacros = new Common.UI.ComboBox({ + el : $markup.findById('#fms-cmb-macros'), + style : 'width: 160px;', + editable : false, + cls : 'input-group-nr', + data : [ + { value: 2, displayValue: this.txtStopMacros, descValue: this.txtStopMacrosDesc }, + { value: 0, displayValue: this.txtWarnMacros, descValue: this.txtWarnMacrosDesc }, + { value: 1, displayValue: this.txtRunMacros, descValue: this.txtRunMacrosDesc } + ] + }).on('selected', function(combo, record) { + me.lblMacrosDesc.text(record.descValue); + }); + this.lblMacrosDesc = $markup.findById('#fms-lbl-macros'); + this.btnApply = new Common.UI.Button({ el: $markup.findById('#fms-btn-apply') }); @@ -367,6 +388,7 @@ define([ /** coauthoring begin **/ $('tr.coauth.changes', this.el)[mode.isEdit && !mode.isOffline && mode.canCoAuthoring ? 'show' : 'hide'](); /** coauthoring end **/ + $('tr.macros', this.el)[(mode.customization && mode.customization.macros===false) ? 'hide' : 'show'](); }, updateSettings: function() { @@ -409,6 +431,10 @@ define([ } this.chAlignGuides.setValue(Common.Utils.InternalSettings.get("pe-settings-showsnaplines")); + + item = this.cmbMacros.store.findWhere({value: Common.Utils.InternalSettings.get("pe-macros-mode")}); + this.cmbMacros.setValue(item ? item.get('value') : 0); + this.lblMacrosDesc.text(item ? item.get('descValue') : this.txtWarnMacrosDesc); }, applySettings: function() { @@ -430,6 +456,9 @@ define([ Common.localStorage.setItem("pe-settings-forcesave", this.chForcesave.isChecked() ? 1 : 0); Common.Utils.InternalSettings.set("pe-settings-showsnaplines", this.chAlignGuides.isChecked()); + Common.localStorage.setItem("pe-macros-mode", this.cmbMacros.getValue()); + Common.Utils.InternalSettings.set("pe-macros-mode", Common.localStorage.getItem("pe-macros-mode")); + Common.localStorage.save(); if (this.menu) { @@ -484,7 +513,14 @@ define([ strForcesave: 'Always save to server (otherwise save to server on document close)', txtSpellCheck: 'Spell Checking', strSpellCheckMode: 'Turn on spell checking option', - txtCacheMode: 'Default cache mode' + txtCacheMode: 'Default cache mode', + strMacrosSettings: 'Macros Settings', + txtWarnMacros: 'Show Notification', + txtRunMacros: 'Enable All', + txtStopMacros: 'Disable All', + txtWarnMacrosDesc: 'Disable all macros with notification', + txtRunMacrosDesc: 'Enable all macros without notification', + txtStopMacrosDesc: 'Disable all macros without notification' }, PE.Views.FileMenuPanels.Settings || {})); PE.Views.FileMenuPanels.RecentFiles = Common.UI.BaseView.extend({ diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 2d716ff0b..01212cb3b 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -390,6 +390,14 @@ define([ $('#editor_sdk').append('
' + '
'.repeat(2) + '
'); } + var value = Common.localStorage.getItem("sse-macros-mode"); + if (value === null) { + value = this.editorConfig.customization ? this.editorConfig.customization.macrosMode : 'warn'; + value = (value == 'enable') ? 1 : (value == 'disable' ? 2 : 0); + } else + value = parseInt(value); + Common.Utils.InternalSettings.set("sse-macros-mode", value); + this.isFrameClosed = (this.appOptions.isEditDiagram || this.appOptions.isEditMailMerge); Common.Controllers.Desktop.init(this.appOptions); }, @@ -422,6 +430,11 @@ define([ docInfo.put_Permissions(_permissions); docInfo.put_EncryptedInfo(this.editorConfig.encryptionKeys); + var enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); + docInfo.asc_putIsEnabledMacroses(!!enable); + enable = !this.editorConfig.customization || (this.editorConfig.customization.plugins!==false); + docInfo.asc_putIsEnabledPlugins(!!enable); + this.headerView && this.headerView.setDocumentCaption(data.doc.title); Common.Utils.InternalSettings.set("sse-doc-info-key", data.doc.key); @@ -429,6 +442,7 @@ define([ this.api.asc_registerCallback('asc_onGetEditorPermissions', _.bind(this.onEditorPermissions, this)); this.api.asc_registerCallback('asc_onLicenseChanged', _.bind(this.onLicenseChanged, this)); + this.api.asc_registerCallback('asc_onRunAutostartMacroses', _.bind(this.onRunAutostartMacroses, this)); this.api.asc_setDocInfo(docInfo); this.api.asc_getEditorPermissions(this.editorConfig.licenseUrl, this.editorConfig.customerId); }, @@ -2183,6 +2197,36 @@ define([ }}); }, + onRunAutostartMacroses: function() { + var me = this, + enable = !this.editorConfig.customization || (this.editorConfig.customization.macros!==false); + if (enable) { + var value = Common.Utils.InternalSettings.get("sse-macros-mode"); + if (value==1) + this.api.asc_runAutostartMacroses(); + else if (value === 0) { + Common.UI.warning({ + msg: this.textHasMacros + '
', + buttons: ['yes', 'no'], + primary: 'yes', + dontshow: true, + textDontShow: this.textRemember, + callback: function(btn, dontshow){ + if (dontshow) { + Common.Utils.InternalSettings.set("sse-macros-mode", (btn == 'yes') ? 1 : 2); + Common.localStorage.setItem("sse-macros-mode", (btn == 'yes') ? 1 : 2); + } + if (btn == 'yes') { + setTimeout(function() { + me.api.asc_runAutostartMacroses(); + }, 1); + } + } + }); + } + } + }, + leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', criticalErrorTitle: 'Error', notcriticalErrorTitle: 'Warning', @@ -2548,7 +2592,9 @@ define([ txtRowLbls: 'Row Labels', txtColLbls: 'Column Labels', errNoDuplicates: 'No duplicate values found.', - errRemDuplicates: 'Duplicate values found and deleted: {0}, unique values left: {1}.' + errRemDuplicates: 'Duplicate values found and deleted: {0}, unique values left: {1}.', + textHasMacros: 'The file contains automatic macros.
Do you want to run macros?', + textRemember: 'Remember my choice' } })(), SSE.Controllers.Main || {})) }); diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index 61385ae5d..848719a1b 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -667,6 +667,12 @@ define([ '', '
', '','', + '', + '', + '', + '
', + '
', + '','', '', '', '', @@ -897,6 +903,21 @@ define([ var $thousandsSeparatorInput = this.inputThousandsSeparator.$el.find('input'); $thousandsSeparatorInput.on('keydown', keyDown); + this.cmbMacros = new Common.UI.ComboBox({ + el : $markup.findById('#fms-cmb-macros'), + style : 'width: 160px;', + editable : false, + cls : 'input-group-nr', + data : [ + { value: 2, displayValue: this.txtStopMacros, descValue: this.txtStopMacrosDesc }, + { value: 0, displayValue: this.txtWarnMacros, descValue: this.txtWarnMacrosDesc }, + { value: 1, displayValue: this.txtRunMacros, descValue: this.txtRunMacrosDesc } + ] + }).on('selected', function(combo, record) { + me.lblMacrosDesc.text(record.descValue); + }); + this.lblMacrosDesc = $markup.findById('#fms-lbl-macros'); + this.btnApply = new Common.UI.Button({ el: $markup.findById('#fms-btn-apply') }); @@ -932,6 +953,7 @@ define([ $('tr.forcesave', this.el)[mode.canForcesave ? 'show' : 'hide'](); $('tr.comments', this.el)[mode.canCoAuthoring ? 'show' : 'hide'](); $('tr.coauth.changes', this.el)[mode.isEdit && !mode.isOffline && mode.canCoAuthoring? 'show' : 'hide'](); + $('tr.macros', this.el)[(mode.customization && mode.customization.macros===false) ? 'hide' : 'show'](); }, setApi: function(api) { @@ -1016,6 +1038,10 @@ define([ } else { this.$el.find('.label-separator').removeClass('disabled'); } + + item = this.cmbMacros.store.findWhere({value: Common.Utils.InternalSettings.get("sse-macros-mode")}); + this.cmbMacros.setValue(item ? item.get('value') : 0); + this.lblMacrosDesc.text(item ? item.get('descValue') : this.txtWarnMacrosDesc); }, applySettings: function() { @@ -1056,6 +1082,9 @@ define([ Common.localStorage.setBool("sse-settings-use-base-separator", isChecked); Common.Utils.InternalSettings.set("sse-settings-use-base-separator", isChecked); + Common.localStorage.setItem("sse-macros-mode", this.cmbMacros.getValue()); + Common.Utils.InternalSettings.set("sse-macros-mode", Common.localStorage.getItem("sse-macros-mode")); + Common.localStorage.save(); if (this.menu) { this.menu.fireEvent('settings:apply', [this.menu]); @@ -1150,7 +1179,14 @@ define([ strUseSeparatorsBasedOnRegionalSettings: 'Use separators based on regional settings', strDecimalSeparator: 'Decimal separator', strThousandsSeparator: 'Thousands separator', - txtCacheMode: 'Default cache mode' + txtCacheMode: 'Default cache mode', + strMacrosSettings: 'Macros Settings', + txtWarnMacros: 'Show Notification', + txtRunMacros: 'Enable All', + txtStopMacros: 'Disable All', + txtWarnMacrosDesc: 'Disable all macros with notification', + txtRunMacrosDesc: 'Enable all macros without notification', + txtStopMacrosDesc: 'Disable all macros without notification' }, SSE.Views.FileMenuPanels.MainSettingsGeneral || {})); SSE.Views.FileMenuPanels.MainSpellCheckSettings = Common.UI.BaseView.extend(_.extend({