diff --git a/apps/common/main/lib/controller/ReviewChanges.js b/apps/common/main/lib/controller/ReviewChanges.js index 0c2953ccf..1ae06f6b4 100644 --- a/apps/common/main/lib/controller/ReviewChanges.js +++ b/apps/common/main/lib/controller/ReviewChanges.js @@ -1017,7 +1017,7 @@ define([ var wbprotect = this.getApplication().getController('WBProtection'); props = wbprotect ? wbprotect.getWSProps() : null; } - this._state.wsProps = props ? props.wsProps : {}; + this._state.wsProps = props ? props.wsProps : []; this._state.wsLock = props ? props.wsLock : false; if (!this.view) return; diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index 15a11225c..ff1223e9e 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -116,7 +116,7 @@ define([ me._currentMathObj = undefined; me._currentParaObjDisabled = false; me._isDisabled = false; - me._state = {}; + me._state = {wsLock: false, wsProps: []}; me.fastcoauthtips = []; me._TtHeight = 20; /** coauthoring begin **/ diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index f5f43f48a..9764b6f26 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -1389,11 +1389,13 @@ define([ Common.Utils.Metric.setCurrentMetric(value); Common.Utils.InternalSettings.set("sse-settings-unit", value); - if (this.appOptions.isEdit || this.appOptions.isRestrictedEdit) { // set api events for toolbar in the Restricted Editing mode + if (this.appOptions.isRestrictedEdit) { + var toolbarController = application.getController('Toolbar'); + toolbarController && toolbarController.setApi(me.api); + application.getController('WBProtection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api); + } else if (this.appOptions.isEdit) { // set api events for toolbar in the Restricted Editing mode var toolbarController = application.getController('Toolbar'); toolbarController && toolbarController.setApi(me.api); - - if (!this.appOptions.isEdit) return; var statusbarController = application.getController('Statusbar'), rightmenuController = application.getController('RightMenu'), diff --git a/apps/spreadsheeteditor/main/app/controller/RightMenu.js b/apps/spreadsheeteditor/main/app/controller/RightMenu.js index 00bcf8923..a1cf476a0 100644 --- a/apps/spreadsheeteditor/main/app/controller/RightMenu.js +++ b/apps/spreadsheeteditor/main/app/controller/RightMenu.js @@ -54,7 +54,7 @@ define([ initialize: function() { this.editMode = true; - this._state = {}; + this._state = {wsLock: false, wsProps: []}; this.addListeners({ 'Toolbar': { @@ -456,8 +456,10 @@ define([ var wbprotect = this.getApplication().getController('WBProtection'); props = wbprotect ? wbprotect.getWSProps() : null; } - this._state.wsProps = props.wsProps; - this._state.wsLock = props.wsLock; + if (props) { + this._state.wsProps = props.wsProps; + this._state.wsLock = props.wsLock; + } this.onSelectionChanged(this.api.asc_getCellInfo()); } }); diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index e045f7e44..cc434b41b 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -426,9 +426,10 @@ define([ this.api.asc_registerCallback('asc_onUnLockCFManager', _.bind(this.onUnLockCFManager, this)); this.api.asc_registerCallback('asc_onZoomChanged', _.bind(this.onApiZoomChange, this)); Common.NotificationCenter.on('fonts:change', _.bind(this.onApiChangeFont, this)); - } else if (config.isRestrictedEdit) + } else if (config.isRestrictedEdit) { this.api.asc_registerCallback('asc_onSelectionChanged', _.bind(this.onApiSelectionChangedRestricted, this)); - + Common.NotificationCenter.on('protect:wslock', _.bind(this.onChangeProtectSheet, this)); + } }, // onNewDocument: function(btn, e) { @@ -2913,10 +2914,13 @@ define([ }, onApiSelectionChangedRestricted: function(info) { + if (!this.appConfig.isRestrictedEdit) return; + var selectionType = info.asc_getSelectionType(); this.toolbar.lockToolbar(SSE.enumLock.commentLock, (selectionType == Asc.c_oAscSelectionType.RangeCells) && (!info.asc_getComments() || info.asc_getComments().length>0 || info.asc_getLocked()) || this.appConfig && this.appConfig.compatibleFeatures && (selectionType != Asc.c_oAscSelectionType.RangeCells), { array: this.btnsComment }); + this.toolbar.lockToolbar(SSE.enumLock['Objects'], !!this._state.wsProps['Objects'], { array: this.btnsComment }); }, onApiSelectionChanged_DiagramEditor: function(info) { @@ -4065,7 +4069,7 @@ define([ this.toolbar.lockToolbar(SSE.enumLock.wsLock, this._state.wsLock); this.toolbar.lockToolbar(SSE.enumLock['InsertHyperlinks'], this._state.wsProps['InsertHyperlinks'], {array: [this.toolbar.btnInsertHyperlink]}); - this.onApiSelectionChanged(this.api.asc_getCellInfo()); + this.appConfig && this.appConfig.isEdit ? this.onApiSelectionChanged(this.api.asc_getCellInfo()) : this.onApiSelectionChangedRestricted(this.api.asc_getCellInfo()); } }, diff --git a/apps/spreadsheeteditor/main/app/controller/WBProtection.js b/apps/spreadsheeteditor/main/app/controller/WBProtection.js index 9590cbc02..a1e17fbb8 100644 --- a/apps/spreadsheeteditor/main/app/controller/WBProtection.js +++ b/apps/spreadsheeteditor/main/app/controller/WBProtection.js @@ -98,15 +98,16 @@ define([ setMode: function(mode) { this.appConfig = mode; - this.view = this.createView('WBProtection', { + this.appConfig.isEdit && (this.view = this.createView('WBProtection', { mode: mode - }); + })); return this; }, createToolbarPanel: function() { - return this.view.getPanel(); + if (this.view) + return this.view.getPanel(); }, getView: function(name) { @@ -270,6 +271,8 @@ define([ }, onAppReady: function (config) { + if (!this.view) return; + var me = this; (new Promise(function (resolve) { resolve(); @@ -284,15 +287,17 @@ define([ }, onChangeProtectWorkbook: function() { - this.view.btnProtectWB.toggle(this.api.asc_isProtectedWorkbook(), true); + this.view && this.view.btnProtectWB.toggle(this.api.asc_isProtectedWorkbook(), true); }, onChangeProtectSheet: function() { var props = this.getWSProps(true); - this.view.btnProtectSheet.toggle(props.wsLock, true); //current sheet - Common.Utils.lockControls(SSE.enumLock['Objects'], props.wsProps['Objects'], { array: [this.view.chLockedText, this.view.chLockedShape]}); - Common.Utils.lockControls(SSE.enumLock.wsLock, props.wsLock, { array: [this.view.btnAllowRanges]}); + if (this.view) { + this.view.btnProtectSheet.toggle(props.wsLock, true); //current sheet + Common.Utils.lockControls(SSE.enumLock['Objects'], props.wsProps['Objects'], { array: [this.view.chLockedText, this.view.chLockedShape]}); + Common.Utils.lockControls(SSE.enumLock.wsLock, props.wsLock, { array: [this.view.btnAllowRanges]}); + } Common.NotificationCenter.trigger('protect:wslock', props); }, @@ -301,6 +306,8 @@ define([ }, getWSProps: function(update) { + if (!this.appConfig || !this.appConfig.isEdit && !this.appConfig.isRestrictedEdit) return; + if (update || !this._state.protection) { var wsProtected = !!this.api.asc_isProtectedSheet(); var arr = []; @@ -322,6 +329,7 @@ define([ }, onApiSelectionChanged: function(info) { + if (!this.view) return; if ($('.asc-window.enable-key-events:visible').length>0) return; var selectionType = info.asc_getSelectionType();