2017-11-15 07:59:06 +00:00
|
|
|
/*
|
|
|
|
*
|
2019-01-17 12:58:05 +00:00
|
|
|
* (c) Copyright Ascensio System Limited 2010-2019
|
2017-11-15 07:59:06 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2019-01-17 13:00:34 +00:00
|
|
|
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
|
|
|
* street, Riga, Latvia, EU, LV-1050.
|
2017-11-15 07:59:06 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Protection.js
|
|
|
|
*
|
|
|
|
* Created by Julia Radzhabova on 14.11.2017
|
2018-03-01 12:16:38 +00:00
|
|
|
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
|
2017-11-15 07:59:06 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (Common === undefined)
|
|
|
|
var Common = {};
|
|
|
|
Common.Controllers = Common.Controllers || {};
|
|
|
|
|
|
|
|
define([
|
|
|
|
'core',
|
|
|
|
'common/main/lib/view/Protection',
|
|
|
|
'common/main/lib/view/PasswordDialog',
|
|
|
|
'common/main/lib/view/SignDialog',
|
|
|
|
'common/main/lib/view/SignSettingsDialog'
|
|
|
|
], function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Common.Controllers.Protection = Backbone.Controller.extend(_.extend({
|
|
|
|
models : [],
|
|
|
|
collections : [
|
|
|
|
],
|
|
|
|
views : [
|
|
|
|
'Common.Views.Protection'
|
|
|
|
],
|
|
|
|
sdkViewName : '#id_main',
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
|
|
|
|
this.addListeners({
|
|
|
|
'Common.Views.Protection': {
|
|
|
|
'protect:password': _.bind(this.onPasswordClick, this),
|
|
|
|
'protect:signature': _.bind(this.onSignatureClick, this)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onLaunch: function () {
|
|
|
|
this._state = {};
|
|
|
|
|
|
|
|
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
|
2017-11-23 13:29:05 +00:00
|
|
|
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
|
2017-11-15 07:59:06 +00:00
|
|
|
},
|
|
|
|
setConfig: function (data, api) {
|
|
|
|
this.setApi(api);
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
this.sdkViewName = data['sdkviewname'] || this.sdkViewName;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setApi: function (api) {
|
|
|
|
if (api) {
|
|
|
|
this.api = api;
|
|
|
|
|
2018-08-01 16:08:24 +00:00
|
|
|
if (this.appConfig.isPasswordSupport)
|
2017-11-15 07:59:06 +00:00
|
|
|
this.api.asc_registerCallback('asc_onDocumentPassword', _.bind(this.onDocumentPassword, this));
|
2018-08-01 16:08:24 +00:00
|
|
|
if (this.appConfig.isSignatureSupport) {
|
|
|
|
Common.NotificationCenter.on('protect:sign', _.bind(this.onSignatureRequest, this));
|
|
|
|
Common.NotificationCenter.on('protect:signature', _.bind(this.onSignatureClick, this));
|
|
|
|
this.api.asc_registerCallback('asc_onSignatureClick', _.bind(this.onSignatureSign, this));
|
|
|
|
this.api.asc_registerCallback('asc_onUpdateSignatures', _.bind(this.onApiUpdateSignatures, this));
|
2017-11-15 07:59:06 +00:00
|
|
|
}
|
2017-11-23 13:29:05 +00:00
|
|
|
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
|
2017-11-15 07:59:06 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setMode: function(mode) {
|
|
|
|
this.appConfig = mode;
|
|
|
|
|
|
|
|
this.view = this.createView('Common.Views.Protection', {
|
|
|
|
mode: mode
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-06-14 12:11:50 +00:00
|
|
|
onDocumentPassword: function(hasPassword, disabled) {
|
|
|
|
this.view && this.view.onDocumentPassword(hasPassword, disabled);
|
2017-11-15 07:59:06 +00:00
|
|
|
},
|
|
|
|
|
2017-11-23 13:29:05 +00:00
|
|
|
SetDisabled: function(state, canProtect) {
|
|
|
|
this.view && this.view.SetDisabled(state, canProtect);
|
2017-11-15 07:59:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onPasswordClick: function(btn, opts){
|
|
|
|
switch (opts) {
|
|
|
|
case 'add': this.addPassword(); break;
|
2017-11-15 08:40:36 +00:00
|
|
|
case 'delete': this.deletePassword(); break;
|
2017-11-15 07:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.view);
|
|
|
|
},
|
|
|
|
|
2017-11-17 08:44:36 +00:00
|
|
|
onSignatureRequest: function(guid){
|
|
|
|
this.api.asc_RequestSign(guid);
|
|
|
|
},
|
|
|
|
|
2017-11-16 13:06:55 +00:00
|
|
|
onSignatureClick: function(type, signed, guid){
|
|
|
|
switch (type) {
|
2017-11-17 09:23:31 +00:00
|
|
|
case 'invisible': this.onSignatureRequest('unvisibleAdd'); break;
|
2017-11-16 13:06:55 +00:00
|
|
|
case 'visible': this.addVisibleSignature(signed, guid); break;
|
2017-11-15 07:59:06 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
createToolbarPanel: function() {
|
|
|
|
return this.view.getPanel();
|
|
|
|
},
|
|
|
|
|
|
|
|
getView: function(name) {
|
|
|
|
return !name && this.view ?
|
|
|
|
this.view : Backbone.Controller.prototype.getView.call(this, name);
|
|
|
|
},
|
|
|
|
|
|
|
|
onAppReady: function (config) {
|
|
|
|
},
|
|
|
|
|
|
|
|
addPassword: function() {
|
|
|
|
var me = this,
|
|
|
|
win = new Common.Views.PasswordDialog({
|
|
|
|
api: me.api,
|
|
|
|
signType: 'invisible',
|
|
|
|
handler: function(result, props) {
|
|
|
|
if (result == 'ok') {
|
2017-11-15 08:40:36 +00:00
|
|
|
me.api.asc_setCurrentPassword(props);
|
2017-11-15 07:59:06 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
win.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
deletePassword: function() {
|
2017-11-15 08:40:36 +00:00
|
|
|
this.api.asc_resetPassword();
|
2017-11-15 07:59:06 +00:00
|
|
|
},
|
|
|
|
|
2017-11-16 13:06:55 +00:00
|
|
|
addInvisibleSignature: function() {
|
2017-11-15 07:59:06 +00:00
|
|
|
var me = this,
|
|
|
|
win = new Common.Views.SignDialog({
|
|
|
|
api: me.api,
|
|
|
|
signType: 'invisible',
|
|
|
|
handler: function(dlg, result) {
|
|
|
|
if (result == 'ok') {
|
|
|
|
var props = dlg.getSettings();
|
|
|
|
me.api.asc_Sign(props.certificateId);
|
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
win.show();
|
|
|
|
},
|
|
|
|
|
2017-11-16 13:06:55 +00:00
|
|
|
addVisibleSignature: function(signed, guid) {
|
2017-11-15 07:59:06 +00:00
|
|
|
var me = this,
|
|
|
|
win = new Common.Views.SignSettingsDialog({
|
2017-11-16 13:06:55 +00:00
|
|
|
type: (!signed) ? 'edit' : 'view',
|
2017-11-15 07:59:06 +00:00
|
|
|
handler: function(dlg, result) {
|
2017-11-16 13:06:55 +00:00
|
|
|
if (!signed && result == 'ok') {
|
2017-11-15 07:59:06 +00:00
|
|
|
me.api.asc_AddSignatureLine2(dlg.getSettings());
|
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
win.show();
|
2017-11-16 13:06:55 +00:00
|
|
|
|
|
|
|
if (guid)
|
|
|
|
win.setSettings(this.api.asc_getSignatureSetup(guid));
|
2017-11-15 07:59:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
signVisibleSignature: function(guid, width, height) {
|
|
|
|
var me = this;
|
|
|
|
if (_.isUndefined(me.fontStore)) {
|
|
|
|
me.fontStore = new Common.Collections.Fonts();
|
|
|
|
var fonts = me.getApplication().getController('Toolbar').getView('Toolbar').cmbFontName.store.toJSON();
|
|
|
|
var arr = [];
|
|
|
|
_.each(fonts, function(font, index){
|
|
|
|
if (!font.cloneid) {
|
|
|
|
arr.push(_.clone(font));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
me.fontStore.add(arr);
|
|
|
|
}
|
|
|
|
|
|
|
|
var win = new Common.Views.SignDialog({
|
|
|
|
api: me.api,
|
|
|
|
signType: 'visible',
|
|
|
|
fontStore: me.fontStore,
|
|
|
|
signSize: {width: width || 0, height: height || 0},
|
|
|
|
handler: function(dlg, result) {
|
|
|
|
if (result == 'ok') {
|
|
|
|
var props = dlg.getSettings();
|
|
|
|
me.api.asc_Sign(props.certificateId, guid, props.images[0], props.images[1]);
|
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
win.show();
|
|
|
|
},
|
|
|
|
|
2017-11-17 08:44:36 +00:00
|
|
|
onSignatureSign: function(guid, width, height, isVisible) {
|
|
|
|
(isVisible) ? this.signVisibleSignature(guid, width, height) : this.addInvisibleSignature();
|
2017-11-15 08:40:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onApiUpdateSignatures: function(valid, requested){
|
2017-11-23 13:29:05 +00:00
|
|
|
this.SetDisabled(valid && valid.length>0, true);// can add invisible signature
|
|
|
|
},
|
|
|
|
|
|
|
|
onCoAuthoringDisconnect: function() {
|
|
|
|
this.SetDisabled(true);
|
2017-11-15 07:59:06 +00:00
|
|
|
}
|
2017-11-15 08:40:36 +00:00
|
|
|
|
2017-11-15 07:59:06 +00:00
|
|
|
}, Common.Controllers.Protection || {}));
|
|
|
|
});
|