djgentelella 0.4.9__py3-none-any.whl → 0.4.10__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 +1 -1
- djgentelella/firmador_digital/consumers/sign.py +15 -1
- djgentelella/firmador_digital/utils.py +11 -0
- djgentelella/locale/es/LC_MESSAGES/django.po +1 -0
- djgentelella/locale/es/LC_MESSAGES/djangojs.mo +0 -0
- djgentelella/locale/es/LC_MESSAGES/djangojs.po +9 -0
- djgentelella/serializers/firmador_digital.py +5 -0
- djgentelella/static/djgentelella.readonly.vendors.min.css +9 -5
- djgentelella/static/djgentelella.readonly.vendors.min.js +1 -1
- djgentelella/static/gentelella/js/base/digital_signature.js +164 -62
- djgentelella/static/gentelella/js/base/form.common.js +9 -4
- djgentelella/static/gentelella/js/base.js +172 -65
- djgentelella/static/gentelella/js/obj_api_management.js +5 -3
- djgentelella/static/vendors/timeline/css/timeline.css +9 -5
- djgentelella/static/vendors/timeline/js/timeline.js +1 -1
- djgentelella/templates/gentelella/widgets/digital_signature.html +5 -3
- {djgentelella-0.4.9.dist-info → djgentelella-0.4.10.dist-info}/METADATA +1 -1
- {djgentelella-0.4.9.dist-info → djgentelella-0.4.10.dist-info}/RECORD +22 -22
- {djgentelella-0.4.9.dist-info → djgentelella-0.4.10.dist-info}/AUTHORS +0 -0
- {djgentelella-0.4.9.dist-info → djgentelella-0.4.10.dist-info}/LICENSE.txt +0 -0
- {djgentelella-0.4.9.dist-info → djgentelella-0.4.10.dist-info}/WHEEL +0 -0
- {djgentelella-0.4.9.dist-info → djgentelella-0.4.10.dist-info}/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var socket_connections = {};
|
|
5
5
|
var socket_manager_instances = {};
|
|
6
6
|
const max_close_inicialice = 5;
|
|
7
|
-
var count_close_inicialice=0;
|
|
7
|
+
var count_close_inicialice = 0;
|
|
8
8
|
|
|
9
9
|
// Configuración del MutationObserver
|
|
10
10
|
const observer = new MutationObserver((mutations) => {
|
|
@@ -12,18 +12,18 @@ const observer = new MutationObserver((mutations) => {
|
|
|
12
12
|
if (mutation.type === 'attributes' && mutation.attributeName === 'data-port') {
|
|
13
13
|
let port = mutation.target.getAttribute('data-port');
|
|
14
14
|
mutation.target.setAttribute("href",
|
|
15
|
-
|
|
15
|
+
"firmador:" + window.location.protocol + "//" + window.location.host + "#" + port);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
build_cors_headers = function(instance){
|
|
20
|
+
build_cors_headers = function (instance) {
|
|
21
21
|
let port = instance.getAttribute('data-port');
|
|
22
22
|
instance.setAttribute("href", "firmador:" + window.location.protocol + "//" + window.location.host + "#" + port);
|
|
23
|
-
observer.observe(instance, {
|
|
23
|
+
observer.observe(instance, {attributes: true});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
build_ws_url = function(base){
|
|
26
|
+
build_ws_url = function (base) {
|
|
27
27
|
return base;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -34,10 +34,10 @@ build_digital_signature = function (instance) {
|
|
|
34
34
|
const container = instance.closest(".widget-digital-signature");
|
|
35
35
|
const container_tag = `container-${widgetId}`;
|
|
36
36
|
const doc_instance = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
"pk": instance.getAttribute("data-pk"),
|
|
38
|
+
"cc": instance.getAttribute("data-cc"),
|
|
39
|
+
"value": instance.getAttribute("data-value")
|
|
40
|
+
}
|
|
41
41
|
const urls = {
|
|
42
42
|
"logo": instance.getAttribute("data-logo"),
|
|
43
43
|
"sign_doc": instance.getAttribute("data-renderurl"),
|
|
@@ -56,8 +56,17 @@ build_digital_signature = function (instance) {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
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
|
+
|
|
59
68
|
// Signature
|
|
60
|
-
let signatureManager = new SignatureManager(widgetId, container, url_ws, pdfInstance);
|
|
69
|
+
let signatureManager = new SignatureManager(widgetId, container, url_ws, pdfInstance, event);
|
|
61
70
|
signatureManager.startSign(doc_instance, urls['logo']);
|
|
62
71
|
|
|
63
72
|
// Store the instance in a global object with key per widget ID
|
|
@@ -70,6 +79,7 @@ build_digital_signature = function (instance) {
|
|
|
70
79
|
window.pdfSignatureComponents[container_tag] = pdfInstance;
|
|
71
80
|
}
|
|
72
81
|
|
|
82
|
+
|
|
73
83
|
}
|
|
74
84
|
|
|
75
85
|
///////////////////////////////////////////////
|
|
@@ -80,8 +90,8 @@ class PdfSignatureComponent {
|
|
|
80
90
|
this.container = container;
|
|
81
91
|
this.defaultPage = defaultPage;
|
|
82
92
|
this.widgetId = container.getAttribute("data-widget-id");
|
|
83
|
-
this.urls=urls;
|
|
84
|
-
this.doc_instance=doc_instance;
|
|
93
|
+
this.urls = urls;
|
|
94
|
+
this.doc_instance = doc_instance;
|
|
85
95
|
|
|
86
96
|
// Internal elements
|
|
87
97
|
this.signature = container.querySelector('.signature');
|
|
@@ -131,7 +141,7 @@ class PdfSignatureComponent {
|
|
|
131
141
|
console.warn("The variable 'sign_doc' is not defined.");
|
|
132
142
|
return;
|
|
133
143
|
}
|
|
134
|
-
pdfjsLib.getDocument(this.urls['sign_doc']+"?"+this.urls['renderattr']).promise.then((pdfDoc_) => {
|
|
144
|
+
pdfjsLib.getDocument(this.urls['sign_doc'] + "?" + this.urls['renderattr']).promise.then((pdfDoc_) => {
|
|
135
145
|
this.pdfDoc = pdfDoc_;
|
|
136
146
|
this.page_count.textContent = pdfDoc_.numPages;
|
|
137
147
|
|
|
@@ -393,11 +403,11 @@ class PdfSignatureComponent {
|
|
|
393
403
|
// Signature manager Digital Signature
|
|
394
404
|
///////////////////////////////////////////////
|
|
395
405
|
class SignatureManager {
|
|
396
|
-
constructor(input_id, container, url_ws, pdfvisor) {
|
|
397
|
-
this.input_id=input_id;
|
|
406
|
+
constructor(input_id, container, url_ws, pdfvisor, custom_event) {
|
|
407
|
+
this.input_id = input_id;
|
|
398
408
|
this.container = container;
|
|
399
409
|
this.modal = new bootstrap.Modal(container.querySelector("#loading_sign"));
|
|
400
|
-
this.firmador = new DocumentClient(container, container.getAttribute("data-widget-id"), this, url_ws, this.doc_instance);
|
|
410
|
+
this.firmador = new DocumentClient(container, container.getAttribute("data-widget-id"), this, url_ws, custom_event, this.doc_instance);
|
|
401
411
|
this.signerBtn = container.querySelector(".btn_signer");
|
|
402
412
|
this.errorsContainer = container.querySelector(".errors_signer");
|
|
403
413
|
this.refreshBtn = container.querySelector(".btn_signer_refresh");
|
|
@@ -503,24 +513,26 @@ function responseManageTypeData(instance, err_json_fn, error_text_fn) {
|
|
|
503
513
|
|
|
504
514
|
class SocketManager {
|
|
505
515
|
constructor(url, signatureManager, instance) {
|
|
506
|
-
this.url=url;
|
|
507
|
-
this.signatureManager=signatureManager;
|
|
516
|
+
this.url = url;
|
|
517
|
+
this.signatureManager = signatureManager;
|
|
508
518
|
this.instance = instance;
|
|
509
519
|
|
|
510
520
|
this.connect();
|
|
511
521
|
}
|
|
512
|
-
|
|
522
|
+
|
|
523
|
+
connect() {
|
|
513
524
|
socket_manager_instances[this.instance.socket_id] = this.instance;
|
|
514
|
-
|
|
525
|
+
if (!socket_connections.hasOwnProperty(this.url)) {
|
|
515
526
|
let ws = new WebSocket(this.url);
|
|
516
|
-
ws.onerror=this.fn_error(this);
|
|
517
|
-
ws.onclose=this.fn_close(this);
|
|
518
|
-
ws.onopen=this.fn_open(this);
|
|
519
|
-
ws.onmessage=this.fn_messages(this);
|
|
520
|
-
socket_connections[this.url]=ws;
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
|
|
527
|
+
ws.onerror = this.fn_error(this);
|
|
528
|
+
ws.onclose = this.fn_close(this);
|
|
529
|
+
ws.onopen = this.fn_open(this);
|
|
530
|
+
ws.onmessage = this.fn_messages(this);
|
|
531
|
+
socket_connections[this.url] = ws;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
fn_error(element) {
|
|
524
536
|
return (event) => {
|
|
525
537
|
// console.error("WebSocket error");
|
|
526
538
|
element.signatureManager.hideLoading();
|
|
@@ -528,47 +540,51 @@ class SocketManager {
|
|
|
528
540
|
element.signatureManager.socketError = true;
|
|
529
541
|
}
|
|
530
542
|
}
|
|
531
|
-
|
|
543
|
+
|
|
544
|
+
fn_close(element) {
|
|
532
545
|
return (event) => {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
546
|
+
console.warn("WebSocket cerrado " + event.type);
|
|
547
|
+
Reflect.deleteProperty(socket_connections, event.currentTarget.url);
|
|
548
|
+
if (count_close_inicialice < max_close_inicialice) {
|
|
536
549
|
count_close_inicialice += 1;
|
|
537
550
|
element.instance.inicialize();
|
|
538
|
-
|
|
551
|
+
}
|
|
539
552
|
};
|
|
540
553
|
}
|
|
541
|
-
|
|
554
|
+
|
|
555
|
+
fn_open(element) {
|
|
542
556
|
return (event) => {
|
|
543
|
-
|
|
557
|
+
// console.log("WebSocket conectado");
|
|
544
558
|
element.signatureManager.socket_error = false;
|
|
545
|
-
count_close_inicialice=0;
|
|
546
|
-
|
|
559
|
+
count_close_inicialice = 0;
|
|
560
|
+
};
|
|
547
561
|
}
|
|
548
|
-
|
|
549
|
-
|
|
562
|
+
|
|
563
|
+
fn_messages(element) {
|
|
564
|
+
return (event) => {
|
|
550
565
|
try {
|
|
551
566
|
const data = JSON.parse(event.data);
|
|
552
|
-
if (data.hasOwnProperty("socket_id") && socket_manager_instances.hasOwnProperty(data["socket_id"])){
|
|
553
|
-
|
|
554
|
-
}else{
|
|
567
|
+
if (data.hasOwnProperty("socket_id") && socket_manager_instances.hasOwnProperty(data["socket_id"])) {
|
|
568
|
+
socket_manager_instances[data["socket_id"]].receive_json(data);
|
|
569
|
+
} else {
|
|
555
570
|
console.error("Socket id not found");
|
|
556
571
|
}
|
|
557
572
|
} catch (err) {
|
|
558
573
|
console.error("Error al parsear mensaje WS:", err);
|
|
559
574
|
}
|
|
560
|
-
|
|
575
|
+
};
|
|
561
576
|
}
|
|
562
|
-
|
|
563
|
-
|
|
577
|
+
|
|
578
|
+
send(str) {
|
|
579
|
+
if (!socket_connections.hasOwnProperty(this.url)) {
|
|
564
580
|
this.connect();
|
|
565
|
-
|
|
566
|
-
if(socket_connections[this.url].readyState != WebSocket.OPEN){
|
|
581
|
+
} else {
|
|
582
|
+
if (socket_connections[this.url].readyState != WebSocket.OPEN) {
|
|
567
583
|
Reflect.deleteProperty(socket_connections, this.url);
|
|
568
584
|
this.connect();
|
|
569
585
|
}
|
|
570
|
-
|
|
571
|
-
|
|
586
|
+
}
|
|
587
|
+
if (socket_connections.hasOwnProperty(this.url)) {
|
|
572
588
|
socket_connections[this.url].send(str);
|
|
573
589
|
}
|
|
574
590
|
}
|
|
@@ -623,7 +639,7 @@ function FirmadorLibreLocal(docmanager, signatureManager) {
|
|
|
623
639
|
callFetch(instance);
|
|
624
640
|
},
|
|
625
641
|
"sign": function (data) {
|
|
626
|
-
if(data.hasOwnProperty("socket_id")){
|
|
642
|
+
if (data.hasOwnProperty("socket_id")) {
|
|
627
643
|
Reflect.deleteProperty(data, "socket_id");
|
|
628
644
|
}
|
|
629
645
|
let json = JSON.stringify(data);
|
|
@@ -667,7 +683,7 @@ function FirmadorLibreLocal(docmanager, signatureManager) {
|
|
|
667
683
|
}
|
|
668
684
|
|
|
669
685
|
const generateRandomString = () => {
|
|
670
|
-
|
|
686
|
+
return Math.floor(Math.random() * Date.now()).toString(36);
|
|
671
687
|
};
|
|
672
688
|
|
|
673
689
|
function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
@@ -727,11 +743,13 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
|
727
743
|
break;
|
|
728
744
|
}
|
|
729
745
|
}
|
|
730
|
-
}else{
|
|
746
|
+
} else {
|
|
731
747
|
|
|
732
|
-
if(data.hasOwnProperty('
|
|
748
|
+
if (data.hasOwnProperty('report')) {
|
|
749
|
+
docmanager.validate_document_remote_done(data['report']);
|
|
750
|
+
} else if (data.hasOwnProperty('tobesigned')) {
|
|
733
751
|
docmanager.do_sign_local(data);
|
|
734
|
-
}else{
|
|
752
|
+
} else {
|
|
735
753
|
docmanager.remote_done(data)
|
|
736
754
|
}
|
|
737
755
|
|
|
@@ -739,7 +757,7 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
|
739
757
|
},
|
|
740
758
|
|
|
741
759
|
"inicialize": function () {
|
|
742
|
-
|
|
760
|
+
this.websocket = new SocketManager(url, signatureManager, this);
|
|
743
761
|
|
|
744
762
|
},
|
|
745
763
|
"local_done": function (data) {
|
|
@@ -767,12 +785,24 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
|
|
|
767
785
|
alertFunction(errorInterpreter(3), gettext("Error"), "error", false, closeModalSignature);
|
|
768
786
|
}
|
|
769
787
|
},
|
|
788
|
+
|
|
789
|
+
"validate_document": function (data) {
|
|
790
|
+
data["action"] = "validate_document";
|
|
791
|
+
data["socket_id"] = this.socket_id;
|
|
792
|
+
signatureManager.showLoading();
|
|
793
|
+
try {
|
|
794
|
+
this.websocket.send(JSON.stringify(data));
|
|
795
|
+
} catch (e) {
|
|
796
|
+
signatureManager.hideLoading();
|
|
797
|
+
alertFunction(errorInterpreter(3), gettext("Error"), "error", false, closeModalSignature);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
770
800
|
};
|
|
771
801
|
firmador.inicialize();
|
|
772
802
|
return firmador;
|
|
773
803
|
}
|
|
774
804
|
|
|
775
|
-
function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
805
|
+
function DocumentClient(container, widgetId, signatureManager, url_ws, custom_event) {
|
|
776
806
|
const docmanager = {
|
|
777
807
|
"widgetId": widgetId,
|
|
778
808
|
"container": container,
|
|
@@ -782,6 +812,7 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
|
782
812
|
"certificates": null,
|
|
783
813
|
"doc_instance": null,
|
|
784
814
|
"logo_url": null,
|
|
815
|
+
"custom_event": custom_event,
|
|
785
816
|
|
|
786
817
|
"start_sign": function (doc_instance, logo_url = null) {
|
|
787
818
|
this.doc_instance = doc_instance;
|
|
@@ -844,6 +875,7 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
|
844
875
|
}
|
|
845
876
|
|
|
846
877
|
},
|
|
878
|
+
|
|
847
879
|
"do_sign_local": function (data) {
|
|
848
880
|
this.localsigner.sign(data);
|
|
849
881
|
},
|
|
@@ -853,21 +885,91 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
|
|
|
853
885
|
this.remotesigner.complete_sign(data);
|
|
854
886
|
},
|
|
855
887
|
"remote_done": function (data) {
|
|
856
|
-
|
|
888
|
+
if (data.result !== null) {
|
|
857
889
|
const l = btoa(JSON.stringify({'token': data.result}));
|
|
858
|
-
this.signatureManager.doc_instance['value'] =l;
|
|
859
|
-
this.signatureManager.pdfvisor.urls['renderattr']="value="+l;
|
|
860
|
-
document.getElementById(this.signatureManager.input_id).value=l;
|
|
890
|
+
this.signatureManager.doc_instance['value'] = l;
|
|
891
|
+
this.signatureManager.pdfvisor.urls['renderattr'] = "value=" + l;
|
|
892
|
+
document.getElementById(this.signatureManager.input_id).value = l;
|
|
861
893
|
this.signatureManager.pdfvisor.initPDFViewer();
|
|
862
894
|
signatureManager.hideLoading();
|
|
895
|
+
document.dispatchEvent(this.custom_event);
|
|
863
896
|
alertFunction(
|
|
864
897
|
gettext("The signing was successfully completed."),
|
|
865
898
|
gettext("Success"),
|
|
866
|
-
"success", false, function(){
|
|
899
|
+
"success", false, function () {
|
|
900
|
+
}
|
|
867
901
|
);
|
|
868
|
-
|
|
902
|
+
}
|
|
903
|
+
},
|
|
904
|
+
|
|
905
|
+
"validate_document_remote": function () {
|
|
906
|
+
data = {
|
|
907
|
+
"instance": this.doc_instance,
|
|
908
|
+
}
|
|
909
|
+
document.dispatchEvent(this.custom_event);
|
|
910
|
+
//this.remotesigner.validate_document(data);
|
|
869
911
|
},
|
|
870
912
|
|
|
913
|
+
"validate_document_remote_done": function (reportData) {
|
|
914
|
+
signatureManager.hideLoading();
|
|
915
|
+
if (!reportData || typeof reportData !== 'string') {
|
|
916
|
+
alertFunction(
|
|
917
|
+
gettext("Please, sign the document before saving"),
|
|
918
|
+
gettext("Warning"),
|
|
919
|
+
"warning", false, function () {
|
|
920
|
+
}
|
|
921
|
+
);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
if (reportData.includes("no está firmado digitalmente")) {
|
|
926
|
+
alertFunction(
|
|
927
|
+
gettext("The document is not digitally signed. Please sign the document before saving."),
|
|
928
|
+
gettext("Warning"),
|
|
929
|
+
"warning", false,
|
|
930
|
+
function () {
|
|
931
|
+
}
|
|
932
|
+
);
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
const firmasMatch = reportData.match(/Contiene\s*([\d]+)\s*firma/);
|
|
937
|
+
let numFirmas = 0;
|
|
938
|
+
if (firmasMatch && firmasMatch[1]) {
|
|
939
|
+
numFirmas = parseInt(firmasMatch[1], 10);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
if (numFirmas > 0) {
|
|
943
|
+
if (typeof update_signed_document === "function") {
|
|
944
|
+
update_signed_document(this.doc_instance);
|
|
945
|
+
} else {
|
|
946
|
+
console.log("warning: update_signed_document function not defined, using default action");
|
|
947
|
+
alertFunction(
|
|
948
|
+
gettext(`The document was saved`),
|
|
949
|
+
gettext("Success"),
|
|
950
|
+
"success", false,
|
|
951
|
+
function () {
|
|
952
|
+
const container = this.signatureManager.container;
|
|
953
|
+
const form = container.closest('form');
|
|
954
|
+
if (form) {
|
|
955
|
+
form.submit();
|
|
956
|
+
}
|
|
957
|
+
}.bind(this)
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
} else {
|
|
962
|
+
alertFunction(
|
|
963
|
+
gettext("The document is not digitally signed. Please sign the document before saving."),
|
|
964
|
+
gettext("Warning"),
|
|
965
|
+
"warning", false,
|
|
966
|
+
function () {
|
|
967
|
+
}
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
|
|
871
973
|
};
|
|
872
974
|
|
|
873
975
|
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
|
|