[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) {
this.editor.$btnfunc[!disabled?'removeClass':'addClass']('disabled');
this.editor.btnNamedRanges.setVisible(!disabled);
this.editor.$btnfunc[!disabled && this.mode.isEdit ?'removeClass':'addClass']('disabled');
this.editor.btnNamedRanges.setVisible(!disabled && this.mode.isEdit && !this.mode.isEditDiagram && !this.mode.isEditMailMerge);
},
setPreviewMode: function(mode) {
if (this.viewmode === mode) return;
this.viewmode = mode;
this.editor.$btnfunc[!mode?'removeClass':'addClass']('disabled');
this.editor.cellNameDisabled(mode);
this.editor.$btnfunc[!mode && this.mode.isEdit?'removeClass':'addClass']('disabled');
this.editor.cellNameDisabled(mode && !(this.mode.isEdit && !this.mode.isEditDiagram && !this.mode.isEditMailMerge));
}
});
});

View file

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

View file

@ -209,7 +209,8 @@ define([
Common.NotificationCenter.on('download:cancel', _.bind(this.onDownloadCancel, this));
Common.NotificationCenter.on('download:advanced', _.bind(this.onAdvancedOptions, 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({
strongCompare : this._compareActionStrong,
@ -218,6 +219,11 @@ define([
this.stackLongActions.push({id: InitApplication, type: Asc.c_oAscAsyncActionType.BlockInteraction});
this.stackDisableActions = new Common.IrregularStack({
strongCompare : this._compareActionWeak,
weakCompare : this._compareActionWeak
});
this.isShowOpenDialog = false;
// 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) ))
this.onEditComplete(this.loadMask, {restorefocus:true});
}
if ( id == Asc.c_oAscAsyncAction['Disconnect']) {
this.disableEditing(false, true);
}
},
setLongActionView: function(action) {
@ -741,6 +750,12 @@ define([
case LoadingDocument:
title = this.loadingDocumentTitleText + ' ';
break;
case Asc.c_oAscAsyncAction['Disconnect']:
title = this.textDisconnect;
this.disableEditing(true, true);
break;
default:
if (typeof action.id == 'string'){
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();
if (this.appOptions.canEdit && this.editorConfig.mode !== 'view') {
app.getController('RightMenu').getView('RightMenu').clearSelection();
app.getController('RightMenu').SetDisabled(disable, false);
app.getController('Toolbar').DisableToolbar(disable,disable);
var action = {type: type, disable: disable, options: options};
if (disable && !this.stackDisableActions.get({type: type}))
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('LeftMenu').SetDisabled(disable, true);
app.getController('Common.Controllers.ReviewChanges').SetDisabled(disable);
app.getController('Viewport').SetDisabled(disable);
app.getController('CellEditor').SetDisabled(disable);
if (options.review) {
app.getController('Common.Controllers.ReviewChanges').SetDisabled(disable);
}
if (options.viewport) {
app.getController('Viewport').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) {
@ -2443,15 +2516,7 @@ define([
var me = this;
Common.Utils.warningDocumentIsLocked({
disablefunc: function (disable) {
me.disableEditing(disable);
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);
me.disableEditing(disable, true);
}});
},
@ -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.',
txtQuarter: 'Qtr',
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 || {}))
});

View file

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

View file

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

View file

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

View file

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