2022-09-21 14:15:33 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (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;
|
2022-10-03 10:44:27 +00:00
|
|
|
this.api.asc_registerCallback('asc_onChangeDocumentProtection',_.bind(this.onChangeProtectDocument, this));
|
2022-09-21 14:15:33 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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({
|
2022-09-27 08:34:47 +00:00
|
|
|
props: me.appConfig,
|
2022-09-21 14:15:33 +00:00
|
|
|
handler: function(result, value, props) {
|
|
|
|
btn = result;
|
|
|
|
if (result == 'ok') {
|
2022-10-03 10:44:27 +00:00
|
|
|
me.api.asc_setDocumentProtection(props, value);
|
2022-09-21 14:15:33 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete');
|
|
|
|
}
|
|
|
|
}).on('close', function() {
|
|
|
|
if (btn!=='ok')
|
|
|
|
me.view.btnProtectDoc.toggle(false, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
win.show();
|
|
|
|
} else {
|
|
|
|
var me = this,
|
|
|
|
btn,
|
2022-10-03 10:44:27 +00:00
|
|
|
props = me.api.asc_getDocumentProtection();
|
|
|
|
if (props && props[1]) {
|
2022-09-21 14:15:33 +00:00
|
|
|
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) {
|
2022-10-03 20:36:58 +00:00
|
|
|
me.api.asc_setDocumentProtection(Asc.c_oAscEDocProtect.None, value && value.drmOptions ? value.drmOptions.asc_getPassword() : undefined);
|
2022-09-21 14:15:33 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).on('close', function() {
|
|
|
|
if (btn!=='ok')
|
|
|
|
me.view.btnProtectDoc.toggle(true, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
win.show();
|
|
|
|
} else {
|
2022-10-03 20:36:58 +00:00
|
|
|
me.api.asc_setDocumentProtection(Asc.c_oAscEDocProtect.None);
|
2022-09-21 14:15:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onAppReady: function (config) {
|
|
|
|
if (!this.view) return;
|
|
|
|
|
|
|
|
var me = this;
|
|
|
|
(new Promise(function (resolve) {
|
|
|
|
resolve();
|
|
|
|
})).then(function () {
|
2022-10-03 10:44:27 +00:00
|
|
|
var props = me.api.asc_getDocumentProtection(),
|
|
|
|
isProtected = props && (props[0] === Asc.c_oAscEDocProtect.ReadOnly || props[0] === Asc.c_oAscEDocProtect.Comments ||
|
|
|
|
props[0] === Asc.c_oAscEDocProtect.TrackedChanges || props[0] === Asc.c_oAscEDocProtect.Forms);
|
|
|
|
|
|
|
|
me.view.btnProtectDoc.toggle(!!isProtected, true);
|
2022-09-21 14:15:33 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onChangeProtectDocument: function() {
|
2022-10-03 10:44:27 +00:00
|
|
|
var props = this.getDocProps(true),
|
|
|
|
isProtected = props && (props[0] === Asc.c_oAscEDocProtect.ReadOnly || props[0] === Asc.c_oAscEDocProtect.Comments ||
|
|
|
|
props[0] === Asc.c_oAscEDocProtect.TrackedChanges || props[0] === Asc.c_oAscEDocProtect.Forms);
|
2022-09-23 12:13:58 +00:00
|
|
|
this.view && this.view.btnProtectDoc.toggle(isProtected, true);
|
2022-10-03 10:44:27 +00:00
|
|
|
Common.NotificationCenter.trigger('protect:doclock', props);
|
2022-09-21 14:15:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getDocProps: function(update) {
|
|
|
|
if (!this.appConfig || !this.appConfig.isEdit && !this.appConfig.isRestrictedEdit) return;
|
|
|
|
|
2022-09-27 22:01:27 +00:00
|
|
|
if (update || !this._state.docProtection) {
|
2022-10-03 10:44:27 +00:00
|
|
|
var props = this.api.asc_getDocumentProtection(),
|
|
|
|
type = props ? props[0] : Asc.c_oAscEDocProtect.None;
|
2022-09-27 22:01:27 +00:00
|
|
|
this._state.docProtection = {
|
2022-10-03 10:44:27 +00:00
|
|
|
isReadOnly: type===Asc.c_oAscEDocProtect.ReadOnly,
|
|
|
|
isCommentsOnly: type===Asc.c_oAscEDocProtect.Comments,
|
|
|
|
isReviewOnly: type===Asc.c_oAscEDocProtect.TrackedChanges,
|
|
|
|
isFormsOnly: type===Asc.c_oAscEDocProtect.Forms
|
2022-09-27 22:01:27 +00:00
|
|
|
};
|
2022-09-21 14:15:33 +00:00
|
|
|
}
|
2022-09-27 22:01:27 +00:00
|
|
|
return this._state.docProtection;
|
2022-09-21 14:15:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}, DE.Controllers.DocProtection || {}));
|
|
|
|
});
|