Skip to content

Commit 67a372d

Browse files
committed
signature: open file from nextcloud webdav
1 parent fd38e19 commit 67a372d

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

public/js/common.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const modalLoading = new bootstrap.Modal('#modalLoading')
2+
let davTokenReceived = null;
3+
const isIframe = window.parent !== window;
24

35
function is_mobile() {
46
return !(window.getComputedStyle(document.getElementById('is_mobile')).display === "none");
@@ -313,3 +315,20 @@ function debounce(callback, delay){
313315
}, delay)
314316
}
315317
}
318+
319+
window.addEventListener('message', function(event) {
320+
if (event.data.action === 'davOpenFile' && event.data.key == "token") {
321+
davTokenReceived = event.data.value
322+
console.log(event.data)
323+
}
324+
});
325+
326+
if(document.getElementById('btn_exit')) {
327+
document.getElementById('btn_exit').addEventListener('click', function(e) {
328+
if(isIframe) {
329+
window.parent.postMessage({action: 'exit'}, '*');
330+
e.preventDefault();
331+
return;
332+
}
333+
});
334+
}

public/js/metadata.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ let pdffile = null
44
let deletedMetadata = [];
55
let isLocalPath = false;
66
let isDavPath = false;
7-
let isIframe = Boolean(window.parent);
8-
let davTokenReceived = null;
97
let hasModifications = false;
108
let sizeOfText = 0;
119
let pdf = null;
@@ -230,9 +228,6 @@ window.addEventListener('message', function(event) {
230228
}
231229
setIsChanged(true);
232230
}
233-
if (event.data.action === 'davOpenFile' && event.data.key == "token") {
234-
davTokenReceived = event.data.value
235-
}
236231
});
237232

238233
function updateMetadataInfos() {
@@ -492,14 +487,6 @@ function createEventsListener() {
492487
}
493488
followText(e.target, '#container-pages .textLayer span', '#pdf_text span', true);
494489
});
495-
496-
document.getElementById('btn_exit').addEventListener('click', function(e) {
497-
if(isIframe) {
498-
window.parent.postMessage({action: 'exit'}, '*');
499-
e.preventDefault();
500-
return;
501-
}
502-
});
503490
}
504491

505492
function followText(element, selectorFrom, selectorTo, hide) {

public/js/signature.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ let hasModifications = false;
2323
let currentTextScale = 1;
2424
const defaultScale = 1.5;
2525
let customText = '';
26+
let isDavPath = false;
2627

2728
fabric.Object.prototype.controls.mtr.x = 0;
2829
fabric.Object.prototype.controls.mtr.y = 0.5; // bas de l'objet
@@ -1391,7 +1392,7 @@ async function pageSignature(url) {
13911392
fontCaveat = font;
13921393
});
13931394

1394-
if(url && url.match(/^cache:\/\//)) {
1395+
if(url && url.match(/^cache:\/\//) && !isDavPath) {
13951396
await loadFileFromCache(url.replace(/^cache:\/\//, ''));
13961397
} else if (url) {
13971398
await loadFileFromUrl(url);
@@ -1434,6 +1435,9 @@ document.addEventListener('DOMContentLoaded', function () {
14341435
pageSignature('/signature/'+pdfHash+'/pdf');
14351436
} else if(window.location.hash && window.location.hash.match(/^\#http/)) {
14361437
pageSignature(window.location.hash.replace(/^\#/, ''));
1438+
} else if(window.location.hash && window.location.hash.match(/^\#dav:/)) {
1439+
isDavPath = true;
1440+
pageSignature(window.location.hash.replace(/^\#dav:/, ''));
14371441
} else if(window.location.hash) {
14381442
pageSignature('cache:///pdf/'+window.location.hash.replace(/^\#/, ''));
14391443
} else {

templates/signature.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</div>
3939
<div style="height: 55px;" class="d-md-none"></div>
4040
<div class="offcanvas offcanvas-end show d-none d-md-block shadow-sm" data-bs-backdrop="false" data-bs-scroll="true" data-bs-keyboard="false" tabindex="-1" id="sidebarTools" aria-labelledby="sidebarToolsLabel">
41-
<a class="btn btn-close btn-sm position-absolute d-none d-sm-none d-md-block" style="right: 16px; top: 16px;" title="<?php echo _("Close this PDF and return to the homepage"); ?>" href="<?php echo $REVERSE_PROXY_URL; ?>/signature"></a>
41+
<a id="btn_exit" class="btn btn-close btn-sm position-absolute d-none d-sm-none d-md-block" style="right: 16px; top: 16px;" title="<?php echo _("Close this PDF and return to the homepage"); ?>" href="<?php echo $REVERSE_PROXY_URL; ?>/signature"></a>
4242
<div class="offcanvas-header mb-0 pb-0">
4343
<h5 class="mb-1 d-block w-100" id="sidebarToolsLabel"><i class="bi bi-vector-pen"></i> <?php echo _("PDF Signature"); ?> <?php if(isset($hash)): ?><span class="badge rounded-pill text-bg-dark" title="<?php echo _("This PDF is shared with others to be signed by multiple people"); ?>"><span class="nblayers"></span> <i class="bi bi-people-fill"></i></span><?php endif; ?></h5>
4444
<button type="button" class="btn-close text-reset d-md-none" data-bs-dismiss="offcanvas" aria-label="Close"></button>

0 commit comments

Comments
 (0)