[SSE] Protect row/columns insert/delete

This commit is contained in:
Julia Radzhabova 2021-07-18 00:22:55 +03:00
parent 6aeda263a8
commit ef2af067b0
5 changed files with 64 additions and 44 deletions

View file

@ -74,6 +74,8 @@ define([
this.api.asc_registerCallback('asc_onChangeProtectWorkbook',_.bind(this.onChangeProtectWorkbook, this)); this.api.asc_registerCallback('asc_onChangeProtectWorkbook',_.bind(this.onChangeProtectWorkbook, this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('api:disconnect', _.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; return this;
}, },
@ -420,6 +422,18 @@ define([
this.onWorksheetLocked(currentSheet, this.api.asc_isWorksheetLockedOrDeleted(currentSheet)); 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', textWizard: 'Text to Columns Wizard',
txtRemDuplicates: 'Remove Duplicates', 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?', 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?',

View file

@ -170,10 +170,6 @@ define([
merge: undefined, merge: undefined,
angle: undefined, angle: undefined,
controlsdisabled: { controlsdisabled: {
rows: undefined,
cols: undefined,
cells_right: undefined,
cells_down: undefined,
filters: undefined filters: undefined
}, },
selection_type: undefined, selection_type: undefined,
@ -1836,7 +1832,7 @@ define([
var shortcuts = { var shortcuts = {
'command+l,ctrl+l': function(e) { '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(), var cellinfo = me.api.asc_getCellInfo(),
filterinfo = cellinfo.asc_getAutoFilterInfo(), filterinfo = cellinfo.asc_getAutoFilterInfo(),
formattableinfo = cellinfo.asc_getFormatTableInfo(); formattableinfo = cellinfo.asc_getFormatTableInfo();
@ -1849,7 +1845,7 @@ define([
return false; return false;
}, },
'command+shift+l,ctrl+shift+l': function(e) { '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; var state = me._state.filter;
me._state.filter = undefined; me._state.filter = undefined;
@ -1868,7 +1864,7 @@ define([
}, },
'command+k,ctrl+k': function (e) { '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 && 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(), var cellinfo = me.api.asc_getCellInfo(),
selectionType = cellinfo.asc_getSelectionType(); selectionType = cellinfo.asc_getSelectionType();
if (selectionType !== Asc.c_oAscSelectionType.RangeShapeText || me.api.asc_canAddShapeHyperlink()!==false) if (selectionType !== Asc.c_oAscSelectionType.RangeShapeText || me.api.asc_canAddShapeHyperlink()!==false)
@ -1899,14 +1895,18 @@ define([
var cellinfo = me.api.asc_getCellInfo(), var cellinfo = me.api.asc_getCellInfo(),
selectionType = cellinfo.asc_getSelectionType(); selectionType = cellinfo.asc_getSelectionType();
if (selectionType === Asc.c_oAscSelectionType.RangeRow || selectionType === Asc.c_oAscSelectionType.RangeCol) { 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); Common.NotificationCenter.trigger('edit:complete', me.toolbar);
} else { } else {
var items = me.toolbar.btnAddCell.menu.items, var items = me.toolbar.btnAddCell.menu.items,
arr = []; arr = [],
for (var i=0; i<4; i++) enabled = false;
for (var i=0; i<4; i++) {
arr.push({caption: items[i].caption, value: items[i].value, disabled: items[i].isDisabled()}); 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, title: me.txtInsertCells,
items: arr, items: arr,
handler: function (dlg, result) { handler: function (dlg, result) {
@ -1930,10 +1930,13 @@ define([
Common.NotificationCenter.trigger('edit:complete', me.toolbar); Common.NotificationCenter.trigger('edit:complete', me.toolbar);
} else { } else {
var items = me.toolbar.btnDeleteCell.menu.items, var items = me.toolbar.btnDeleteCell.menu.items,
arr = []; arr = [],
for (var i=0; i<4; i++) enabled = false;
for (var i=0; i<4; i++) {
arr.push({caption: items[i].caption, value: items[i].value, disabled: items[i].isDisabled()}); 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, title: me.txtDeleteCells,
items: arr, items: arr,
handler: function (dlg, result) { handler: function (dlg, result) {
@ -2823,30 +2826,34 @@ define([
} }
} }
val = (selectionType==Asc.c_oAscSelectionType.RangeRow); var selCol = selectionType==Asc.c_oAscSelectionType.RangeCol,
if ( this._state.controlsdisabled.rows!==val ) { selRow = selectionType==Asc.c_oAscSelectionType.RangeRow,
this._state.controlsdisabled.rows=val; selMax = selectionType==Asc.c_oAscSelectionType.RangeMax;
toolbar.btnAddCell.menu.items[3].setDisabled(val);
toolbar.btnDeleteCell.menu.items[3].setDisabled(val); need_disable = selRow || selMax && this._state.wsLock || this._state.wsProps['InsertColumns'];
} toolbar.btnAddCell.menu.items[3].setDisabled(need_disable);
val = (selectionType==Asc.c_oAscSelectionType.RangeCol);
if ( this._state.controlsdisabled.cols!==val ) { need_disable = selRow || selMax && this._state.wsLock || !selCol && this._state.wsLock || this._state.wsProps['DeleteColumns'];
this._state.controlsdisabled.cols=val; toolbar.btnDeleteCell.menu.items[3].setDisabled(need_disable);
toolbar.btnAddCell.menu.items[2].setDisabled(val);
toolbar.btnDeleteCell.menu.items[2].setDisabled(val); 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(); val = filterInfo && filterInfo.asc_getIsApplyAutoFilter();
if ( this._state.controlsdisabled.cells_right!==(this._state.controlsdisabled.rows || val || this._state.wsLock) ) { need_disable = selRow || val || !(selCol || selMax) && this._state.wsLock || selCol && this._state.wsProps['InsertColumns'] || selMax && this._state.wsProps['InsertColumns'] && this._state.wsProps['InsertRows'];
this._state.controlsdisabled.cells_right = (this._state.controlsdisabled.rows || val || this._state.wsLock); toolbar.btnAddCell.menu.items[0].setDisabled(need_disable);
toolbar.btnAddCell.menu.items[0].setDisabled(this._state.controlsdisabled.cells_right);
toolbar.btnDeleteCell.menu.items[0].setDisabled(this._state.controlsdisabled.cells_right); 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);
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); 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(this._state.controlsdisabled.cells_down); toolbar.btnAddCell.menu.items[1].setDisabled(need_disable);
toolbar.btnDeleteCell.menu.items[1].setDisabled(this._state.controlsdisabled.cells_down);
} 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()) || 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), this.toolbar.mode.compatibleFeatures && (selectionType != Asc.c_oAscSelectionType.RangeCells),

View file

@ -270,7 +270,6 @@ define([
})).then(function () { })).then(function () {
me.view.btnProtectWB.toggle(me.api.asc_isProtectedWorkbook(), true); me.view.btnProtectWB.toggle(me.api.asc_isProtectedWorkbook(), true);
me.view.btnProtectSheet.toggle(me.api.asc_isProtectedSheet(), true); //current sheet 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); this.view.btnProtectWB.toggle(this.api.asc_isProtectedWorkbook(), true);
}, },
onChangeProtectSheet: function(suppressEvent) { onChangeProtectSheet: function() {
var props = this.getWSProps(); var props = this.getWSProps();
this.view.btnProtectSheet.toggle(props.wsLock, true); //current sheet this.view.btnProtectSheet.toggle(props.wsLock, true); //current sheet
!suppressEvent && Common.NotificationCenter.trigger('protect:wslock', props); Common.NotificationCenter.trigger('protect:wslock', props);
}, },
onApiSheetChanged: function() { onApiSheetChanged: function() {

View file

@ -215,15 +215,15 @@ define([
iconCls: 'toolbar__icon btn-custom-sort', iconCls: 'toolbar__icon btn-custom-sort',
caption: this.capBtnTextCustomSort, caption: this.capBtnTextCustomSort,
disabled: true, 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.lockedControls.push(this.btnCustomSort);
this.btnsSortDown = Common.Utils.injectButtons($host.find('.slot-sortdesc'), '', 'toolbar__icon btn-sort-down', '', 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', '', 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', '', 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], [_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],

View file

@ -800,7 +800,7 @@ define([
id : 'id-toolbar-btn-ttempl', id : 'id-toolbar-btn-ttempl',
cls : 'btn-toolbar', cls : 'btn-toolbar',
iconCls : 'toolbar__icon btn-menu-table', 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({ menu : new Common.UI.Menu({
items: [ items: [
{ template: _.template('<div id="id-toolbar-menu-table-templates" style="width: 494px; height: 300px; margin: 0px 4px;"></div>') } { template: _.template('<div id="id-toolbar-menu-table-templates" style="width: 494px; height: 300px; margin: 0px 4px;"></div>') }
@ -813,7 +813,7 @@ define([
cls : 'btn-toolbar x-huge icon-top', cls : 'btn-toolbar x-huge icon-top',
iconCls : 'toolbar__icon btn-inserttable', iconCls : 'toolbar__icon btn-inserttable',
caption : me.capInsertTable, 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({ me.listStyles = new Common.UI.ComboDataView({