[SSE] Refactoring disable editing

This commit is contained in:
Julia Radzhabova 2021-07-02 00:54:55 +03:00
parent c55886f6e3
commit f910c046b8
7 changed files with 132 additions and 62 deletions

View file

@ -324,15 +324,15 @@ define([
}, },
SetDisabled: function(disabled) { SetDisabled: function(disabled) {
this.editor.$btnfunc[!disabled?'removeClass':'addClass']('disabled'); this.editor.$btnfunc[!disabled && this.mode.isEdit ?'removeClass':'addClass']('disabled');
this.editor.btnNamedRanges.setVisible(!disabled); this.editor.btnNamedRanges.setVisible(!disabled && this.mode.isEdit && !this.mode.isEditDiagram && !this.mode.isEditMailMerge);
}, },
setPreviewMode: function(mode) { setPreviewMode: function(mode) {
if (this.viewmode === mode) return; if (this.viewmode === mode) return;
this.viewmode = mode; this.viewmode = mode;
this.editor.$btnfunc[!mode?'removeClass':'addClass']('disabled'); this.editor.$btnfunc[!mode && this.mode.isEdit?'removeClass':'addClass']('disabled');
this.editor.cellNameDisabled(mode); this.editor.cellNameDisabled(mode && !(this.mode.isEdit && !this.mode.isEditDiagram && !this.mode.isEditMailMerge));
} }
}); });
}); });

View file

