diff --git a/apps/documenteditor/main/app/controller/LeftMenu.js b/apps/documenteditor/main/app/controller/LeftMenu.js index 89703bcf0..4a0ca7fc1 100644 --- a/apps/documenteditor/main/app/controller/LeftMenu.js +++ b/apps/documenteditor/main/app/controller/LeftMenu.js @@ -137,6 +137,7 @@ define([ this.api.asc_registerCallback('asc_onReplaceAll', _.bind(this.onApiTextReplaced, this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(this.onApiServerDisconnect, this, true)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiServerDisconnect, this)); + this.api.asc_registerCallback('on_signature_defaultcertificate_ret', _.bind(this.onDefaultCertificate, this)); /** coauthoring begin **/ if (this.mode.canCoAuthoring) { if (this.mode.canChat) @@ -694,6 +695,12 @@ define([ }, addInvisibleSign: function(menu) { + this.api.asc_GetDefaultCertificate(); + menu.hide(); + this.leftMenu.btnFile.toggle(false, true); + }, + + onDefaultCertificate: function(certificate) { var me = this, win = new DE.Views.SignDialog({ api: me.api, @@ -701,18 +708,14 @@ define([ handler: function(dlg, result) { if (result == 'ok') { var props = dlg.getSettings(); - me.api.asc_Sign(); + me.api.asc_Sign(props.certificateId); } Common.NotificationCenter.trigger('edit:complete'); } }); win.show(); - win.setSettings({}); - // win.setSettings(me.api.asc_getCertificateSettings()); - - menu.hide(); - this.leftMenu.btnFile.toggle(false, true); + win.setSettings(certificate); }, textNoTextFound : 'Text not found', diff --git a/apps/documenteditor/main/app/view/DocumentHolder.js b/apps/documenteditor/main/app/view/DocumentHolder.js index 803b8ac73..ce3007401 100644 --- a/apps/documenteditor/main/app/view/DocumentHolder.js +++ b/apps/documenteditor/main/app/view/DocumentHolder.js @@ -52,7 +52,8 @@ define([ 'documenteditor/main/app/view/DropcapSettingsAdvanced', 'documenteditor/main/app/view/HyperlinkSettingsDialog', 'documenteditor/main/app/view/ParagraphSettingsAdvanced', - 'documenteditor/main/app/view/TableSettingsAdvanced' + 'documenteditor/main/app/view/TableSettingsAdvanced', + 'documenteditor/main/app/view/SignDialog' ], function ($, _, Backbone, gateway) { 'use strict'; DE.Views.DocumentHolder = Backbone.View.extend(_.extend({ @@ -80,6 +81,7 @@ define([ me._currentMathObj = undefined; me._currentParaObjDisabled = false; me._isDisabled = false; + me._currentSignGuid = null; var showPopupMenu = function(menu, value, event, docElement, eOpts){ if (!_.isUndefined(menu) && menu !== null){ @@ -724,6 +726,28 @@ define([ me.mode.isEdit = false; }; + var onSignatureClick = function(guid) { + me._currentSignGuid = guid; + me.api.asc_GetDefaultCertificate(); + }; + + var onDefaultCertificate = function(certificate) { + var win = new DE.Views.SignDialog({ + api: me.api, + signType: 'visible', + handler: function(dlg, result) { + if (result == 'ok') { + var props = dlg.getSettings(); + me.api.asc_Sign(props.certificateId, me._currentSignGuid, props.image); + } + Common.NotificationCenter.trigger('edit:complete'); + } + }); + + win.show(); + win.setSettings(certificate); + }; + var onTextLanguage = function(langid) { me._currLang.id = langid; }; @@ -1528,6 +1552,8 @@ define([ this.api.asc_registerCallback('asc_onShowSpecialPasteOptions', _.bind(onShowSpecialPasteOptions, this)); this.api.asc_registerCallback('asc_onHideSpecialPasteOptions', _.bind(onHideSpecialPasteOptions, this)); + this.api.asc_registerCallback('asc_onSignatureClick', _.bind(onSignatureClick, this)); + this.api.asc_registerCallback('on_signature_defaultcertificate_ret', _.bind(onDefaultCertificate, this)); } return this; diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 0a89d76dc..b6d79d9e7 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -1188,10 +1188,20 @@ define([ updateSignatures: function(){ var requested = this.api.asc_getRequestSignatures(), - valid = this.api.asc_getSignatures(); - // this.cntRequestedSign.html(this.templateRequested({signatures: this.api.asc_getRequestSignatures(), header: this.strRequested})); - // this.cntValidSign.html(this.templateValid({signatures: this.api.asc_getValidSignatures(), header: this.strValid})); - // this.cntInvalidSign.html(this.templateInvalid({signatures: this.api.asc_getInvalidSignatures(), header: this.strInvalid})); + requested_arr = [], + valid = this.api.asc_getSignatures(), + valid_arr = [], invalid_arr = []; + + _.each(requested, function(item, index){ + requested_arr.push(item.asc_getSigner1()); + }); + _.each(valid, function(item, index){ + var sign = {name: item.asc_getSigner1(), date: '18/05/2017'}; + (item.asc_getValid()) ? valid_arr.push(sign) : invalid_arr.push(sign); + }); + this.cntRequestedSign.html(this.templateRequested({signatures: requested_arr, header: this.strRequested})); + this.cntValidSign.html(this.templateValid({signatures: valid_arr, header: this.strValid})); + this.cntInvalidSign.html(this.templateValid({signatures: invalid_arr, header: this.strInvalid})); // this.cntRequestedSign.html(this.templateRequested({signatures: ['Hammish Mitchell', 'Someone Somewhere', 'Mary White', 'John Black'], header: this.strRequested})); // this.cntValidSign.html(this.templateValid({signatures: [{name: 'Hammish Mitchell', date: '18/05/2017'}, {name: 'Someone Somewhere', date: '18/05/2017'}], header: this.strValid})); // this.cntInvalidSign.html(this.templateValid({signatures: [{name: 'Mary White', date: '18/05/2017'}, {name: 'John Black', date: '18/05/2017'}], header: this.strInvalid})); diff --git a/apps/documenteditor/main/app/view/SignDialog.js b/apps/documenteditor/main/app/view/SignDialog.js index 9f78fde18..9158d2569 100644 --- a/apps/documenteditor/main/app/view/SignDialog.js +++ b/apps/documenteditor/main/app/view/SignDialog.js @@ -62,6 +62,7 @@ define([ this.api = this.options.api; this.signType = this.options.signType || 'invisible'; + this.certificateId = null; this.template = [ '
', @@ -152,18 +153,23 @@ define([ setSettings: function (props) { if (props) { var me = this, - name = 'Hammish Mitchell',//props.asc_getName(), - from = '1/02/2011',//props.asc_getFrom(), - to = '1/02/2021';//props.asc_getTo(); - - this.cntCertificate.html(this.templateCertificate({name: name, valid: this.textValid.replace('%1', from).replace('%2', to)})); + name = (props.name) ? props.name : '', + date = props.date, + arr_date = (typeof date == 'string') ? date.split(' - ') : ['', '']; + this.cntCertificate.html(this.templateCertificate({name: name, valid: this.textValid.replace('%1', arr_date[0]).replace('%2', arr_date[1])})); + this.certificateId = props.id; + } + if (this.api) { + this.api.asc_unregisterCallback('on_signature_selectsertificate_ret', _.bind(this.onCertificateChanged, this)); + this.api.asc_registerCallback('on_signature_selectsertificate_ret', _.bind(this.onCertificateChanged, this)); } }, getSettings: function () { - var me = this, props; - if (me.signType == 'invisible') { - // props.asc_putPurpose(me.inputPurpose.getValue()); + var props = {}; + props.certificateId = this.certificateId; + if (this.signType == 'invisible') { + props.purpose(this.inputPurpose.getValue()); } else { // props.asc_putName(me.inputName.getValue()); } @@ -189,7 +195,14 @@ define([ }, onChangeCertificate: function() { - // this.api.asc_changeCertificate(); + this.api.asc_SelectCertificate(); + }, + + onCertificateChanged: function(certificate) { + this.certificateId = certificate.id; + var date = certificate.date, + arr_date = (typeof date == 'string') ? date.split(' - ') : ['', '']; + this.cntCertificate.html(this.templateCertificate({name: certificate.name, valid: this.textValid.replace('%1', arr_date[0]).replace('%2', arr_date[1])})); }, textTitle: 'Sign Document', diff --git a/apps/documenteditor/main/app/view/SignSettingsDialog.js b/apps/documenteditor/main/app/view/SignSettingsDialog.js index 177e50ced..c52feddc9 100644 --- a/apps/documenteditor/main/app/view/SignSettingsDialog.js +++ b/apps/documenteditor/main/app/view/SignSettingsDialog.js @@ -146,15 +146,15 @@ define([ if (props) { var me = this; - // var value = props.asc_getName(); + // var value = props.asc_getSigner1(); // me.inputName.setValue(value ? value : ''); - // value = props.asc_getTitle(); + // value = props.asc_getSigner2(); // me.inputTitle.setValue(value ? value : ''); // value = props.asc_getEmail(); // me.inputEmail.setValue(value ? value : ''); // value = props.asc_getInstructions(); // me.textareaInstructions.val(value ? value : ''); - // me.chDate.setValue(props.asc_getDate()); + // me.chDate.setValue(props.asc_getShowDate()); } },