djgentelella 0.4.30__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- djgentelella/__init__.py +4 -1
- djgentelella/admin.py +7 -1
- djgentelella/firmador_digital/consumers/sign.py +24 -3
- djgentelella/firmador_digital/forms.py +140 -0
- djgentelella/firmador_digital/models.py +20 -2
- djgentelella/firmador_digital/utils.py +11 -0
- djgentelella/firmador_digital/views.py +31 -0
- djgentelella/firmador_digital/viewsets.py +15 -4
- djgentelella/forms/forms.py +10 -2
- djgentelella/groute.py +4 -1
- djgentelella/locale/es/LC_MESSAGES/django.mo +0 -0
- djgentelella/locale/es/LC_MESSAGES/django.po +67 -0
- djgentelella/locale/es/LC_MESSAGES/djangojs.mo +0 -0
- djgentelella/locale/es/LC_MESSAGES/djangojs.po +9 -0
- djgentelella/migrations/0014_trash.py +31 -0
- djgentelella/migrations/0015_trash_deleted_by.py +21 -0
- djgentelella/migrations/0016_trash_created_at.py +20 -0
- djgentelella/models.py +96 -0
- djgentelella/models_manager.py +40 -0
- djgentelella/serializers/firmador_digital.py +9 -1
- djgentelella/serializers/selects.py +14 -0
- djgentelella/static/djgentelella.flags.vendors.min.css +1 -1
- djgentelella/static/djgentelella.readonly.vendors.min.css +9 -5
- djgentelella/static/djgentelella.readonly.vendors.min.js +1 -1
- djgentelella/static/gentelella/css/custom.css +23 -2
- djgentelella/static/gentelella/css/modern.css +15 -0
- djgentelella/static/gentelella/css/modern_black_white.css +15 -0
- djgentelella/static/gentelella/css/pdfviewer.css +43 -1
- djgentelella/static/gentelella/images/default.png +0 -0
- djgentelella/static/gentelella/js/base/digital_signature.js +318 -79
- djgentelella/static/gentelella/js/base/form.common.js +9 -4
- djgentelella/static/gentelella/js/base/select2_wrap.js +15 -1
- djgentelella/static/gentelella/js/base/select2related.js +5 -0
- djgentelella/static/gentelella/js/base.js +347 -83
- djgentelella/static/gentelella/js/custom.js +6 -1
- djgentelella/static/gentelella/js/datatables.js +15 -0
- djgentelella/static/gentelella/js/digital_signature_update.js +29 -0
- djgentelella/static/gentelella/js/obj_api_management.js +403 -344
- djgentelella/static/gentelella/js/widgets.js +10 -1
- djgentelella/static/vendors/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css.map +75 -7
- djgentelella/static/vendors/flags/1x1/ac.svg +75 -7
- djgentelella/static/vendors/flags/1x1/cp.svg +75 -7
- djgentelella/static/vendors/flags/1x1/dg.svg +75 -7
- djgentelella/static/vendors/flags/1x1/ea.svg +75 -7
- djgentelella/static/vendors/flags/1x1/es-ct.svg +75 -7
- djgentelella/static/vendors/flags/1x1/es-ga.svg +75 -7
- djgentelella/static/vendors/flags/1x1/ic.svg +75 -7
- djgentelella/static/vendors/flags/1x1/ta.svg +75 -7
- djgentelella/static/vendors/flags/1x1/xx.svg +75 -7
- djgentelella/static/vendors/flags/4x3/ac.svg +75 -7
- djgentelella/static/vendors/flags/4x3/cp.svg +75 -7
- djgentelella/static/vendors/flags/4x3/dg.svg +75 -7
- djgentelella/static/vendors/flags/4x3/ea.svg +75 -7
- djgentelella/static/vendors/flags/4x3/es-ct.svg +75 -7
- djgentelella/static/vendors/flags/4x3/es-ga.svg +75 -7
- djgentelella/static/vendors/flags/4x3/ic.svg +75 -7
- djgentelella/static/vendors/flags/4x3/ta.svg +75 -7
- djgentelella/static/vendors/flags/4x3/xx.svg +75 -7
- djgentelella/static/vendors/timeline/css/timeline.css +9 -5
- djgentelella/static/vendors/timeline/js/timeline.js +1 -1
- djgentelella/templates/forms/as_grid.html +2 -2
- djgentelella/templates/forms/as_inline.html +3 -5
- djgentelella/templates/gentelella/app/sidebar.html +16 -13
- djgentelella/templates/gentelella/digital_signature/update_signature_settings.html +45 -0
- djgentelella/templates/gentelella/registration/reset_done.html +24 -0
- djgentelella/templates/gentelella/widgets/digital_signature.html +47 -11
- djgentelella/trash/api.py +58 -0
- djgentelella/trash/filterset.py +20 -0
- djgentelella/trash/serializer.py +45 -0
- djgentelella/urls.py +8 -1
- djgentelella/views/select2autocomplete.py +40 -0
- djgentelella/widgets/core.py +6 -5
- djgentelella/widgets/digital_signature.py +5 -21
- djgentelella/widgets/selects.py +47 -0
- {djgentelella-0.4.30.dist-info → djgentelella-0.5.0.dist-info}/METADATA +2 -2
- {djgentelella-0.4.30.dist-info → djgentelella-0.5.0.dist-info}/RECORD +80 -68
- {djgentelella-0.4.30.dist-info → djgentelella-0.5.0.dist-info}/AUTHORS +0 -0
- {djgentelella-0.4.30.dist-info → djgentelella-0.5.0.dist-info}/LICENSE.txt +0 -0
- {djgentelella-0.4.30.dist-info → djgentelella-0.5.0.dist-info}/WHEEL +0 -0
- {djgentelella-0.4.30.dist-info → djgentelella-0.5.0.dist-info}/top_level.txt +0 -0
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
///////////////////////////////////////////////
|
|
2
2
|
// Init widgets digital signature
|
|
3
3
|
///////////////////////////////////////////////
|
|
4
|
+
var socket_connections = {};
|
|
5
|
+
var socket_manager_instances = {};
|
|
6
|
+
const max_close_inicialice = 5;
|
|
7
|
+
var count_close_inicialice = 0;
|
|
8
|
+
|
|
9
|
+
// Configuración del MutationObserver
|
|
10
|
+
const observer = new MutationObserver((mutations) => {
|
|
11
|
+
mutations.forEach((mutation) => {
|
|
12
|
+
if (mutation.type === 'attributes' && mutation.attributeName === 'data-port') {
|
|
13
|
+
let port = mutation.target.getAttribute('data-port');
|
|
14
|
+
mutation.target.setAttribute("href",
|
|
15
|
+
"firmador:" + window.location.protocol + "//" + window.location.host + "#" + port);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
build_cors_headers = function (instance) {
|
|
21
|
+
let port = instance.getAttribute('data-port');
|
|
22
|
+
instance.setAttribute("href", "firmador:" + window.location.protocol + "//" + window.location.host + "#" + port);
|
|
23
|
+
observer.observe(instance, {attributes: true});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
build_ws_url = function (base) {
|
|
27
|
+
return base;
|
|
28
|
+
}
|
|
29
|
+
|
|
4
30
|
build_digital_signature = function (instance) {
|
|
5
31
|
|
|
6
32
|
const widgetId = instance.getAttribute("id");
|
|
7
|
-
const url_ws = instance.getAttribute("data-ws-url");
|
|
33
|
+
const url_ws = build_ws_url(instance.getAttribute("data-ws-url"));
|
|
8
34
|
const container = instance.closest(".widget-digital-signature");
|
|
9
35
|
const container_tag = `container-${widgetId}`;
|
|
10
36
|
const doc_instance = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
37
|
+
"pk": instance.getAttribute("data-pk"),
|
|
38
|
+
"cc": instance.getAttribute("data-cc"),
|
|
39
|
+
"value": instance.getAttribute("data-value")
|
|
40
|
+
}
|
|
15
41
|
const urls = {
|
|
16
42
|
"logo": instance.getAttribute("data-logo"),
|
|
17
43
|
"sign_doc": instance.getAttribute("data-renderurl"),
|
|
@@ -30,8 +56,17 @@ build_digital_signature = function (instance) {
|
|
|
30
56
|
return;
|
|
31
57
|
}
|
|
32
58
|
|
|
59
|
+
//Custom Event
|
|
60
|
+
const event = new CustomEvent("document:signed", {
|
|
61
|
+
bubbles: true, // Important for global handlers
|
|
62
|
+
detail: {
|
|
63
|
+
message: "Signed document",
|
|
64
|
+
instance: doc_instance,
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
33
68
|
// Signature
|
|
34
|
-
let signatureManager = new SignatureManager(widgetId, container, url_ws, pdfInstance);
|
|
69
|
+
let signatureManager = new SignatureManager(widgetId, container, url_ws, pdfInstance, event);
|
|
35
70
|
signatureManager.startSign(doc_instance, urls['logo']);
|
|
36
71
|
|
|
37
72
|
// Store the instance in a global object with key per widget ID
|
|
@@ -44,6 +79,7 @@ build_digital_signature = function (instance) {
|
|
|
44
79
|
window.pdfSignatureComponents[container_tag] = pdfInstance;
|
|
45
80
|
}
|
|
46
81
|
|
|
82
|
+
|
|
47
83
|
}
|
|
48
84
|
|
|
49
85
|
///////////////////////////////////////////////
|
|
@@ -54,8 +90,8 @@ class PdfSignatureComponent {
|
|
|
54
90
|
this.container = container;
|
|
55
91
|
this.defaultPage = defaultPage;
|
|
56
92
|
this.widgetId = container.getAttribute("data-widget-id");
|
|
57
|
-
this.urls=urls;
|
|
58
|
-
this.doc_instance=doc_instance;
|
|
93
|
+
this.urls = urls;
|
|
94
|
+
this.doc_instance = doc_instance;
|
|
59
95
|
|
|
60
96
|
// Internal elements
|
|
61
97
|
this.signature = container.querySelector('.signature');
|
|
@@ -64,8 +100,13 @@ class PdfSignatureComponent {
|
|
|
64
100
|
this.btn_next = container.querySelector('.next');
|
|
65
101
|
this.page_num = container.querySelector('.page_num');
|
|
66
102
|
this.page_number = container.querySelector('.page_number');
|
|
103
|
+
this.btn_expand = container.querySelector('.btn_expand');
|
|
67
104
|
this.page_count = container.querySelector('.page_count');
|
|
68
105
|
this.sub_canvas_container = container.querySelector('.sub_canvas_container');
|
|
106
|
+
this.pdfSignatureContainer = container.querySelector('.pdf-signature-container');
|
|
107
|
+
this.digitalSignatureCard = container.querySelector('.digital-signature-card');
|
|
108
|
+
this.btns_expand = container.querySelector('.container_select_card_expanded');
|
|
109
|
+
this.expandHelpMessage = container.querySelector('.expand-help-message');
|
|
69
110
|
|
|
70
111
|
// Verify that all required elements are present
|
|
71
112
|
if (!this.signature || !this.canvas || !this.btn_prev || !this.btn_next || !this.page_num || !this.page_number || !this.page_count || !this.sub_canvas_container) {
|
|
@@ -83,6 +124,7 @@ class PdfSignatureComponent {
|
|
|
83
124
|
this.signY = 198;
|
|
84
125
|
this.signWidth = 133;
|
|
85
126
|
this.signHeight = 133;
|
|
127
|
+
this.expanded = false;
|
|
86
128
|
|
|
87
129
|
// Initializes the processes
|
|
88
130
|
this.initEvents();
|
|
@@ -97,6 +139,7 @@ class PdfSignatureComponent {
|
|
|
97
139
|
this.btn_next.addEventListener('click', () => this.onNextPage());
|
|
98
140
|
this.page_number.addEventListener('change', (e) => this.renderPage(e.target.value));
|
|
99
141
|
this.page_number.addEventListener('keyup', (e) => this.renderPage(e.target.value));
|
|
142
|
+
this.btn_expand.addEventListener('click', () => this.expand());
|
|
100
143
|
}
|
|
101
144
|
|
|
102
145
|
initPDFViewer() {
|
|
@@ -105,7 +148,7 @@ class PdfSignatureComponent {
|
|
|
105
148
|
console.warn("The variable 'sign_doc' is not defined.");
|
|
106
149
|
return;
|
|
107
150
|
}
|
|
108
|
-
pdfjsLib.getDocument(this.urls['sign_doc']+"?"+this.urls['renderattr']).promise.then((pdfDoc_) => {
|
|
151
|
+
pdfjsLib.getDocument(this.urls['sign_doc'] + "?" + this.urls['renderattr']).promise.then((pdfDoc_) => {
|
|
109
152
|
this.pdfDoc = pdfDoc_;
|
|
110
153
|
this.page_count.textContent = pdfDoc_.numPages;
|
|
111
154
|
|
|
@@ -149,6 +192,44 @@ class PdfSignatureComponent {
|
|
|
149
192
|
}
|
|
150
193
|
}
|
|
151
194
|
|
|
195
|
+
expand() {
|
|
196
|
+
this.expanded = !this.expanded;
|
|
197
|
+
if (this.expanded) {
|
|
198
|
+
this.pdfSignatureContainer.classList.add('expanded-viewer');
|
|
199
|
+
this.sub_canvas_container.classList.add('expanded-canvas-container');
|
|
200
|
+
this.digitalSignatureCard.classList.add('hide');
|
|
201
|
+
this.expandHelpMessage.classList.add('hide');
|
|
202
|
+
this.btns_expand.classList.remove('hide');
|
|
203
|
+
|
|
204
|
+
requestAnimationFrame(() => {
|
|
205
|
+
this.adjustScaleToContainer().then(() => {
|
|
206
|
+
this.renderPage(this.pageNum);
|
|
207
|
+
this.sub_canvas_container.scrollTop = (this.canvas.height / 2) - (this.sub_canvas_container.clientHeight / 2);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
this.pdfSignatureContainer.classList.remove('expanded-viewer');
|
|
212
|
+
this.sub_canvas_container.classList.remove('expanded-canvas-container');
|
|
213
|
+
this.digitalSignatureCard.classList.remove('hide');
|
|
214
|
+
this.expandHelpMessage.classList.remove('hide');
|
|
215
|
+
this.btns_expand.classList.add('hide');
|
|
216
|
+
this.scale = 1.2;
|
|
217
|
+
this.renderPage(this.pageNum);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
adjustScaleToContainer() {
|
|
224
|
+
return this.pdfDoc.getPage(this.pageNum).then((page) => {
|
|
225
|
+
const containerWidth = Math.min(this.sub_canvas_container.offsetWidth, 1200);
|
|
226
|
+
const viewport = page.getViewport({scale: 1});
|
|
227
|
+
let nextScale = (containerWidth * 0.95) / viewport.width;
|
|
228
|
+
this.scale = Math.min(nextScale, 2.0);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
|
|
152
233
|
renderPage(num) {
|
|
153
234
|
this.pageRendering = true;
|
|
154
235
|
this.pdfDoc.getPage(num).then((page) => {
|
|
@@ -321,7 +402,7 @@ class PdfSignatureComponent {
|
|
|
321
402
|
return tempSignature;
|
|
322
403
|
}
|
|
323
404
|
|
|
324
|
-
|
|
405
|
+
// If required, you can define a method for loading an image
|
|
325
406
|
loadSignatureImage(signatureImage, imageContainer) {
|
|
326
407
|
return new Promise((resolve, reject) => {
|
|
327
408
|
if (!signatureImage) {
|
|
@@ -367,14 +448,14 @@ class PdfSignatureComponent {
|
|
|
367
448
|
// Signature manager Digital Signature
|
|
368
449
|
///////////////////////////////////////////////
|
|
369
450
|
class SignatureManager {
|
|
370
|
-
constructor(input_id, container, url_ws, pdfvisor) {
|
|
371
|
-
this.input_id=input_id;
|
|
451
|
+
constructor(input_id, container, url_ws, pdfvisor, custom_event) {
|
|
452
|
+
this.input_id = input_id;
|
|
372
453
|
this.container = container;
|
|
373
454
|
this.modal = new bootstrap.Modal(container.querySelector("#loading_sign"));
|
|
374
|
-
this.firmador = new DocumentClient(container, container.getAttribute("data-widget-id"), this, url_ws, this.doc_instance);
|
|
375
|
-
this.signerBtn = container.
|
|
455
|
+
this.firmador = new DocumentClient(container, container.getAttribute("data-widget-id"), this, url_ws, custom_event, this.doc_instance);
|
|
456
|
+
this.signerBtn = container.querySelectorAll(".btn_signer");
|
|
376
457
|
this.errorsContainer = container.querySelector(".errors_signer");
|
|
377
|
-
this.refreshBtn = container.
|
|
458
|
+
this.refreshBtn = container.querySelectorAll(".btn_signer_refresh");
|
|
378
459
|
this.socketError = false;
|
|
379
460
|
this.pdfvisor = pdfvisor;
|
|
380
461
|
|
|
@@ -382,11 +463,15 @@ class SignatureManager {
|
|
|
382
463
|
}
|
|
383
464
|
|
|
384
465
|
initEvents() {
|
|
385
|
-
if (this.signerBtn) {
|
|
386
|
-
this.signerBtn.
|
|
466
|
+
if (this.signerBtn && this.signerBtn.length) {
|
|
467
|
+
this.signerBtn.forEach(btn => {
|
|
468
|
+
btn.addEventListener('click', () => this.sign());
|
|
469
|
+
});
|
|
387
470
|
}
|
|
388
|
-
if (this.refreshBtn) {
|
|
389
|
-
this.refreshBtn.
|
|
471
|
+
if (this.refreshBtn && this.refreshBtn.length) {
|
|
472
|
+
this.refreshBtn.forEach(btn => {
|
|
473
|
+
btn.addEventListener('click', () => this.refresh());
|
|
474
|
+
});
|
|
390
475
|
}
|
|
391
476
|
}
|
|
392
477
|
|
|
@@ -475,25 +560,83 @@ function responseManageTypeData(instance, err_json_fn, error_text_fn) {
|
|
|
475
560
|
}
|
|
476
561
|
}
|
|
477
562
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
alertSimple(errorInterpreter(3), gettext("Error"), "error");
|
|
484
|
-
signatureManager.socketError = true;
|
|
485
|
-
};
|
|
563
|
+
class SocketManager {
|
|
564
|
+
constructor(url, signatureManager, instance) {
|
|
565
|
+
this.url = url;
|
|
566
|
+
this.signatureManager = signatureManager;
|
|
567
|
+
this.instance = instance;
|
|
486
568
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
// console.warn("WebSocket cerrado");
|
|
490
|
-
};
|
|
569
|
+
this.connect();
|
|
570
|
+
}
|
|
491
571
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
572
|
+
connect() {
|
|
573
|
+
socket_manager_instances[this.instance.socket_id] = this.instance;
|
|
574
|
+
if (!socket_connections.hasOwnProperty(this.url)) {
|
|
575
|
+
let ws = new WebSocket(this.url);
|
|
576
|
+
ws.onerror = this.fn_error(this);
|
|
577
|
+
ws.onclose = this.fn_close(this);
|
|
578
|
+
ws.onopen = this.fn_open(this);
|
|
579
|
+
ws.onmessage = this.fn_messages(this);
|
|
580
|
+
socket_connections[this.url] = ws;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
fn_error(element) {
|
|
585
|
+
return (event) => {
|
|
586
|
+
// console.error("WebSocket error");
|
|
587
|
+
element.signatureManager.hideLoading();
|
|
588
|
+
alertSimple(errorInterpreter(3), gettext("Error"), "error");
|
|
589
|
+
element.signatureManager.socketError = true;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
fn_close(element) {
|
|
594
|
+
return (event) => {
|
|
595
|
+
console.warn("WebSocket cerrado " + event.type);
|
|
596
|
+
Reflect.deleteProperty(socket_connections, event.currentTarget.url);
|
|
597
|
+
if (count_close_inicialice < max_close_inicialice) {
|
|
598
|
+
count_close_inicialice += 1;
|
|
599
|
+
element.instance.inicialize();
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
fn_open(element) {
|
|
605
|
+
return (event) => {
|
|
606
|
+
// console.log("WebSocket conectado");
|
|
607
|
+
element.signatureManager.socket_error = false;
|
|
608
|
+
count_close_inicialice = 0;
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
fn_messages(element) {
|
|
613
|
+
return (event) => {
|
|
614
|
+
try {
|
|
615
|
+
const data = JSON.parse(event.data);
|
|
616
|
+
if (data.hasOwnProperty("socket_id") && socket_manager_instances.hasOwnProperty(data["socket_id"])) {
|
|
617
|
+
socket_manager_instances[data["socket_id"]].receive_json(data);
|
|
618
|
+
} else {
|
|
619
|
+
console.error("Socket id not found");
|
|
620
|
+
}
|
|
621
|
+
} catch (err) {
|
|
622
|
+
console.error("Error al parsear mensaje WS:", err);
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
send(str) {
|
|
628
|
+
if (!socket_connections.hasOwnProperty(this.url)) {
|
|
629
|
+
this.connect();
|
|
630
|
+
} else {
|
|
631
|
+
if (socket_connections[this.url].readyState != WebSocket.OPEN) {
|
|
632
|
+
Reflect.deleteProperty(socket_connections, this.url);
|
|
633
|
+
this.connect();
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
if (socket_connections.hasOwnProperty(this.url)) {
|
|
637
|
+
socket_connections[this.url].send(str);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
497
640
|
}
|
|
498
641
|
|
|
499
642
|
function callFetch(instance) {
|
|
@@ -545,6 +688,9 @@ function FirmadorLibreLocal(docmanager, signatureManager) {
|
|
|
545
688
|
callFetch(instance);
|
|
546
689
|
},
|
|
547
690
|
"sign": function (data) {
|
|
691
|
+
if (data.hasOwnProperty("socket_id")) {
|
|
692
|
+
Reflect.deleteProperty(data, "socket_id");
|
|
693
|
+
}
|
|
548
694
|
let json = JSON.stringify(data);
|
|
549
695
|
let manager = docmanager;
|
|
550
696
|
|
|
@@ -585,21 +731,16 @@ function FirmadorLibreLocal(docmanager, signatureManager) {
|
|
|
585
731
|
}
|
|
586
732
|
}
|
|
587
733
|
|
|
734
|
+
const generateRandomString = () => {
|
|
735
|
+
return Math.floor(Math.random() * Date.now()).toString(36);
|
|
736
|
+
};
|
|
737
|
+
|
|
588
738
|
function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
589
739
|
var firmador = {
|
|
590
740
|
"url": url,
|
|
591
741
|
"websocket": null,
|
|
592
742
|
"firmador_url": "http://localhost:3516",
|
|
593
|
-
"
|
|
594
|
-
return function (event) {
|
|
595
|
-
try {
|
|
596
|
-
const data = JSON.parse(event.data);
|
|
597
|
-
instance.receive_json(data);
|
|
598
|
-
} catch (err) {
|
|
599
|
-
console.error("Error al parsear mensaje WS:", err);
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
},
|
|
743
|
+
"socket_id": generateRandomString(),
|
|
603
744
|
"receive_json": function (data) {
|
|
604
745
|
// validate socket errors
|
|
605
746
|
if (data.result === false && data.error) {
|
|
@@ -651,11 +792,13 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
|
651
792
|
break;
|
|
652
793
|
}
|
|
653
794
|
}
|
|
654
|
-
}else{
|
|
795
|
+
} else {
|
|
655
796
|
|
|
656
|
-
if(data.hasOwnProperty('
|
|
797
|
+
if (data.hasOwnProperty('report')) {
|
|
798
|
+
docmanager.validate_document_remote_done(data['report']);
|
|
799
|
+
} else if (data.hasOwnProperty('tobesigned')) {
|
|
657
800
|
docmanager.do_sign_local(data);
|
|
658
|
-
}else{
|
|
801
|
+
} else {
|
|
659
802
|
docmanager.remote_done(data)
|
|
660
803
|
}
|
|
661
804
|
|
|
@@ -663,15 +806,15 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
|
663
806
|
},
|
|
664
807
|
|
|
665
808
|
"inicialize": function () {
|
|
666
|
-
this.websocket = new
|
|
667
|
-
|
|
668
|
-
this.websocket.onmessage = this.trans_received(this);
|
|
809
|
+
this.websocket = new SocketManager(url, signatureManager, this);
|
|
810
|
+
|
|
669
811
|
},
|
|
670
812
|
"local_done": function (data) {
|
|
671
813
|
// console.log("local_done", data);
|
|
672
814
|
},
|
|
673
815
|
"sign": function (data) {
|
|
674
816
|
data["action"] = "initial_signature";
|
|
817
|
+
data["socket_id"] = this.socket_id;
|
|
675
818
|
if (data.card !== undefined) {
|
|
676
819
|
this.websocket.send(JSON.stringify(data));
|
|
677
820
|
signatureManager.showLoading();
|
|
@@ -682,7 +825,7 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
|
682
825
|
},
|
|
683
826
|
"complete_sign": function (data) {
|
|
684
827
|
data["action"] = "complete_signature";
|
|
685
|
-
|
|
828
|
+
data["socket_id"] = this.socket_id;
|
|
686
829
|
try {
|
|
687
830
|
this.websocket.send(JSON.stringify(data));
|
|
688
831
|
} catch (e) {
|
|
@@ -691,12 +834,24 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
|
691
834
|
alertFunction(errorInterpreter(3), gettext("Error"), "error", false, closeModalSignature);
|
|
692
835
|
}
|
|
693
836
|
},
|
|
837
|
+
|
|
838
|
+
"validate_document": function (data) {
|
|
839
|
+
data["action"] = "validate_document";
|
|
840
|
+
data["socket_id"] = this.socket_id;
|
|
841
|
+
signatureManager.showLoading();
|
|
842
|
+
try {
|
|
843
|
+
this.websocket.send(JSON.stringify(data));
|
|
844
|
+
} catch (e) {
|
|
845
|
+
signatureManager.hideLoading();
|
|
846
|
+
alertFunction(errorInterpreter(3), gettext("Error"), "error", false, closeModalSignature);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
694
849
|
};
|
|
695
850
|
firmador.inicialize();
|
|
696
851
|
return firmador;
|
|
697
852
|
}
|
|
698
853
|
|
|
699
|
-
function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
854
|
+
function DocumentClient(container, widgetId, signatureManager, url_ws, custom_event) {
|
|
700
855
|
const docmanager = {
|
|
701
856
|
"widgetId": widgetId,
|
|
702
857
|
"container": container,
|
|
@@ -706,6 +861,7 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
|
706
861
|
"certificates": null,
|
|
707
862
|
"doc_instance": null,
|
|
708
863
|
"logo_url": null,
|
|
864
|
+
"custom_event": custom_event,
|
|
709
865
|
|
|
710
866
|
"start_sign": function (doc_instance, logo_url = null) {
|
|
711
867
|
this.doc_instance = doc_instance;
|
|
@@ -714,37 +870,49 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
|
714
870
|
this.signatureManager.clearErrors();
|
|
715
871
|
},
|
|
716
872
|
"success_certificates": function (data) {
|
|
717
|
-
|
|
718
873
|
if (data.length > 0) {
|
|
719
|
-
container.
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
874
|
+
container.querySelectorAll("#container_select_card, #container_select_card_expanded_hide").forEach(el => {
|
|
875
|
+
el.classList.remove("d-none");
|
|
876
|
+
el.classList.remove("hide");
|
|
877
|
+
});
|
|
878
|
+
container.querySelectorAll("#container_select_card_tem").forEach(el => {
|
|
879
|
+
el.classList.add("d-none");
|
|
880
|
+
el.classList.add("hide");
|
|
881
|
+
});
|
|
723
882
|
|
|
724
|
-
|
|
883
|
+
let select_cards = container.querySelectorAll(".select_card");
|
|
884
|
+
if (!select_cards.length) {
|
|
725
885
|
console.error(`Select not found for widget ${widgetId}`);
|
|
726
886
|
return;
|
|
727
887
|
}
|
|
728
|
-
select_card.innerHTML = "";
|
|
729
888
|
this.certificates = {};
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
889
|
+
select_cards.forEach(select_card => {
|
|
890
|
+
select_card.innerHTML = "";
|
|
891
|
+
data.forEach((element) => {
|
|
892
|
+
this.certificates[element.tokenSerialNumber] = element;
|
|
893
|
+
let start_token = element.tokenSerialNumber.substring(0, 4);
|
|
894
|
+
let newOption = new Option(
|
|
895
|
+
`${start_token} ${element.commonName}`,
|
|
896
|
+
element.tokenSerialNumber,
|
|
897
|
+
false, false
|
|
898
|
+
);
|
|
899
|
+
select_card.appendChild(newOption);
|
|
900
|
+
});
|
|
740
901
|
});
|
|
741
902
|
} else {
|
|
742
|
-
container.
|
|
743
|
-
|
|
903
|
+
container.querySelectorAll("#container_select_card, #container_select_card_expanded_hide").forEach(el => {
|
|
904
|
+
el.classList.add("d-none");
|
|
905
|
+
el.classList.add("hide");
|
|
906
|
+
});
|
|
907
|
+
container.querySelectorAll("#container_select_card_tem").forEach(el => {
|
|
908
|
+
el.classList.remove("d-none");
|
|
909
|
+
el.classList.remove("hide");
|
|
910
|
+
});
|
|
744
911
|
this.signatureManager.addError(2);
|
|
745
912
|
}
|
|
746
913
|
},
|
|
747
914
|
|
|
915
|
+
|
|
748
916
|
"do_sign_remote": function () {
|
|
749
917
|
let select = container.querySelector(".select_card");
|
|
750
918
|
let selected_card = select ? select.value : null;
|
|
@@ -768,6 +936,7 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
|
768
936
|
}
|
|
769
937
|
|
|
770
938
|
},
|
|
939
|
+
|
|
771
940
|
"do_sign_local": function (data) {
|
|
772
941
|
this.localsigner.sign(data);
|
|
773
942
|
},
|
|
@@ -777,21 +946,91 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
|
777
946
|
this.remotesigner.complete_sign(data);
|
|
778
947
|
},
|
|
779
948
|
"remote_done": function (data) {
|
|
780
|
-
|
|
949
|
+
if (data.result !== null) {
|
|
781
950
|
const l = btoa(JSON.stringify({'token': data.result}));
|
|
782
|
-
this.signatureManager.doc_instance['value'] =l;
|
|
783
|
-
this.signatureManager.pdfvisor.urls['renderattr']="value="+l;
|
|
784
|
-
document.getElementById(this.signatureManager.input_id).value=l;
|
|
951
|
+
this.signatureManager.doc_instance['value'] = l;
|
|
952
|
+
this.signatureManager.pdfvisor.urls['renderattr'] = "value=" + l;
|
|
953
|
+
document.getElementById(this.signatureManager.input_id).value = l;
|
|
785
954
|
this.signatureManager.pdfvisor.initPDFViewer();
|
|
786
955
|
signatureManager.hideLoading();
|
|
956
|
+
document.dispatchEvent(this.custom_event);
|
|
787
957
|
alertFunction(
|
|
788
958
|
gettext("The signing was successfully completed."),
|
|
789
959
|
gettext("Success"),
|
|
790
|
-
"success", false, function(){
|
|
960
|
+
"success", false, function () {
|
|
961
|
+
}
|
|
791
962
|
);
|
|
792
|
-
|
|
963
|
+
}
|
|
793
964
|
},
|
|
794
965
|
|
|
966
|
+
"validate_document_remote": function () {
|
|
967
|
+
data = {
|
|
968
|
+
"instance": this.doc_instance,
|
|
969
|
+
}
|
|
970
|
+
document.dispatchEvent(this.custom_event);
|
|
971
|
+
//this.remotesigner.validate_document(data);
|
|
972
|
+
},
|
|
973
|
+
|
|
974
|
+
"validate_document_remote_done": function (reportData) {
|
|
975
|
+
signatureManager.hideLoading();
|
|
976
|
+
if (!reportData || typeof reportData !== 'string') {
|
|
977
|
+
alertFunction(
|
|
978
|
+
gettext("Please, sign the document before saving"),
|
|
979
|
+
gettext("Warning"),
|
|
980
|
+
"warning", false, function () {
|
|
981
|
+
}
|
|
982
|
+
);
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
if (reportData.includes("no está firmado digitalmente")) {
|
|
987
|
+
alertFunction(
|
|
988
|
+
gettext("The document is not digitally signed. Please sign the document before saving."),
|
|
989
|
+
gettext("Warning"),
|
|
990
|
+
"warning", false,
|
|
991
|
+
function () {
|
|
992
|
+
}
|
|
993
|
+
);
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
const firmasMatch = reportData.match(/Contiene\s*([\d]+)\s*firma/);
|
|
998
|
+
let numFirmas = 0;
|
|
999
|
+
if (firmasMatch && firmasMatch[1]) {
|
|
1000
|
+
numFirmas = parseInt(firmasMatch[1], 10);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
if (numFirmas > 0) {
|
|
1004
|
+
if (typeof update_signed_document === "function") {
|
|
1005
|
+
update_signed_document(this.doc_instance);
|
|
1006
|
+
} else {
|
|
1007
|
+
console.log("warning: update_signed_document function not defined, using default action");
|
|
1008
|
+
alertFunction(
|
|
1009
|
+
gettext(`The document was saved`),
|
|
1010
|
+
gettext("Success"),
|
|
1011
|
+
"success", false,
|
|
1012
|
+
function () {
|
|
1013
|
+
const container = this.signatureManager.container;
|
|
1014
|
+
const form = container.closest('form');
|
|
1015
|
+
if (form) {
|
|
1016
|
+
form.submit();
|
|
1017
|
+
}
|
|
1018
|
+
}.bind(this)
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
} else {
|
|
1023
|
+
alertFunction(
|
|
1024
|
+
gettext("The document is not digitally signed. Please sign the document before saving."),
|
|
1025
|
+
gettext("Warning"),
|
|
1026
|
+
"warning", false,
|
|
1027
|
+
function () {
|
|
1028
|
+
}
|
|
1029
|
+
);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
|
|
795
1034
|
};
|
|
796
1035
|
|
|
797
1036
|
docmanager["remotesigner"] = new FirmadorLibreWS(docmanager, url_ws, signatureManager);
|
|
@@ -127,7 +127,10 @@ function clear_action_form(form) {
|
|
|
127
127
|
});
|
|
128
128
|
$(form).find('[data-widget="TaggingInput"],[data-widget="EmailTaggingInput"]').each(function (i, e) {
|
|
129
129
|
var tg = $(e).data().tagify;
|
|
130
|
-
tg
|
|
130
|
+
if(tg != undefined){
|
|
131
|
+
tg.removeAllTags();
|
|
132
|
+
}
|
|
133
|
+
|
|
131
134
|
});
|
|
132
135
|
$(form).find('[data-widget="FileChunkedUpload"],[data-widget="FileInput"]').each(function (i, e) {
|
|
133
136
|
var tg = $(e).data().fileUploadWidget;
|
|
@@ -208,9 +211,11 @@ function updateInstanceValuesForm(form, name, value) {
|
|
|
208
211
|
}
|
|
209
212
|
if (inputfield.data().widget === "TaggingInput" || inputfield.data().widget === "EmailTaggingInput") {
|
|
210
213
|
var tagifyelement = inputfield.data().tagify;
|
|
211
|
-
tagifyelement
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
if(tagifyelement!=undefined){
|
|
215
|
+
tagifyelement.removeAllTags();
|
|
216
|
+
tagifyelement.loadOriginalValues(value);
|
|
217
|
+
}
|
|
218
|
+
done = false;
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
|
|
@@ -8,4 +8,18 @@ function decore_select2 (data) {
|
|
|
8
8
|
$wrapper.addClass($element[0].className);
|
|
9
9
|
$wrapper.text(data.text);
|
|
10
10
|
return $wrapper;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function decore_img_select2 (data) {
|
|
14
|
+
if(!data.url && data.text){
|
|
15
|
+
return $('<span>'+data.text+'</span>');
|
|
16
|
+
}
|
|
17
|
+
if (!data.url) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
let img_width = "2em"; let img_height="2em;";
|
|
21
|
+
if(data.img_width != undefined){img_width=data.img_width;}
|
|
22
|
+
if(data.img_height != undefined){ img_height=data.img_height; }
|
|
23
|
+
var $state = $('<span><img style="width: '+img_width+'; height: '+img_height+';" src="' + data.url+ '" class="img-flag" /> ' + data.text + '</span>');
|
|
24
|
+
return $state;
|
|
25
|
+
};
|
|
@@ -14,6 +14,11 @@ function extract_select2_context(context, instance){
|
|
|
14
14
|
}else{
|
|
15
15
|
context.theme='bootstrap-5'
|
|
16
16
|
}
|
|
17
|
+
let template = data.templateresult;
|
|
18
|
+
if(template != undefined){
|
|
19
|
+
context.templateResult=window[template];
|
|
20
|
+
context.templateSelection=window[template];
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
function add_selected_option(item, data){
|