Lock edit plugins when document is protected

This commit is contained in:
Julia Radzhabova 2022-09-28 17:29:24 +03:00
parent 6f1ee48c6d
commit 041557e6a3
4 changed files with 66 additions and 13 deletions
apps
common/main/lib
controller
view
documenteditor/main/app/controller
spreadsheeteditor/main/app/controller

View file

@ -105,6 +105,7 @@ define([
Common.NotificationCenter.on('app:face', this.onAppShowed.bind(this));
Common.NotificationCenter.on('uitheme:changed', this.updatePluginsButtons.bind(this));
Common.NotificationCenter.on('window:resize', this.updatePluginsButtons.bind(this));
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
},
loadConfig: function(data) {
@ -151,6 +152,16 @@ define([
onAppShowed: function (config) {
},
onAppReady: function (config) {
var me = this;
(new Promise(function (accept, reject) {
accept();
})).then(function(){
me.onChangeProtectDocument();
Common.NotificationCenter.on('protect:doclock', _.bind(me.onChangeProtectDocument, me));
});
},
setApi: function(api) {
this.api = api;
@ -225,6 +236,10 @@ define([
var _group = $('> .group', me.$toolbarPanelPlugins);
var $slot = $('<span class="btn-slot text x-huge"></span>').appendTo(_group);
btn.render($slot);
var docProtection = me.panelPlugins._state.docProtection;
Common.Utils.lockControls(Common.enumLock.docLockView, docProtection.isReadOnly, {array: btn});
Common.Utils.lockControls(Common.enumLock.docLockForms, docProtection.isFormsOnly, {array: btn});
Common.Utils.lockControls(Common.enumLock.docLockComments, docProtection.isCommentsOnly, {array: btn});
}
},
@ -259,6 +274,10 @@ define([
rank = new_rank;
});
_group.appendTo(me.$toolbarPanelPlugins);
var docProtection = me.panelPlugins._state.docProtection;
Common.Utils.lockControls(Common.enumLock.docLockView, docProtection.isReadOnly, {array: me.panelPlugins.lockedControls});
Common.Utils.lockControls(Common.enumLock.docLockForms, docProtection.isFormsOnly, {array: me.panelPlugins.lockedControls});
Common.Utils.lockControls(Common.enumLock.docLockComments, docProtection.isCommentsOnly, {array: me.panelPlugins.lockedControls});
} else {
console.error('toolbar panel isnot created');
}
@ -518,10 +537,13 @@ define([
}
var variationsArr = [],
pluginVisible = false;
pluginVisible = false,
isDisplayedInViewer = false;
item.variations.forEach(function(itemVar){
var visible = (isEdit || itemVar.isViewer && (itemVar.isDisplayedInViewer!==false)) && _.contains(itemVar.EditorsSupport, editor) && !itemVar.isSystem;
if ( visible ) pluginVisible = true;
if (itemVar.isViewer && (itemVar.isDisplayedInViewer!==false))
isDisplayedInViewer = true;
if (item.isUICustomizer ) {
visible && arrUI.push({
@ -571,7 +593,8 @@ define([
groupName: (item.group) ? item.group.name : '',
groupRank: (item.group) ? item.group.rank : 0,
minVersion: item.minVersion,
original: item
original: item,
isDisplayedInViewer: isDisplayedInViewer
}));
}
});
@ -720,6 +743,19 @@ define([
}, funcComplete);
} else
funcComplete();
},
onChangeProtectDocument: function(props) {
if (!props) {
var docprotect = this.getApplication().getController('DocProtection');
props = docprotect ? docprotect.getDocProps() : null;
}
if (props && this.panelPlugins) {
this.panelPlugins._state.docProtection = props;
Common.Utils.lockControls(Common.enumLock.docLockView, props.isReadOnly, {array: this.panelPlugins.lockedControls});
Common.Utils.lockControls(Common.enumLock.docLockForms, props.isFormsOnly, {array: this.panelPlugins.lockedControls});
Common.Utils.lockControls(Common.enumLock.docLockComments, props.isCommentsOnly, {array: this.panelPlugins.lockedControls});
}
}
}, Common.Controllers.Plugins || {}));
});

View file

