[SSE] Add sheet/workbook protection buttons

This commit is contained in:
Julia Radzhabova 2021-06-21 18:00:20 +03:00
parent 5ee4af680e
commit 11c999227d
6 changed files with 366 additions and 9 deletions

View file

@ -159,6 +159,7 @@ require([
'PivotTable',
'DataTab',
'ViewTab',
'WBProtection',
'Common.Controllers.Fonts',
'Common.Controllers.Chat',
'Common.Controllers.Comments',
@ -183,6 +184,7 @@ require([
'spreadsheeteditor/main/app/controller/PivotTable',
'spreadsheeteditor/main/app/controller/DataTab',
'spreadsheeteditor/main/app/controller/ViewTab',
'spreadsheeteditor/main/app/controller/WBProtection',
'spreadsheeteditor/main/app/view/FileMenuPanels',
'spreadsheeteditor/main/app/view/ParagraphSettings',
'spreadsheeteditor/main/app/view/ImageSettings',

View file

@ -1276,8 +1276,8 @@ define([
// statusbarController && statusbarController.setApi(me.api);
rightmenuController && rightmenuController.setApi(me.api);
if (me.appOptions.canProtect)
application.getController('Common.Controllers.Protection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api);
application.getController('Common.Controllers.Protection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api);
application.getController('WBProtection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api);
if (statusbarController) {
statusbarController.getView('Statusbar').changeViewMode(true);

View file

@ -3705,13 +3705,12 @@ define([
me.toolbar.btnCopy.$el.removeClass('split');
}
if ( config.isDesktopApp ) {
if ( config.canProtect ) {
var tab = {action: 'protect', caption: me.toolbar.textTabProtect};
var $panel = me.getApplication().getController('Common.Controllers.Protection').createToolbarPanel();
if ($panel)
me.toolbar.addTab(tab, $panel, 7);
}
var tab = {action: 'protect', caption: me.toolbar.textTabProtect};
var $panel = me.getApplication().getController('Common.Controllers.Protection').createToolbarPanel();
if ($panel) {
config.canProtect && $panel.append($('<div class="separator long"></div>'));
$panel.append(me.getApplication().getController('WBProtection').createToolbarPanel());
me.toolbar.addTab(tab, $panel, 7);
}
var viewtab = me.getApplication().getController('ViewTab');

View file

@ -0,0 +1,139 @@
/*
*
* (c) Copyright Ascensio System SIA 2010-2021
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
* WBProtection.js
*
* Created by Julia Radzhabova on 21.06.2021
* Copyright (c) 2021Ascensio System SIA. All rights reserved.
*
*/
define([
'core',
'common/main/lib/view/Protection',
'spreadsheeteditor/main/app/view/WBProtection'
], function () {
'use strict';
SSE.Controllers.WBProtection = Backbone.Controller.extend(_.extend({
models : [],
collections : [
],
views : [
'WBProtection'
],
sdkViewName : '#id_main',
initialize: function () {
this.addListeners({
'WBProtection': {
'protect:workbook': _.bind(this.onWorkbookClick, this),
'protect:sheet': _.bind(this.onSheetClick, this),
'protect:ranges': _.bind(this.onRangesClick, this),
'protect:lock-options': _.bind(this.onLockOptionClick, this)
}
});
},
onLaunch: function () {
this._state = {};
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
},
setConfig: function (data, api) {
this.setApi(api);
if (data) {
this.sdkViewName = data['sdkviewname'] || this.sdkViewName;
}
},
setApi: function (api) {
if (api) {
this.api = api;
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
}
},
setMode: function(mode) {
this.appConfig = mode;
this.view = this.createView('WBProtection', {
mode: mode
});
return this;
},
createToolbarPanel: function() {
return this.view.getPanel();
},
getView: function(name) {
return !name && this.view ?
this.view : Backbone.Controller.prototype.getView.call(this, name);
},
onWorkbookClick: function(state) {
},
onSheetClick: function(state) {
},
onRangesClick: function() {
},
onLockOptionClick: function(type, value) {
switch (type) {
case 0: // cell
// this._originalProps.asc_getStyleInfo().asc_setShowRowHeaders(this.api, this._originalProps, value=='checked');
break;
case 1: // shape
break;
case 2: // text
break;
case 3: // formula
break;
}
Common.NotificationCenter.trigger('edit:complete', this);
},
onAppReady: function (config) {
},
onCoAuthoringDisconnect: function() {
this.SetDisabled(true);
}
}, SSE.Controllers.WBProtection || {}));
});

View file

@ -0,0 +1,215 @@
/*
*
* (c) Copyright Ascensio System SIA 2010-2021
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
* WBProtection.js
*
* Created by Julia Radzhabova on 21.06.2021
* Copyright (c) 2021Ascensio System SIA. All rights reserved.
*
*/
define([
'common/main/lib/util/utils',
'common/main/lib/component/BaseView',
'common/main/lib/component/Layout',
'common/main/lib/component/Window'
], function (template) {
'use strict';
SSE.Views.WBProtection = Common.UI.BaseView.extend(_.extend((function(){
var template =
'<div class="group">' +
'<span id="slot-btn-protect-wb" class="btn-slot text x-huge"></span>' +
'<span id="slot-btn-protect-sheet" class="btn-slot text x-huge"></span>' +
'<span id="slot-btn-allow-ranges" class="btn-slot text x-huge"></span>' +
'</div>' +
'<div class="group small">' +
'<div class="elset">' +
'<span class="btn-slot text" id="slot-chk-locked-cell"></span>' +
'</div>' +
'<div class="elset">' +
'<span class="btn-slot text" id="slot-chk-hidden-formula"></span>' +
'</div>' +
'</div>' +
'<div class="group small">' +
'<div class="elset">' +
'<span class="btn-slot text" id="slot-chk-locked-shape"></span>' +
'</div>' +
'<div class="elset">' +
'<span class="btn-slot text" id="slot-chk-locked-text"></span>' +
'</div>' +
'</div>';
function setEvents() {
var me = this;
this.btnProtectWB.on('click', function (btn, e) {
me.fireEvent('protect:workbook', [btn.pressed]);
});
this.btnProtectSheet.on('click', function (btn, e) {
me.fireEvent('protect:sheet', [btn.pressed]);
});
this.btnAllowRanges.on('click', function (btn, e) {
me.fireEvent('protect:ranges');
});
this.chLockedCell.on('change', function (field, value) {
me.fireEvent('protect:lock-options', [0, value]);
});
this.chLockedShape.on('change', function (field, value) {
me.fireEvent('protect:lock-options', [1, value]);
});
this.chLockedText.on('change', function (field, value) {
me.fireEvent('protect:lock-options', [2, value]);
});
this.chHiddenFormula.on('change', function (field, value) {
me.fireEvent('protect:lock-options', [3, value]);
});
me._isSetEvents = true;
}
return {
options: {},
initialize: function (options) {
Common.UI.BaseView.prototype.initialize.call(this, options);
this.appConfig = options.mode;
var _set = SSE.enumLock;
this.lockedControls = [];
this._state = {disabled: false};
this.btnProtectWB = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
iconCls: 'toolbar__icon protect-workbook',
enableToggle: true,
caption: this.txtProtectWB,
lock : [_set.lostConnect, _set.coAuth]
});
this.lockedControls.push(this.btnProtectWB);
this.btnProtectSheet = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
iconCls: 'toolbar__icon protect-sheet',
enableToggle: true,
caption: this.txtProtectSheet,
lock : [_set.lostConnect, _set.coAuth]
});
this.lockedControls.push(this.btnProtectSheet);
this.btnAllowRanges = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
iconCls: 'toolbar__icon allow-edit-ranges',
caption: this.txtAllowRanges,
lock : [_set.lostConnect, _set.coAuth]
});
this.lockedControls.push(this.btnAllowRanges);
this.chLockedCell = new Common.UI.CheckBox({
labelText: this.txtLockedCell,
lock : [_set.lostConnect, _set.coAuth]
});
this.lockedControls.push(this.chLockedCell);
this.chLockedShape = new Common.UI.CheckBox({
labelText: this.txtLockedShape,
lock : [_set.lostConnect, _set.coAuth]
});
this.lockedControls.push(this.chLockedShape);
this.chLockedText = new Common.UI.CheckBox({
labelText: this.txtLockedText,
lock : [_set.lostConnect, _set.coAuth]
});
this.lockedControls.push(this.chLockedText);
this.chHiddenFormula = new Common.UI.CheckBox({
labelText: this.txtHiddenFormula,
lock : [_set.lostConnect, _set.coAuth]
});
this.lockedControls.push(this.chHiddenFormula);
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
},
render: function (el) {
return this;
},
onAppReady: function (config) {
var me = this;
(new Promise(function (accept, reject) {
accept();
})).then(function(){
me.btnProtectWB.updateHint(me.hintProtectWB);
me.btnProtectSheet.updateHint(me.hintProtectSheet);
me.btnAllowRanges.updateHint(me.hintAllowRanges);
setEvents.call(me);
});
},
getPanel: function () {
this.$el = $(_.template(template)( {} ));
this.btnProtectWB.render(this.$el.find('#slot-btn-protect-wb'));
this.btnProtectSheet.render(this.$el.find('#slot-btn-protect-sheet'));
this.btnAllowRanges.render(this.$el.find('#slot-btn-allow-ranges'));
this.chLockedCell.render(this.$el.find('#slot-chk-locked-cell'));
this.chLockedShape.render(this.$el.find('#slot-chk-locked-shape'));
this.chLockedText.render(this.$el.find('#slot-chk-locked-text'));
this.chHiddenFormula.render(this.$el.find('#slot-chk-hidden-formula'));
return this.$el;
},
show: function () {
Common.UI.BaseView.prototype.show.call(this);
this.fireEvent('show', this);
},
txtProtectWB: 'Protect Workbook',
txtProtectSheet: 'Protect Sheet',
txtAllowRanges: 'Allow Edit Ranges',
hintProtectWB: 'Protect workbook',
hintProtectSheet: 'Protect sheet',
hintAllowRanges: 'Allow edit ranges',
txtLockedCell: 'Locked Cell',
txtLockedShape: 'Shape Locked',
txtLockedText: 'Lock Text',
txtHiddenFormula: 'Hidden Formulas'
}
}()), SSE.Views.WBProtection || {}));
});

View file

@ -149,6 +149,7 @@ require([
'PivotTable',
'DataTab',
'ViewTab',
'WBProtection',
'Common.Controllers.Fonts',
'Common.Controllers.Chat',
'Common.Controllers.Comments',
@ -173,6 +174,7 @@ require([
'spreadsheeteditor/main/app/controller/PivotTable',
'spreadsheeteditor/main/app/controller/DataTab',
'spreadsheeteditor/main/app/controller/ViewTab',
'spreadsheeteditor/main/app/controller/WBProtection',
'spreadsheeteditor/main/app/view/FileMenuPanels',
'spreadsheeteditor/main/app/view/ParagraphSettings',
'spreadsheeteditor/main/app/view/ImageSettings',