diff --git a/apps/documenteditor/main/app.js b/apps/documenteditor/main/app.js index 190281919..4d7b05f6d 100644 --- a/apps/documenteditor/main/app.js +++ b/apps/documenteditor/main/app.js @@ -157,6 +157,7 @@ require([ 'Main', 'ViewTab', 'Search', + 'DocProtection', 'Common.Controllers.Fonts', 'Common.Controllers.History' /** coauthoring begin **/ @@ -191,6 +192,7 @@ require([ 'documenteditor/main/app/controller/Main', 'documenteditor/main/app/controller/ViewTab', 'documenteditor/main/app/controller/Search', + 'documenteditor/main/app/controller/DocProtection', 'documenteditor/main/app/view/FileMenuPanels', 'documenteditor/main/app/view/ParagraphSettings', 'documenteditor/main/app/view/HeaderFooterSettings', diff --git a/apps/documenteditor/main/app/controller/DocProtection.js b/apps/documenteditor/main/app/controller/DocProtection.js new file mode 100644 index 000000000..c5202176f --- /dev/null +++ b/apps/documenteditor/main/app/controller/DocProtection.js @@ -0,0 +1,203 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2022 + * + * 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 + * + */ + +/** + * DocProtection.js + * + * Created by Julia Radzhabova on 21.09.2022 + * Copyright (c) 2022 Ascensio System SIA. All rights reserved. + * + */ +define([ + 'core', + 'common/main/lib/view/Protection', + 'documenteditor/main/app/view/DocProtection', + 'documenteditor/main/app/view/ProtectDialog' +], function () { + 'use strict'; + + if (!Common.enumLock) + Common.enumLock = {}; + + var enumLock = { + docLockView: 'lock-mode-view', + docLockForms: 'lock-mode-forms', + docLockReview: 'lock-mode-review', + docLockComments: 'lock-mode-comments' + }; + for (var key in enumLock) { + if (enumLock.hasOwnProperty(key)) { + Common.enumLock[key] = enumLock[key]; + } + } + + DE.Controllers.DocProtection = Backbone.Controller.extend(_.extend({ + models : [], + collections : [ + ], + views : [ + 'DocProtection' + ], + + initialize: function () { + + this.addListeners({ + 'DocProtection': { + 'protect:document': _.bind(this.onProtectDocClick, this) + } + }); + }, + onLaunch: function () { + this._state = {}; + Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); + }, + setConfig: function (data, api) { + this.setApi(api); + }, + setApi: function (api) { + if (api) { + this.api = api; + this.api.asc_registerCallback('asc_onChangeProtectDocument',_.bind(this.onChangeProtectDocument, this)); + } + }, + + setMode: function(mode) { + this.appConfig = mode; + + this.appConfig.isEdit && (this.view = this.createView('DocProtection', { + mode: mode + })); + + return this; + }, + + createToolbarPanel: function() { + if (this.view) + return this.view.getPanel(); + }, + + getView: function(name) { + return !name && this.view ? + this.view : Backbone.Controller.prototype.getView.call(this, name); + }, + + onProtectDocClick: function(state) { + this.view.btnProtectDoc.toggle(!state, true); + if (state) { + var me = this, + btn, + win = new DE.Views.ProtectDialog({ + handler: function(result, value, props) { + btn = result; + if (result == 'ok') { + // var props = me.api.asc_getProtectedDocument(); + // props.asc_setLockMode(props); + // props.asc_setLockPwd(value); + // me.api.asc_setProtectedDocument(props); + } + Common.NotificationCenter.trigger('edit:complete'); + } + }).on('close', function() { + if (btn!=='ok') + me.view.btnProtectDoc.toggle(false, true); + }); + + win.show(); + } else { + var me = this, + btn, + props = me.api.asc_getProtectedDocument(); + if (props.asc_isPassword()) { + var win = new Common.Views.OpenDialog({ + title: me.view.txtWBUnlockTitle, + closable: true, + type: Common.Utils.importTextType.DRM, + txtOpenFile: me.view.txtWBUnlockDescription, + validatePwd: false, + handler: function (result, value) { + btn = result; + if (result == 'ok') { + if (me.api) { + // props.asc_setLockPwd(value && value.drmOptions ? value.drmOptions.asc_getPassword() : undefined); + // me.api.asc_setProtectedDocument(props); + } + Common.NotificationCenter.trigger('edit:complete'); + } + } + }).on('close', function() { + if (btn!=='ok') + me.view.btnProtectDoc.toggle(true, true); + }); + + win.show(); + } else { + props.asc_setLockPwd(); + me.api.asc_setProtectedDocument(props); + } + } + }, + + onAppReady: function (config) { + if (!this.view) return; + + var me = this; + (new Promise(function (resolve) { + resolve(); + })).then(function () { + // me.view.btnProtectDoc.toggle(me.api.asc_isProtectedDocument(), true); + }); + }, + + onChangeProtectDocument: function() { + // this.view && this.view.btnProtectDoc.toggle(this.api.asc_isProtectedDocument(), true); + }, + + getDocProps: function(update) { + if (!this.appConfig || !this.appConfig.isEdit && !this.appConfig.isRestrictedEdit) return; + + if (update || !this._state.protection) { + var docProtected = !!this.api.asc_isProtectedDocument(), + type; + + if (docProtected) { + var props = this.api.asc_getProtectedDocument(); + type = props.asc_getLockMode(); + } + this._state.protection = {docLock: docProtected, lockMode: type}; + } + + return this._state.protection; + } + + }, DE.Controllers.DocProtection || {})); +}); \ No newline at end of file diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 9af86ff56..a0fdd0c70 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1700,8 +1700,8 @@ define([ fontsControllers && fontsControllers.setApi(me.api); rightmenuController && rightmenuController.setApi(me.api); - if (this.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('DocProtection').setMode(me.appOptions).setConfig({config: me.editorConfig}, me.api); var viewport = this.getApplication().getController('Viewport').getView('Viewport'); diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 6812ef505..94aaaf698 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -3203,13 +3203,24 @@ define([ me.toolbar.processPanelVisible(null, true, true); } - if ( config.isDesktopApp ) { - if ( config.canProtect ) { - tab = {action: 'protect', caption: me.toolbar.textTabProtect, dataHintTitle: 'T', layoutname: 'toolbar-protect'}; - $panel = me.getApplication().getController('Common.Controllers.Protection').createToolbarPanel(); + // if ( config.isDesktopApp ) { + // if ( config.canProtect ) { + // tab = {action: 'protect', caption: me.toolbar.textTabProtect, dataHintTitle: 'T', layoutname: 'toolbar-protect'}; + // $panel = me.getApplication().getController('Common.Controllers.Protection').createToolbarPanel(); + // + // if ($panel) me.toolbar.addTab(tab, $panel, 6); + // } + // } - if ($panel) me.toolbar.addTab(tab, $panel, 6); - } + tab = {action: 'protect', caption: me.toolbar.textTabProtect, layoutname: 'toolbar-protect', dataHintTitle: 'T'}; + $panel = me.getApplication().getController('Common.Controllers.Protection').createToolbarPanel(); + if ($panel) { + config.canProtect && $panel.append($('
')); + var doctab = me.getApplication().getController('DocProtection'); + $panel.append(doctab.createToolbarPanel()); + me.toolbar.addTab(tab, $panel, 6); + me.toolbar.setVisible('protect', Common.UI.LayoutManager.isElementVisible('toolbar-protect')); + Array.prototype.push.apply(me.toolbar.lockControls, doctab.getView('DocProtection').getButtons()); } var links = me.getApplication().getController('Links'); diff --git a/apps/documenteditor/main/app/view/DocProtection.js b/apps/documenteditor/main/app/view/DocProtection.js new file mode 100644 index 000000000..3f4916175 --- /dev/null +++ b/apps/documenteditor/main/app/view/DocProtection.js @@ -0,0 +1,130 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2022 + * + * 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 + * + */ + +/** + * DocProtection.js + * + * Created by Julia Radzhabova on 21.09.2022 + * Copyright (c) 2022 Ascensio 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'; + + DE.Views.DocProtection = Common.UI.BaseView.extend(_.extend((function(){ + var template = + '