@ -188,21 +188,28 @@ define([
return this; return this;
}, },
SetDisabled: function(disable, disableFileMenu) { SetDisabled: function(disable, options) {
this.mode.isEdit = !disable; if (this.leftMenu._state.disabled !== disable) {
this.leftMenu._state.disabled = disable;
if (disable) {
this.previsEdit = this.mode.isEdit;
this.prevcanEdit = this.mode.canEdit;
this.mode.isEdit = this.mode.canEdit = !disable;
} else {
this.mode.isEdit = this.previsEdit;
this.mode.canEdit = this.prevcanEdit;
}
}
if (disable) this.leftMenu.close(); if (disable) this.leftMenu.close();
/** coauthoring begin **/ if (!options || options.comments && options.comments.disable)
this.leftMenu.btnComments.setDisabled(disable); this.leftMenu.btnComments.setDisabled(disable);
var comments = this.getApplication().getController('Common.Controllers.Comments'); if (!options || options.chat)
if (comments)
comments.setPreviewMode(disable);
this.setPreviewMode(disable);
this.leftMenu.btnChat.setDisabled(disable); this.leftMenu.btnChat.setDisabled(disable);
/** coauthoring end **/
this.leftMenu.btnPlugins.setDisabled(disable); this.leftMenu.btnPlugins.setDisabled(disable);
this.leftMenu.btnSpellcheck.setDisabled(disable); this.leftMenu.btnSpellcheck.setDisabled(disable);
if (disableFileMenu) this.leftMenu.getMenu('file').SetDisabled(disable);
}, },
createDelayedElements: function() { createDelayedElements: function() {

View file

@ -210,6 +210,7 @@ define([
Common.NotificationCenter.on('download:advanced', _.bind(this.onAdvancedOptions, this)); Common.NotificationCenter.on('download:advanced', _.bind(this.onAdvancedOptions, this));
Common.NotificationCenter.on('showmessage', _.bind(this.onExternalMessage, this)); Common.NotificationCenter.on('showmessage', _.bind(this.onExternalMessage, this));
Common.NotificationCenter.on('markfavorite', _.bind(this.markFavorite, this)); Common.NotificationCenter.on('markfavorite', _.bind(this.markFavorite, this));
Common.NotificationCenter.on('editing:disable', _.bind(this.onEditingDisable, this));
this.stackLongActions = new Common.IrregularStack({ this.stackLongActions = new Common.IrregularStack({
strongCompare : this._compareActionStrong, strongCompare : this._compareActionStrong,
@ -218,6 +219,11 @@ define([
this.stackLongActions.push({id: InitApplication, type: Asc.c_oAscAsyncActionType.BlockInteraction}); this.stackLongActions.push({id: InitApplication, type: Asc.c_oAscAsyncActionType.BlockInteraction});
this.stackDisableActions = new Common.IrregularStack({
strongCompare : this._compareActionWeak,
weakCompare : this._compareActionWeak
});
this.isShowOpenDialog = false; this.isShowOpenDialog = false;
// Initialize api gateway // Initialize api gateway
@ -670,6 +676,9 @@ define([
if (type == Asc.c_oAscAsyncActionType.BlockInteraction && !( (id == Asc.c_oAscAsyncAction['LoadDocumentFonts'] || id == Asc.c_oAscAsyncAction['ApplyChanges']) && (this.dontCloseDummyComment || this.inTextareaControl || Common.Utils.ModalWindow.isVisible() || this.inFormControl) )) if (type == Asc.c_oAscAsyncActionType.BlockInteraction && !( (id == Asc.c_oAscAsyncAction['LoadDocumentFonts'] || id == Asc.c_oAscAsyncAction['ApplyChanges']) && (this.dontCloseDummyComment || this.inTextareaControl || Common.Utils.ModalWindow.isVisible() || this.inFormControl) ))
this.onEditComplete(this.loadMask, {restorefocus:true}); this.onEditComplete(this.loadMask, {restorefocus:true});
} }
if ( id == Asc.c_oAscAsyncAction['Disconnect']) {
this.disableEditing(false, true);
}
}, },
setLongActionView: function(action) { setLongActionView: function(action) {
@ -741,6 +750,12 @@ define([
case LoadingDocument: case LoadingDocument:
title = this.loadingDocumentTitleText + ' '; title = this.loadingDocumentTitleText + ' ';
break; break;
case Asc.c_oAscAsyncAction['Disconnect']:
title = this.textDisconnect;
this.disableEditing(true, true);
break;
default: default:
if (typeof action.id == 'string'){ if (typeof action.id == 'string'){
title = action.id; title = action.id;
@ -1032,18 +1047,76 @@ define([
} }
}, },
disableEditing: function(disable) { disableEditing: function(disable, temp) {
Common.NotificationCenter.trigger('editing:disable', disable, {
viewMode: disable,
allowSignature: false,
allowProtect: false,
rightMenu: {clear: true, disable: true},
statusBar: true,
leftMenu: {disable: true, previewMode: true},
fileMenu: {protect: true, history: temp},
comments: {disable: !temp, previewMode: true},
chat: true,
review: true,
viewport: true,
documentHolder: true,
toolbar: true,
celleditor: {previewMode: true}
}, temp ? 'reconnect' : 'disconnect');
},
onEditingDisable: function(disable, options, type) {
var app = this.getApplication(); var app = this.getApplication();
if (this.appOptions.canEdit && this.editorConfig.mode !== 'view') {
app.getController('RightMenu').getView('RightMenu').clearSelection(); var action = {type: type, disable: disable, options: options};
app.getController('RightMenu').SetDisabled(disable, false); if (disable && !this.stackDisableActions.get({type: type}))
app.getController('Toolbar').DisableToolbar(disable,disable); this.stackDisableActions.push(action);
!disable && this.stackDisableActions.pop({type: type});
var prev_options = !disable && (this.stackDisableActions.length()>0) ? this.stackDisableActions.get(this.stackDisableActions.length()-1) : null;
if (options.rightMenu && app.getController('RightMenu')) {
options.rightMenu.clear && app.getController('RightMenu').getView('RightMenu').clearSelection();
options.rightMenu.disable && app.getController('RightMenu').SetDisabled(disable, options.allowSignature);
}
if (options.statusBar) {
app.getController('Statusbar').SetDisabled(disable); app.getController('Statusbar').SetDisabled(disable);
} }
app.getController('LeftMenu').SetDisabled(disable, true); if (options.review) {
app.getController('Common.Controllers.ReviewChanges').SetDisabled(disable); app.getController('Common.Controllers.ReviewChanges').SetDisabled(disable);
}
if (options.viewport) {
app.getController('Viewport').SetDisabled(disable); app.getController('Viewport').SetDisabled(disable);
app.getController('CellEditor').SetDisabled(disable); }
if (options.toolbar) {
app.getController('Toolbar').DisableToolbar(disable, options.viewMode);
}
if (options.documentHolder) {
app.getController('DocumentHolder').SetDisabled(disable, options.allowProtect);
}
if (options.leftMenu) {
if (options.leftMenu.disable)
app.getController('LeftMenu').SetDisabled(disable, options);
if (options.leftMenu.previewMode)
app.getController('LeftMenu').setPreviewMode(disable);
}
if (options.fileMenu) {
app.getController('LeftMenu').leftMenu.getMenu('file').SetDisabled(disable, options.fileMenu);
if (options.leftMenu.disable)
app.getController('LeftMenu').leftMenu.getMenu('file').applyMode();
}
if (options.comments) {
var comments = this.getApplication().getController('Common.Controllers.Comments');
if (comments && options.comments.previewMode)
comments.setPreviewMode(disable);
}
if (options.celleditor && options.celleditor.previewMode) {
app.getController('CellEditor').setPreviewMode(disable);
}
if (prev_options) {
this.onEditingDisable(prev_options.disable, prev_options.options, prev_options.type);
}
}, },
onOpenDocument: function(progress) { onOpenDocument: function(progress) {
@ -2443,15 +2516,7 @@ define([
var me = this; var me = this;
Common.Utils.warningDocumentIsLocked({ Common.Utils.warningDocumentIsLocked({
disablefunc: function (disable) { disablefunc: function (disable) {
me.disableEditing(disable); me.disableEditing(disable, true);
var app = me.getApplication();
app.getController('DocumentHolder').SetDisabled(disable);
var leftMenu = app.getController('LeftMenu');
leftMenu.leftMenu.getMenu('file').getButton('protect').setDisabled(disable);
leftMenu.setPreviewMode(disable);
var comments = app.getController('Common.Controllers.Comments');
if (comments) comments.setPreviewMode(disable);
}}); }});
}, },
@ -2953,7 +3018,8 @@ define([
errorPivotWithoutUnderlying: 'The Pivot Table report was saved without the underlying data.<br>Use the \'Refresh\' button to update the report.', errorPivotWithoutUnderlying: 'The Pivot Table report was saved without the underlying data.<br>Use the \'Refresh\' button to update the report.',
txtQuarter: 'Qtr', txtQuarter: 'Qtr',
txtOr: '%1 or %2', txtOr: '%1 or %2',
confirmReplaceFormulaInTable: 'Formulas in the header row will be removed and converted to static text.<br>Do you want to continue?' confirmReplaceFormulaInTable: 'Formulas in the header row will be removed and converted to static text.<br>Do you want to continue?',
textDisconnect: 'Connection is lost'
} }
})(), SSE.Controllers.Main || {})) })(), SSE.Controllers.Main || {}))
}); });

View file

@ -253,6 +253,8 @@ define([
}, },
applyMode: function() { applyMode: function() {
if (!this.rendered) return;
if (!this.panels) { if (!this.panels) {
this.panels = { this.panels = {
'opts' : (new SSE.Views.FileMenuPanels.Settings({menu:this})).render(this.$el.find('#panel-settings')), 'opts' : (new SSE.Views.FileMenuPanels.Settings({menu:this})).render(this.$el.find('#panel-settings')),
@ -346,7 +348,6 @@ define([
} }
if (!delay) { if (!delay) {
if ( this.rendered )
this.applyMode(); this.applyMode();
} }
}, },
@ -424,20 +425,16 @@ define([
} }
}, },
SetDisabled: function(disable) { SetDisabled: function(disable, options) {
if ( !this.panels ) { if ( !this.panels ) {
this.mode.disableEditing = disable; this.mode.disableEditing = disable;
} else { } else {
this.panels['opts'].SetDisabled(disable); this.panels['opts'].SetDisabled(disable);
} }
var _btn_save = this.getButton('save'), var _btn_protect = this.getButton('protect');
_btn_rename = this.getButton('rename'),
_btn_protect = this.getButton('protect');
_btn_save.setDisabled(disable || !this.mode.isEdit); options && options.protect && _btn_protect.setDisabled(disable || !this.mode.isEdit);
_btn_protect.setDisabled(disable || !this.mode.isEdit);
_btn_rename.setDisabled(disable || !this.mode.canRename || this.mode.isDesktopApp);
}, },
btnSaveCaption : 'Save', btnSaveCaption : 'Save',

View file

@ -265,6 +265,7 @@ define([
if ( disabled ) { if ( disabled ) {
$(this.viewSettingsPicker.dataViewItems[1].el).hide(); $(this.viewSettingsPicker.dataViewItems[1].el).hide();
$(this.viewSettingsPicker.dataViewItems[2].el).hide(); $(this.viewSettingsPicker.dataViewItems[2].el).hide();
this.viewSettingsPicker.selectByIndex(0, true);
} else { } else {
if ( this.mode.canPrint ) if ( this.mode.canPrint )
$(this.viewSettingsPicker.dataViewItems[1].el).show(); $(this.viewSettingsPicker.dataViewItems[1].el).show();

View file

@ -75,7 +75,7 @@ define([
initialize: function () { initialize: function () {
this.minimizedMode = true; this.minimizedMode = true;
this._state = {}; this._state = {disabled: false};
}, },
render: function () { render: function () {

View file

@ -393,23 +393,22 @@ define([
if (this._state.DisabledEditing != disable) { if (this._state.DisabledEditing != disable) {
this._state.DisabledEditing = disable; this._state.DisabledEditing = disable;
var rightMenuController = SSE.getController('RightMenu'); Common.NotificationCenter.trigger('editing:disable', disable, {
if (disable && rightMenuController.rightmenu.GetActivePane() !== 'id-signature-settings') viewMode: disable,
rightMenuController.rightmenu.clearSelection(); allowSignature: true,
rightMenuController.SetDisabled(disable, true); allowProtect: true,
SSE.getController('Toolbar').DisableToolbar(disable, disable); rightMenu: {clear: disable && (SSE.getController('RightMenu').rightmenu.GetActivePane() !== 'id-signature-settings'), disable: true},
SSE.getController('Statusbar').SetDisabled(disable); statusBar: true,
SSE.getController('Common.Controllers.ReviewChanges').SetDisabled(disable); leftMenu: {disable: false, previewMode: true},
SSE.getController('DocumentHolder').SetDisabled(disable, true); fileMenu: false,
SSE.getController('CellEditor').setPreviewMode(disable); comments: {disable: false, previewMode: true},
SSE.getController('Viewport').disableEditing(disable); chat: false,
review: true,
// var leftMenu = SSE.getController('LeftMenu').leftMenu; viewport: true,
// leftMenu.btnComments.setDisabled(disable); documentHolder: true,
SSE.getController('LeftMenu').setPreviewMode(disable); toolbar: true,
var comments = SSE.getController('Common.Controllers.Comments'); celleditor: {previewMode: true}
if (comments) }, 'signature');
comments.setPreviewMode(disable);
} }
}, },