From 030ad8ea8455922ad59c095d3a9ecbfc462ff69f Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Tue, 14 Jul 2015 13:27:56 +0200 Subject: many fixes for html5 js viewer integration --- pdf-as-web/src/main/webapp/assets/js/dragNdrop.js | 8 ++- .../src/main/webapp/assets/js/pdf.js/web/app.js | 70 ++++++++++++++++----- .../assets/js/pdf.js/web/images/signature-icon.png | Bin 0 -> 417 bytes .../js/pdf.js/web/images/signature-icon@2x.png | Bin 0 -> 417 bytes .../main/webapp/assets/js/pdf.js/web/viewer.css | 5 ++ .../main/webapp/assets/js/pdf.js/web/viewer.html | 7 ++- 6 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/signature-icon.png create mode 100644 pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/signature-icon@2x.png (limited to 'pdf-as-web/src/main/webapp/assets') diff --git a/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js b/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js index 940804bd..fd05f81b 100644 --- a/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js +++ b/pdf-as-web/src/main/webapp/assets/js/dragNdrop.js @@ -111,7 +111,13 @@ function sign(file, connector, locale) { processData: false, contentType: false, type: "POST", + xhrFields: { + withCredentials: true + }, success: function(response) { + $("html").empty(); + $("html").html(response); + /* $("#fade").remove(); $("#popup").remove(); var fade_div = "
"; @@ -122,7 +128,7 @@ function sign(file, connector, locale) { $("#closelink").bind("click", function(evt) { $("#fade").remove(); $("#popup").remove(); - }); + });*/ } }); } diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js index 6e16c306..da71e83d 100644 --- a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js +++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/app.js @@ -12,7 +12,17 @@ function statusObject() { this.connector = null; this.file_path = null; this.file = null; - this.signature = null, + this.signature = null; + this.running = false; + this.applicationContext = '../../../../'; + + this.setRunning = function(r) { + this.running = (r === 'true'); + } + + this.getRunning = function() { + return this.running; + } this.setFile = function(f) { this.file = f; @@ -180,7 +190,7 @@ function isSignaturePlaced() { function placeSignature(evt, page_to_place, s) { var current_scale = PDFViewerApplication.pdfViewer.currentScale; var sig_size = Math.floor(96 * current_scale); - var defaultSignature = "Signature"; + var defaultSignature = "Signature"; if (typeof page_to_place === 'undefined') { page_to_place = PDFView.page;} if (typeof s === 'undefined') { s = defaultSignature} @@ -251,13 +261,15 @@ $(document).ready(function() { if(!results) { return null; } else { - return results[1] || 0; + return decodeURIComponent(results[1]) || decodeURI(0); } } global_status.setConnector($.urlParam("connector")); global_status.setPdfUlr($.urlParam("pdfurl")); global_status.setFilePath($.urlParam("file")); + console.log("Status:", global_status); + global_status.setRunning($.urlParam("running")); if(global_status.getFilePath()) { //if a filepath is given via the file HTML get parameter, try to fetch the file and display it fetchFile(global_status.getFilePath()).then(function(result) { @@ -370,11 +382,16 @@ function quickSign(connector, pdfurl) { fd.append("connector", connector); fd.append("pdf-url", pdfurl); + var signUrl = global_status.applicationContext + "/Sign"; + $.ajax({ - url: "/pdf-as-web/Sign", + url: signUrl, data: fd, processData: false, contentType: false, + xhrFields: { + withCredentials: true + }, type: "POST", success: function(response) { $("html").empty(); @@ -397,22 +414,44 @@ function sign(statusObj) { } var fd = new FormData(); fd.append("source", "internal"); - fd.append("connector", global_status.getConnector()); - fd.append("pdf-file", global_status.getFile()); - - if(isSignaturePlaced()) { - fd.append("sig-pos-x", global_status.getSignature().posx); - fd.append("sig-pos-y", global_status.getSignature().posy); - fd.append("sig-pos-p", global_status.getSignature().page); - } + var method = "POST"; + var signUrl = global_status.applicationContext + "/Sign"; + + if(global_status.getRunning()) { + signUrl = global_status.applicationContext + "/signNow"; + method = "GET"; + fd = null; + + if(isSignaturePlaced()) { + signUrl = signUrl + "?sigPosX=" + encodeURIComponent(global_status.getSignature().posx); + signUrl = signUrl + "&sigPosY=" + encodeURIComponent(global_status.getSignature().posy); + signUrl = signUrl + "&sigPosP=" + encodeURIComponent(global_status.getSignature().page); + } + } else { + fd.append("connector", global_status.getConnector()); + fd.append("pdf-file", global_status.getFile()); + if(isSignaturePlaced()) { + fd.append("sig-pos-x", global_status.getSignature().posx); + fd.append("sig-pos-y", global_status.getSignature().posy); + fd.append("sig-pos-p", global_status.getSignature().page); + } + } + + console.log("Data:", fd); $.ajax({ - url: "/pdf-as-web/Sign", + url: signUrl, data: fd, processData: false, contentType: false, - type: "POST", + type: method, + xhrFields: { + withCredentials: true + }, success: function(response) { + $("html").empty(); + $("html").html(response); + /* $("#fade").remove(); $("#popup").remove(); var fade_div = "
"; @@ -424,6 +463,9 @@ function sign(statusObj) { $("#fade").remove(); $("#popup").remove(); }); + if(typeof onAnmeldeSubmit == 'function') { + onAnmeldeSubmit(); + }*/ } }); } diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/signature-icon.png b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/signature-icon.png new file mode 100644 index 00000000..d47bc8a0 Binary files /dev/null and b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/signature-icon.png differ diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/signature-icon@2x.png b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/signature-icon@2x.png new file mode 100644 index 00000000..d47bc8a0 Binary files /dev/null and b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/images/signature-icon@2x.png differ diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css index adba9ec6..de21f494 100644 --- a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css +++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.css @@ -1052,6 +1052,11 @@ html[dir='rtl'] .toolbarButton.pageDown::before { content: url(images/toolbarButton-openFile.png); } +.toolbarButton.createSignature::before, +.secondaryToolbarButton.createSignature::before { + content: url(images/document_signature.png); +} + .toolbarButton.placeSignature::before, .secondaryToolbarButton.placeSignature::before { content: url(images/document_signature.png); diff --git a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html index 6d49482d..c6cf575f 100644 --- a/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html +++ b/pdf-as-web/src/main/webapp/assets/js/pdf.js/web/viewer.html @@ -31,7 +31,7 @@ http://sourceforge.net/adobe/cmap/wiki/License/ - + @@ -136,6 +136,11 @@ http://sourceforge.net/adobe/cmap/wiki/License/ Open + + +