From ef2af067b0b30cbd6827eeb2719503831b3ae5f3 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Sun, 18 Jul 2021 00:22:55 +0300 Subject: [PATCH] [SSE] Protect row/columns insert/delete --- .../main/app/controller/DataTab.js | 14 ++++ .../main/app/controller/Toolbar.js | 79 ++++++++++--------- .../main/app/controller/WBProtection.js | 5 +- .../main/app/view/DataTab.js | 6 +- .../main/app/view/Toolbar.js | 4 +- 5 files changed, 64 insertions(+), 44 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/DataTab.js b/apps/spreadsheeteditor/main/app/controller/DataTab.js index 78daa73f8..31be82dfc 100644 --- a/apps/spreadsheeteditor/main/app/controller/DataTab.js +++ b/apps/spreadsheeteditor/main/app/controller/DataTab.js @@ -74,6 +74,8 @@ define([ this.api.asc_registerCallback('asc_onChangeProtectWorkbook',_.bind(this.onChangeProtectWorkbook, this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); + Common.NotificationCenter.on('protect:wslock', _.bind(this.onChangeProtectSheet, this)); + Common.NotificationCenter.on('document:ready', _.bind(this.onDocumentReady, this)); } return this; }, @@ -420,6 +422,18 @@ define([ this.onWorksheetLocked(currentSheet, this.api.asc_isWorksheetLockedOrDeleted(currentSheet)); }, + onChangeProtectSheet: function(props) { + if (!props) { + var wbprotect = this.getApplication().getController('WBProtection'); + props = wbprotect ? wbprotect.getWSProps() : null; + } + props && props.wsProps && Common.Utils.lockControls(SSE.enumLock['Sort'], props.wsProps['Sort'], {array: this.view.btnsSortDown.concat(this.view.btnsSortUp, this.view.btnCustomSort)}); + }, + + onDocumentReady: function() { + this.onChangeProtectSheet(); + }, + textWizard: 'Text to Columns Wizard', txtRemDuplicates: 'Remove Duplicates', txtExpandRemDuplicates: 'The data next to the selection will not be removed. Do you want to expand the selection to include the adjacent data or continue with the currently selected cells only?', diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index fe2107b25..10e107703 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -170,10 +170,6 @@ define([ merge: undefined, angle: undefined, controlsdisabled: { - rows: undefined, - cols: undefined, - cells_right: undefined, - cells_down: undefined, filters: undefined }, selection_type: undefined, @@ -1836,7 +1832,7 @@ define([ var shortcuts = { 'command+l,ctrl+l': function(e) { - if ( me.editMode && !me._state.multiselect && me.appConfig.canModifyFilter) { + if ( me.editMode && !me._state.multiselect && me.appConfig.canModifyFilter && !me._state.wsLock) { var cellinfo = me.api.asc_getCellInfo(), filterinfo = cellinfo.asc_getAutoFilterInfo(), formattableinfo = cellinfo.asc_getFormatTableInfo(); @@ -1849,7 +1845,7 @@ define([ return false; }, 'command+shift+l,ctrl+shift+l': function(e) { - if (me.editMode && me.api && !me._state.multiselect && me.appConfig.canModifyFilter) { + if (me.editMode && me.api && !me._state.multiselect && me.appConfig.canModifyFilter && !me._state.wsLock) { var state = me._state.filter; me._state.filter = undefined; @@ -1868,7 +1864,7 @@ define([ }, 'command+k,ctrl+k': function (e) { if (me.editMode && !me.toolbar.mode.isEditMailMerge && !me.toolbar.mode.isEditDiagram && !me.api.isCellEdited && !me._state.multiselect && !me._state.inpivot && - !me.getApplication().getController('LeftMenu').leftMenu.menuFile.isVisible()) { + !me.getApplication().getController('LeftMenu').leftMenu.menuFile.isVisible() && !me._state.wsProps['InsertHyperlinks']) { var cellinfo = me.api.asc_getCellInfo(), selectionType = cellinfo.asc_getSelectionType(); if (selectionType !== Asc.c_oAscSelectionType.RangeShapeText || me.api.asc_canAddShapeHyperlink()!==false) @@ -1899,14 +1895,18 @@ define([ var cellinfo = me.api.asc_getCellInfo(), selectionType = cellinfo.asc_getSelectionType(); if (selectionType === Asc.c_oAscSelectionType.RangeRow || selectionType === Asc.c_oAscSelectionType.RangeCol) { - me.api.asc_insertCells(selectionType === Asc.c_oAscSelectionType.RangeRow ? Asc.c_oAscInsertOptions.InsertRows :Asc.c_oAscInsertOptions.InsertColumns ); + (selectionType === Asc.c_oAscSelectionType.RangeRow) && !me.toolbar.btnAddCell.menu.items[2].isDisabled() && me.api.asc_insertCells(Asc.c_oAscInsertOptions.InsertRows); + (selectionType === Asc.c_oAscSelectionType.RangeCol) && !me.toolbar.btnAddCell.menu.items[3].isDisabled() && me.api.asc_insertCells(Asc.c_oAscInsertOptions.InsertColumns); Common.NotificationCenter.trigger('edit:complete', me.toolbar); } else { var items = me.toolbar.btnAddCell.menu.items, - arr = []; - for (var i=0; i<4; i++) + arr = [], + enabled = false; + for (var i=0; i<4; i++) { arr.push({caption: items[i].caption, value: items[i].value, disabled: items[i].isDisabled()}); - (new Common.Views.OptionsDialog({ + !items[i].isDisabled() && (enabled = true); + } + enabled && (new Common.Views.OptionsDialog({ title: me.txtInsertCells, items: arr, handler: function (dlg, result) { @@ -1930,10 +1930,13 @@ define([ Common.NotificationCenter.trigger('edit:complete', me.toolbar); } else { var items = me.toolbar.btnDeleteCell.menu.items, - arr = []; - for (var i=0; i<4; i++) + arr = [], + enabled = false; + for (var i=0; i<4; i++) { arr.push({caption: items[i].caption, value: items[i].value, disabled: items[i].isDisabled()}); - (new Common.Views.OptionsDialog({ + !items[i].isDisabled() && (enabled = true); + } + enabled && (new Common.Views.OptionsDialog({ title: me.txtDeleteCells, items: arr, handler: function (dlg, result) { @@ -2823,30 +2826,34 @@ define([ } } - val = (selectionType==Asc.c_oAscSelectionType.RangeRow); - if ( this._state.controlsdisabled.rows!==val ) { - this._state.controlsdisabled.rows=val; - toolbar.btnAddCell.menu.items[3].setDisabled(val); - toolbar.btnDeleteCell.menu.items[3].setDisabled(val); - } - val = (selectionType==Asc.c_oAscSelectionType.RangeCol); - if ( this._state.controlsdisabled.cols!==val ) { - this._state.controlsdisabled.cols=val; - toolbar.btnAddCell.menu.items[2].setDisabled(val); - toolbar.btnDeleteCell.menu.items[2].setDisabled(val); - } + var selCol = selectionType==Asc.c_oAscSelectionType.RangeCol, + selRow = selectionType==Asc.c_oAscSelectionType.RangeRow, + selMax = selectionType==Asc.c_oAscSelectionType.RangeMax; + + need_disable = selRow || selMax && this._state.wsLock || this._state.wsProps['InsertColumns']; + toolbar.btnAddCell.menu.items[3].setDisabled(need_disable); + + need_disable = selRow || selMax && this._state.wsLock || !selCol && this._state.wsLock || this._state.wsProps['DeleteColumns']; + toolbar.btnDeleteCell.menu.items[3].setDisabled(need_disable); + + need_disable = selCol || selMax && this._state.wsLock || this._state.wsProps['InsertRows']; + toolbar.btnAddCell.menu.items[2].setDisabled(need_disable); + + need_disable = selCol || selMax && this._state.wsLock || !selRow && this._state.wsLock || this._state.wsProps['DeleteRows']; + toolbar.btnDeleteCell.menu.items[2].setDisabled(need_disable); val = filterInfo && filterInfo.asc_getIsApplyAutoFilter(); - if ( this._state.controlsdisabled.cells_right!==(this._state.controlsdisabled.rows || val || this._state.wsLock) ) { - this._state.controlsdisabled.cells_right = (this._state.controlsdisabled.rows || val || this._state.wsLock); - toolbar.btnAddCell.menu.items[0].setDisabled(this._state.controlsdisabled.cells_right); - toolbar.btnDeleteCell.menu.items[0].setDisabled(this._state.controlsdisabled.cells_right); - } - if ( this._state.controlsdisabled.cells_down!==(this._state.controlsdisabled.cols || val || this._state.wsLock) ) { - this._state.controlsdisabled.cells_down = (this._state.controlsdisabled.cols || val || this._state.wsLock); - toolbar.btnAddCell.menu.items[1].setDisabled(this._state.controlsdisabled.cells_down); - toolbar.btnDeleteCell.menu.items[1].setDisabled(this._state.controlsdisabled.cells_down); - } + need_disable = selRow || val || !(selCol || selMax) && this._state.wsLock || selCol && this._state.wsProps['InsertColumns'] || selMax && this._state.wsProps['InsertColumns'] && this._state.wsProps['InsertRows']; + toolbar.btnAddCell.menu.items[0].setDisabled(need_disable); + + need_disable = selRow || val || !(selCol || selMax) && this._state.wsLock || selCol && this._state.wsProps['DeleteColumns'] || selMax && this._state.wsProps['DeleteColumns'] && this._state.wsProps['DeleteRows']; + toolbar.btnDeleteCell.menu.items[0].setDisabled(need_disable); + + need_disable = selCol || val || !(selRow || selMax) && this._state.wsLock || selRow && this._state.wsProps['InsertRows'] || selMax && this._state.wsProps['InsertColumns'] && this._state.wsProps['InsertRows']; + toolbar.btnAddCell.menu.items[1].setDisabled(need_disable); + + need_disable = selCol || val || !(selRow || selMax) && this._state.wsLock || selRow && this._state.wsProps['DeleteRows'] || selMax && this._state.wsProps['DeleteColumns'] && this._state.wsProps['DeleteRows']; + toolbar.btnDeleteCell.menu.items[1].setDisabled(need_disable); toolbar.lockToolbar(SSE.enumLock.commentLock, (selectionType == Asc.c_oAscSelectionType.RangeCells) && (info.asc_getComments().length>0 || info.asc_getLocked()) || this.toolbar.mode.compatibleFeatures && (selectionType != Asc.c_oAscSelectionType.RangeCells), diff --git a/apps/spreadsheeteditor/main/app/controller/WBProtection.js b/apps/spreadsheeteditor/main/app/controller/WBProtection.js index d595c3c32..4e9bbfcb4 100644 --- a/apps/spreadsheeteditor/main/app/controller/WBProtection.js +++ b/apps/spreadsheeteditor/main/app/controller/WBProtection.js @@ -270,7 +270,6 @@ define([ })).then(function () { me.view.btnProtectWB.toggle(me.api.asc_isProtectedWorkbook(), true); me.view.btnProtectSheet.toggle(me.api.asc_isProtectedSheet(), true); //current sheet - me.onChangeProtectSheet(true); }); }, @@ -278,11 +277,11 @@ define([ this.view.btnProtectWB.toggle(this.api.asc_isProtectedWorkbook(), true); }, - onChangeProtectSheet: function(suppressEvent) { + onChangeProtectSheet: function() { var props = this.getWSProps(); this.view.btnProtectSheet.toggle(props.wsLock, true); //current sheet - !suppressEvent && Common.NotificationCenter.trigger('protect:wslock', props); + Common.NotificationCenter.trigger('protect:wslock', props); }, onApiSheetChanged: function() { diff --git a/apps/spreadsheeteditor/main/app/view/DataTab.js b/apps/spreadsheeteditor/main/app/view/DataTab.js index 957b8483e..1ededb67c 100644 --- a/apps/spreadsheeteditor/main/app/view/DataTab.js +++ b/apps/spreadsheeteditor/main/app/view/DataTab.js @@ -215,15 +215,15 @@ define([ iconCls: 'toolbar__icon btn-custom-sort', caption: this.capBtnTextCustomSort, disabled: true, - lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter, _set.sheetLock] + lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter, _set.sheetLock, _set['Sort']] }); this.lockedControls.push(this.btnCustomSort); this.btnsSortDown = Common.Utils.injectButtons($host.find('.slot-sortdesc'), '', 'toolbar__icon btn-sort-down', '', - [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.cantModifyFilter, _set.sheetLock, _set.cantSort]); + [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.cantModifyFilter, _set.sheetLock, _set.cantSort, _set['Sort']]); this.btnsSortUp = Common.Utils.injectButtons($host.find('.slot-sortasc'), '', 'toolbar__icon btn-sort-up', '', - [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.cantModifyFilter, _set.sheetLock, _set.cantSort]); + [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.cantModifyFilter, _set.sheetLock, _set.cantSort, _set['Sort']]); this.btnsSetAutofilter = Common.Utils.injectButtons($host.find('.slot-btn-setfilter'), '', 'toolbar__icon btn-autofilter', '', [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.editPivot, _set.cantModifyFilter, _set.tableHasSlicer, _set.wsLock], diff --git a/apps/spreadsheeteditor/main/app/view/Toolbar.js b/apps/spreadsheeteditor/main/app/view/Toolbar.js index 994c19d6e..b70a46f52 100644 --- a/apps/spreadsheeteditor/main/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/view/Toolbar.js @@ -800,7 +800,7 @@ define([ id : 'id-toolbar-btn-ttempl', cls : 'btn-toolbar', iconCls : 'toolbar__icon btn-menu-table', - lock : [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.multiselect, _set.cantModifyFilter, _set.wsLock, _set['FormatCells']], + lock : [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.multiselect, _set.cantModifyFilter, _set.wsLock], menu : new Common.UI.Menu({ items: [ { template: _.template('
') } @@ -813,7 +813,7 @@ define([ cls : 'btn-toolbar x-huge icon-top', iconCls : 'toolbar__icon btn-inserttable', caption : me.capInsertTable, - lock : [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.multiselect, _set.cantModifyFilter, _set.ruleMerge, _set.editPivot, _set.wsLock, _set['FormatCells']] + lock : [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.lostConnect, _set.coAuth, _set.ruleFilter, _set.multiselect, _set.cantModifyFilter, _set.ruleMerge, _set.editPivot, _set.wsLock] }); me.listStyles = new Common.UI.ComboDataView({