@ -74,14 +74,16 @@ define([
_.extend(this, options);
this._locked = false;
this._state = {
DisabledControls: false
DisabledControls: false,
docProtection: {
isReadOnly: false,
isReviewOnly: false,
isFormsOnly: false,
isCommentsOnly: false
}
};
this.lockedControls = [];
Common.UI.BaseView.prototype.initialize.call(this, arguments);
Common.NotificationCenter.on('app:ready', function (mode) {
Common.Utils.asyncCall(this._onAppReady, this, mode);
}.bind(this));
},
render: function(el) {
@ -153,6 +155,7 @@ define([
if ( !this.storePlugins.isEmpty() ) {
var me = this;
var _group = $('<div class="group"></div>');
var _set = Common.enumLock;
this.storePlugins.each(function (model) {
if (model.get('visible')) {
var modes = model.get('variations'),
@ -167,6 +170,7 @@ define([
split: modes && modes.length > 1,
value: guid,
hint: model.get('name'),
lock: model.get('isDisplayedInViewer') ? [_set.viewMode, _set.previewReviewMode, _set.viewFormMode, _set.selRangeEdit, _set.editFormula] : [_set.viewMode, _set.previewReviewMode, _set.viewFormMode, _set.lostConnect, _set.docLockView, _set.docLockForms, _set.docLockComments, _set.selRangeEdit, _set.editFormula],
dataHint: '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'
@ -179,6 +183,10 @@ define([
me.lockedControls.push(btn);
}
});
var docProtection = me._state.docProtection
Common.Utils.lockControls(Common.enumLock.docLockView, docProtection.isReadOnly, {array: me.lockedControls});
Common.Utils.lockControls(Common.enumLock.docLockForms, docProtection.isFormsOnly, {array: me.lockedControls});
Common.Utils.lockControls(Common.enumLock.docLockComments, docProtection.isCommentsOnly, {array: me.lockedControls});
parent.html(_group);
$('<div class="separator long"></div>').prependTo(parent);
@ -204,6 +212,16 @@ define([
}
},
SetDisabled: function(disable, reviewMode, fillFormMode) {
if (reviewMode) {
Common.Utils.lockControls(Common.enumLock.previewReviewMode, disable, {array: this.lockedControls});
} else if (fillFormMode) {
Common.Utils.lockControls(Common.enumLock.viewFormMode, disable, {array: this.lockedControls});
} else {
Common.Utils.lockControls(Common.enumLock.viewMode, disable, {array: this.lockedControls});
}
},
openInsideMode: function(name, url, frameId) {
if (!this.pluginsPanel) return false;
@ -289,9 +307,6 @@ define([
this.loadMask.hide();
},
_onAppReady: function (mode) {
},
parseIcons: function(icons) {
if (icons.length && typeof icons[0] !== 'string') {
var theme = Common.UI.Themes.currentThemeId().toLowerCase(),
@ -389,6 +404,7 @@ define([
});
});
var _set = Common.enumLock;
var btn = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
iconImg: icon_url,
@ -397,6 +413,7 @@ define([
split: _menu_items.length > 1,
value: guid,
hint: model.get('name'),
lock: model.get('isDisplayedInViewer') ? [_set.viewMode, _set.previewReviewMode, _set.viewFormMode, _set.selRangeEdit, _set.editFormula] : [_set.viewMode, _set.previewReviewMode, _set.viewFormMode, _set.docLockView, _set.docLockForms, _set.docLockComments, _set.selRangeEdit, _set.editFormula ],
dataHint: '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'

View file

@ -842,7 +842,7 @@ define([
app.getController('Navigation') && app.getController('Navigation').SetDisabled(disable);
}
if (options.plugins) {
app.getController('Common.Controllers.Plugins').getView('Common.Views.Plugins').disableControls(disable);
app.getController('Common.Controllers.Plugins').getView('Common.Views.Plugins').SetDisabled(disable, options.reviewMode, options.fillFormMode);
}
if (options.protect) {
app.getController('Common.Controllers.Protection').SetDisabled(disable, false);

View file

@ -805,8 +805,8 @@ define([
this.leftMenu.btnSearchBar.setDisabled(isRangeSelection);
this.leftMenu.btnSpellcheck.setDisabled(isRangeSelection);
if (this.mode.canPlugins && this.leftMenu.panelPlugins) {
Common.Utils.lockControls(Common.enumLock.selRangeEdit, isRangeSelection, {array: this.leftMenu.panelPlugins.lockedControls});
this.leftMenu.panelPlugins.setLocked(isRangeSelection);
this.leftMenu.panelPlugins.disableControls(isRangeSelection);
}
},
@ -817,8 +817,8 @@ define([
this.leftMenu.btnSearchBar.setDisabled(isEditFormula);
this.leftMenu.btnSpellcheck.setDisabled(isEditFormula);
if (this.mode.canPlugins && this.leftMenu.panelPlugins) {
Common.Utils.lockControls(Common.enumLock.editFormula, isEditFormula, {array: this.leftMenu.panelPlugins.lockedControls});
this.leftMenu.panelPlugins.setLocked(isEditFormula);
this.leftMenu.panelPlugins.disableControls(isEditFormula);
}
},