[Libreoffice-commits] online.git: 2 commits - loleaflet/js loleaflet/src
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Jan 1 22:40:37 UTC 2019
loleaflet/js/toolbar.js | 3
loleaflet/src/control/Signing.js | 207 ++++++++++++++++++++++-----------------
2 files changed, 123 insertions(+), 87 deletions(-)
New commits:
commit 8ddfbead3ca62146a316f1e7959a0c11b4a65075
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Jan 1 22:00:52 2019 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Jan 1 23:40:30 2019 +0100
add functions to get API, iframe and WOPI URL for Vereign
Change-Id: Ib97b696f5a3965c4bdf6ddc79aa4cab196630ce2
Reviewed-on: https://gerrit.libreoffice.org/65785
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/loleaflet/src/control/Signing.js b/loleaflet/src/control/Signing.js
index 7c308c482..5f2bc61b8 100644
--- a/loleaflet/src/control/Signing.js
+++ b/loleaflet/src/control/Signing.js
@@ -29,6 +29,16 @@ function getVereignWopiURL() {
return vereignURL + '/wopi/';
}
+function getVereignApiURL() {
+ var vereignURL = window.documentSigningURL == null ? '' : window.documentSigningURL;
+ return vereignURL + '/api/';
+}
+
+function getVereignIFrameURL() {
+ var vereignURL = window.documentSigningURL == null ? '' : window.documentSigningURL;
+ return vereignURL + '/vcl/js/iframe';
+}
+
function randomName() {
return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);
}
@@ -495,8 +505,8 @@ L.Map.include({
}
}
},
- vereignURL + '/vcl/js/iframe',
- vereignURL + '/api/',
+ getVereignIFrameURL(),
+ getVereignApiURL(),
getVereignWopiURL()
).then(function(lib) {
library = lib;
commit 4656bdcb38fef68410d4ce62517ccc9732cddba6
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue Jan 1 21:58:28 2019 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Jan 1 23:40:18 2019 +0100
Combine Sign and Upload to one action
First the document is signed, then when the signature status is
returned, upload to Vereign.
Change-Id: I02a3a3d401cffa295751483ba85bd45c22c7950f
Reviewed-on: https://gerrit.libreoffice.org/65784
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/loleaflet/js/toolbar.js b/loleaflet/js/toolbar.js
index 0d7335049..7b42ae28a 100644
--- a/loleaflet/js/toolbar.js
+++ b/loleaflet/js/toolbar.js
@@ -1096,8 +1096,7 @@ function initNormalToolbar(toolItems) {
items: [
{type: 'html', id: 'left'},
{type: 'html', id: 'logo', html: '<p><b>Vereign</b></p>'},
- {type: 'button', id: 'sign', caption: _('Sign'), img: '', hint: _('Sign document')},
- {type: 'button', id: 'upload', caption: _('Upload'), img: '', hint: _('Upload document')},
+ {type: 'button', id: 'sign-upload', caption: _('Sign & Upload'), img: '', hint: _('Sign and upload document')},
{type: 'break' },
{type: 'html', id: 'identity-label', html: '<b>' + _('Identity:') + ' </b>'},
{type: 'html', id: 'identity', html: _('N/A')},
diff --git a/loleaflet/src/control/Signing.js b/loleaflet/src/control/Signing.js
index 1450d2615..7c308c482 100644
--- a/loleaflet/src/control/Signing.js
+++ b/loleaflet/src/control/Signing.js
@@ -14,6 +14,8 @@ var oldtoolbarSize = null;
var _map = null;
var currentDocumentSigningStatus = 'N/A'
+var awaitForDocumentStatusToUpload = false;
+
function isSuccess(result) {
return result.code == '200';
}
@@ -22,6 +24,22 @@ function haveIdentity() {
return identity != null;
}
+function getVereignWopiURL() {
+ var vereignURL = window.documentSigningURL == null ? '' : window.documentSigningURL;
+ return vereignURL + '/wopi/';
+}
+
+function randomName() {
+ return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);
+}
+
+function getCurrentDocumentFilename(documentType) {
+ var filename = _map['wopi'].BaseFileName;
+ if (!filename)
+ filename = randomName() + '.' + documentType;
+ return filename;
+}
+
function updateIndentity() {
if (library) {
if (identity) {
@@ -121,8 +139,7 @@ function adjustUIState() {
if (currentPassport) {
w2ui['document-signing-bar'].show('passport');
w2ui['document-signing-bar'].show('current-passport');
- w2ui['document-signing-bar'].show('sign');
- w2ui['document-signing-bar'].show('upload');
+ w2ui['document-signing-bar'].show('sign-upload');
}
else {
w2ui['document-signing-bar'].show('passport');
@@ -265,8 +282,86 @@ function vereignRestoreIdentity() {
});
}
-function randomName() {
- return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36);
+function vereignSign() {
+ if (library == null) {
+ return;
+ }
+ if (currentPassport == null) {
+ return;
+ }
+ library.getOneTimeCertificateByPassport(currentPassport.uuid).then(function(result) {
+ if (isSuccess(result)) {
+ var otp = result.data;
+ var blob = new Blob(['signdocument\n', JSON.stringify(otp)]);
+ _map._socket.sendMessage(blob);
+ awaitForDocumentStatusToUpload = true;
+ checkCurrentDocument();
+ }
+ });
+}
+
+function vereignUploadForType(uploadDocType) {
+ var vereignWopiUrl = getVereignWopiURL();
+ if (vereignWopiUrl == null || vereignWopiUrl == '')
+ return;
+
+ var documentType = null;
+
+ switch (uploadDocType) {
+ case 'ODT':
+ documentType = 'odt';
+ break;
+ case 'DOCX':
+ documentType = 'docx';
+ break;
+ case 'PDF':
+ documentType = 'pdf';
+ break;
+ }
+
+ if (documentType == null)
+ return;
+
+ var filename = getCurrentDocumentFilename(documentType);
+
+ library.getPassports(filename).then(function(result) {
+ if (!isSuccess(result)) {
+ return;
+ }
+ var resultArray = result.data;
+ for (var i = 0; i < resultArray.length; i++) {
+ if (currentPassport.uuid == resultArray[i].PassportUUID) {
+ var jsonRequest = {
+ filename: filename,
+ wopiUrl: vereignWopiUrl + 'files/',
+ token: resultArray[i].AccessToken,
+ type: documentType
+ };
+ var blob = new Blob(['uploadsigneddocument\n', JSON.stringify(jsonRequest)]);
+ _map._socket.sendMessage(blob);
+ // Let the user know that we're done.
+ _map.fire('infobar', {
+ msg: _('Document uploaded.') + '\n\n' + filename,
+ action: null,
+ actionLabel: null
+ });
+ }
+ }
+ });
+}
+
+function vereignUploadDialog() {
+ if (library == null) {
+ return;
+ }
+
+ vex.dialog.open({
+ message: _('Select document type to upload'),
+ input: _('Type:') + '<select name="selection"><option value="ODT">ODT</option><option value="DOCX">DOCX</option><option value="PDF">PDF</option></select>',
+ callback: function(data) {
+ vereignUploadForType(data.selection);
+ }
+ });
}
L.Map.include({
@@ -293,79 +388,8 @@ L.Map.include({
$('#document-signing-bar').hide();
adjustUIState();
},
- signDocument: function() {
- if (library) {
- var map = this;
- if (currentPassport) {
- library.getOneTimeCertificateByPassport(currentPassport.uuid).then(function(result) {
- if (isSuccess(result)) {
- var otp = result.data;
- var blob = new Blob(['signdocument\n', JSON.stringify(otp)]);
- map._socket.sendMessage(blob);
- checkCurrentDocument();
- }
- });
- }
- }
- },
- uploadToVereign: function() {
- if (library == null) {
- return;
- }
-
- var map = this;
-
- vex.dialog.open({
- message: _('Select document type to upload'),
- input: _('Type:') + '<select name="selection"><option value="ODT">ODT</option><option value="DOCX">DOCX</option><option value="PDF">PDF</option></select>',
- callback: function(data) {
- var documentType = null;
-
- switch (data.selection) {
- case 'ODT':
- documentType = 'odt';
- break;
- case 'DOCX':
- documentType = 'docx';
- break;
- case 'PDF':
- documentType = 'pdf';
- break;
- }
-
- if (documentType == null)
- return;
-
- var filename = map['wopi'].BaseFileName;
- if (!filename)
- filename = randomName() + '.' + documentType;
-
- library.getPassports(filename).then(function(result) {
- var vereignURL = window.documentSigningURL == null ? '' : window.documentSigningURL;
- if (isSuccess(result)) {
- var resultArray = result.data;
- for (var i = 0; i < resultArray.length; i++) {
- if (currentPassport.uuid == resultArray[i].PassportUUID) {
- var jsonRequest = {
- filename: filename,
- wopiUrl: vereignURL + '/wopi/files',
- token: resultArray[i].AccessToken,
- type: documentType
- };
- var blob = new Blob(['uploadsigneddocument\n', JSON.stringify(jsonRequest)]);
- map._socket.sendMessage(blob);
- // Let the user know that we're done.
- map.fire('infobar', {
- msg: _('Document uploaded.') + '\n\n' + filename,
- action: null,
- actionLabel: null
- });
- }
- }
- }
- });
- }
- });
+ signAndUploadDocument: function() {
+ vereignSign();
},
signingLogout: function() {
if (library) {
@@ -473,7 +497,7 @@ L.Map.include({
},
vereignURL + '/vcl/js/iframe',
vereignURL + '/api/',
- vereignURL + '/wopi/'
+ getVereignWopiURL()
).then(function(lib) {
library = lib;
adjustUIState();
@@ -499,11 +523,8 @@ L.Map.include({
else if (id === 'logout') {
this.signingLogout();
}
- else if (id === 'sign') {
- this.signDocument();
- }
- else if (id === 'upload') {
- this.uploadToVereign();
+ else if (id === 'sign-upload') {
+ this.signAndUploadDocument();
}
else if (id.startsWith('passport:')) {
this.setCurrentPassport(item.value, item.text);
@@ -549,5 +570,11 @@ L.Map.include({
}
adjustUIState();
+
+ if (awaitForDocumentStatusToUpload) {
+ awaitForDocumentStatusToUpload = false;
+ vereignUploadDialog();
+ }
+ awaitForDocumentStatusToUpload = false;
}
});
More information about the Libreoffice-commits
mailing list