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.
@@ -833,7 +833,10 @@ function clear_action_form(form) {
833
833
  });
834
834
  $(form).find('[data-widget="TaggingInput"],[data-widget="EmailTaggingInput"]').each(function (i, e) {
835
835
  var tg = $(e).data().tagify;
836
- tg.removeAllTags();
836
+ if(tg != undefined){
837
+ tg.removeAllTags();
838
+ }
839
+
837
840
  });
838
841
  $(form).find('[data-widget="FileChunkedUpload"],[data-widget="FileInput"]').each(function (i, e) {
839
842
  var tg = $(e).data().fileUploadWidget;
@@ -914,9 +917,11 @@ function updateInstanceValuesForm(form, name, value) {
914
917
  }
915
918
  if (inputfield.data().widget === "TaggingInput" || inputfield.data().widget === "EmailTaggingInput") {
916
919
  var tagifyelement = inputfield.data().tagify;
917
- tagifyelement.removeAllTags();
918
- tagifyelement.loadOriginalValues(value);
919
- done = true;
920
+ if(tagifyelement!=undefined){
921
+ tagifyelement.removeAllTags();
922
+ tagifyelement.loadOriginalValues(value);
923
+ }
924
+ done = false;
920
925
  }
921
926
 
922
927
 
@@ -2274,7 +2279,7 @@ function getMediaRecord(element, mediatype){
2274
2279
  var socket_connections = {};
2275
2280
  var socket_manager_instances = {};
2276
2281
  const max_close_inicialice = 5;
2277
- var count_close_inicialice=0;
2282
+ var count_close_inicialice = 0;
2278
2283
 
2279
2284
  // Configuración del MutationObserver
2280
2285
  const observer = new MutationObserver((mutations) => {
@@ -2282,18 +2287,18 @@ const observer = new MutationObserver((mutations) => {
2282
2287
  if (mutation.type === 'attributes' && mutation.attributeName === 'data-port') {
2283
2288
  let port = mutation.target.getAttribute('data-port');
2284
2289
  mutation.target.setAttribute("href",
2285
- "firmador:" + window.location.protocol + "//" + window.location.host + "#" + port);
2290
+ "firmador:" + window.location.protocol + "//" + window.location.host + "#" + port);
2286
2291
  }
2287
2292
  });
2288
2293
  });
2289
2294
 
2290
- build_cors_headers = function(instance){
2295
+ build_cors_headers = function (instance) {
2291
2296
  let port = instance.getAttribute('data-port');
2292
2297
  instance.setAttribute("href", "firmador:" + window.location.protocol + "//" + window.location.host + "#" + port);
2293
- observer.observe(instance, { attributes: true });
2298
+ observer.observe(instance, {attributes: true});
2294
2299
  }
2295
2300
 
2296
- build_ws_url = function(base){
2301
+ build_ws_url = function (base) {
2297
2302
  return base;
2298
2303
  }
2299
2304
 
@@ -2304,10 +2309,10 @@ build_digital_signature = function (instance) {
2304
2309
  const container = instance.closest(".widget-digital-signature");
2305
2310
  const container_tag = `container-${widgetId}`;
2306
2311
  const doc_instance = {
2307
- "pk": instance.getAttribute("data-pk"),
2308
- "cc": instance.getAttribute("data-cc"),
2309
- "value": instance.getAttribute("data-value")
2310
- }
2312
+ "pk": instance.getAttribute("data-pk"),
2313
+ "cc": instance.getAttribute("data-cc"),
2314
+ "value": instance.getAttribute("data-value")
2315
+ }
2311
2316
  const urls = {
2312
2317
  "logo": instance.getAttribute("data-logo"),
2313
2318
  "sign_doc": instance.getAttribute("data-renderurl"),
@@ -2326,8 +2331,17 @@ build_digital_signature = function (instance) {
2326
2331
  return;
2327
2332
  }
2328
2333
 
2334
+ //Custom Event
2335
+ const event = new CustomEvent("document:signed", {
2336
+ bubbles: true, // Important for global handlers
2337
+ detail: {
2338
+ message: "Signed document",
2339
+ instance: doc_instance,
2340
+ }
2341
+ });
2342
+
2329
2343
  // Signature
2330
- let signatureManager = new SignatureManager(widgetId, container, url_ws, pdfInstance);
2344
+ let signatureManager = new SignatureManager(widgetId, container, url_ws, pdfInstance, event);
2331
2345
  signatureManager.startSign(doc_instance, urls['logo']);
2332
2346
 
2333
2347
  // Store the instance in a global object with key per widget ID
@@ -2340,6 +2354,7 @@ build_digital_signature = function (instance) {
2340
2354
  window.pdfSignatureComponents[container_tag] = pdfInstance;
2341
2355
  }
2342
2356
 
2357
+
2343
2358
  }
2344
2359
 
2345
2360
  ///////////////////////////////////////////////
@@ -2350,8 +2365,8 @@ class PdfSignatureComponent {
2350
2365
  this.container = container;
2351
2366
  this.defaultPage = defaultPage;
2352
2367
  this.widgetId = container.getAttribute("data-widget-id");
2353
- this.urls=urls;
2354
- this.doc_instance=doc_instance;
2368
+ this.urls = urls;
2369
+ this.doc_instance = doc_instance;
2355
2370
 
2356
2371
  // Internal elements
2357
2372
  this.signature = container.querySelector('.signature');
@@ -2401,7 +2416,7 @@ class PdfSignatureComponent {
2401
2416
  console.warn("The variable 'sign_doc' is not defined.");
2402
2417
  return;
2403
2418
  }
2404
- pdfjsLib.getDocument(this.urls['sign_doc']+"?"+this.urls['renderattr']).promise.then((pdfDoc_) => {
2419
+ pdfjsLib.getDocument(this.urls['sign_doc'] + "?" + this.urls['renderattr']).promise.then((pdfDoc_) => {
2405
2420
  this.pdfDoc = pdfDoc_;
2406
2421
  this.page_count.textContent = pdfDoc_.numPages;
2407
2422
 
@@ -2663,11 +2678,11 @@ class PdfSignatureComponent {
2663
2678
  // Signature manager Digital Signature
2664
2679
  ///////////////////////////////////////////////
2665
2680
  class SignatureManager {
2666
- constructor(input_id, container, url_ws, pdfvisor) {
2667
- this.input_id=input_id;
2681
+ constructor(input_id, container, url_ws, pdfvisor, custom_event) {
2682
+ this.input_id = input_id;
2668
2683
  this.container = container;
2669
2684
  this.modal = new bootstrap.Modal(container.querySelector("#loading_sign"));
2670
- this.firmador = new DocumentClient(container, container.getAttribute("data-widget-id"), this, url_ws, this.doc_instance);
2685
+ this.firmador = new DocumentClient(container, container.getAttribute("data-widget-id"), this, url_ws, custom_event, this.doc_instance);
2671
2686
  this.signerBtn = container.querySelector(".btn_signer");
2672
2687
  this.errorsContainer = container.querySelector(".errors_signer");
2673
2688
  this.refreshBtn = container.querySelector(".btn_signer_refresh");
@@ -2773,24 +2788,26 @@ function responseManageTypeData(instance, err_json_fn, error_text_fn) {
2773
2788
 
2774
2789
  class SocketManager {
2775
2790
  constructor(url, signatureManager, instance) {
2776
- this.url=url;
2777
- this.signatureManager=signatureManager;
2791
+ this.url = url;
2792
+ this.signatureManager = signatureManager;
2778
2793
  this.instance = instance;
2779
2794
 
2780
2795
  this.connect();
2781
2796
  }
2782
- connect(){
2797
+
2798
+ connect() {
2783
2799
  socket_manager_instances[this.instance.socket_id] = this.instance;
2784
- if(!socket_connections.hasOwnProperty(this.url)){
2800
+ if (!socket_connections.hasOwnProperty(this.url)) {
2785
2801
  let ws = new WebSocket(this.url);
2786
- ws.onerror=this.fn_error(this);
2787
- ws.onclose=this.fn_close(this);
2788
- ws.onopen=this.fn_open(this);
2789
- ws.onmessage=this.fn_messages(this);
2790
- socket_connections[this.url]=ws;
2791
- }
2802
+ ws.onerror = this.fn_error(this);
2803
+ ws.onclose = this.fn_close(this);
2804
+ ws.onopen = this.fn_open(this);
2805
+ ws.onmessage = this.fn_messages(this);
2806
+ socket_connections[this.url] = ws;
2807
+ }
2792
2808
  }
2793
- fn_error(element){
2809
+
2810
+ fn_error(element) {
2794
2811
  return (event) => {
2795
2812
  // console.error("WebSocket error");
2796
2813
  element.signatureManager.hideLoading();
@@ -2798,47 +2815,51 @@ class SocketManager {
2798
2815
  element.signatureManager.socketError = true;
2799
2816
  }
2800
2817
  }
2801
- fn_close(element){
2818
+
2819
+ fn_close(element) {
2802
2820
  return (event) => {
2803
- console.warn("WebSocket cerrado "+event.type);
2804
- Reflect.deleteProperty(socket_connections, event.currentTarget.url);
2805
- if(count_close_inicialice < max_close_inicialice){
2821
+ console.warn("WebSocket cerrado " + event.type);
2822
+ Reflect.deleteProperty(socket_connections, event.currentTarget.url);
2823
+ if (count_close_inicialice < max_close_inicialice) {
2806
2824
  count_close_inicialice += 1;
2807
2825
  element.instance.inicialize();
2808
- }
2826
+ }
2809
2827
  };
2810
2828
  }
2811
- fn_open(element){
2829
+
2830
+ fn_open(element) {
2812
2831
  return (event) => {
2813
- // console.log("WebSocket conectado");
2832
+ // console.log("WebSocket conectado");
2814
2833
  element.signatureManager.socket_error = false;
2815
- count_close_inicialice=0;
2816
- };
2834
+ count_close_inicialice = 0;
2835
+ };
2817
2836
  }
2818
- fn_messages(element){
2819
- return (event)=>{
2837
+
2838
+ fn_messages(element) {
2839
+ return (event) => {
2820
2840
  try {
2821
2841
  const data = JSON.parse(event.data);
2822
- if (data.hasOwnProperty("socket_id") && socket_manager_instances.hasOwnProperty(data["socket_id"])){
2823
- socket_manager_instances[data["socket_id"]].receive_json(data);
2824
- }else{
2842
+ if (data.hasOwnProperty("socket_id") && socket_manager_instances.hasOwnProperty(data["socket_id"])) {
2843
+ socket_manager_instances[data["socket_id"]].receive_json(data);
2844
+ } else {
2825
2845
  console.error("Socket id not found");
2826
2846
  }
2827
2847
  } catch (err) {
2828
2848
  console.error("Error al parsear mensaje WS:", err);
2829
2849
  }
2830
- };
2850
+ };
2831
2851
  }
2832
- send(str){
2833
- if(!socket_connections.hasOwnProperty(this.url)){
2852
+
2853
+ send(str) {
2854
+ if (!socket_connections.hasOwnProperty(this.url)) {
2834
2855
  this.connect();
2835
- }else{
2836
- if(socket_connections[this.url].readyState != WebSocket.OPEN){
2856
+ } else {
2857
+ if (socket_connections[this.url].readyState != WebSocket.OPEN) {
2837
2858
  Reflect.deleteProperty(socket_connections, this.url);
2838
2859
  this.connect();
2839
2860
  }
2840
- }
2841
- if(socket_connections.hasOwnProperty(this.url)){
2861
+ }
2862
+ if (socket_connections.hasOwnProperty(this.url)) {
2842
2863
  socket_connections[this.url].send(str);
2843
2864
  }
2844
2865
  }
@@ -2893,7 +2914,7 @@ function FirmadorLibreLocal(docmanager, signatureManager) {
2893
2914
  callFetch(instance);
2894
2915
  },
2895
2916
  "sign": function (data) {
2896
- if(data.hasOwnProperty("socket_id")){
2917
+ if (data.hasOwnProperty("socket_id")) {
2897
2918
  Reflect.deleteProperty(data, "socket_id");
2898
2919
  }
2899
2920
  let json = JSON.stringify(data);
@@ -2937,7 +2958,7 @@ function FirmadorLibreLocal(docmanager, signatureManager) {
2937
2958
  }
2938
2959
 
2939
2960
  const generateRandomString = () => {
2940
- return Math.floor(Math.random() * Date.now()).toString(36);
2961
+ return Math.floor(Math.random() * Date.now()).toString(36);
2941
2962
  };
2942
2963
 
2943
2964
  function FirmadorLibreWS(docmanager, url, signatureManager) {
@@ -2997,11 +3018,13 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
2997
3018
  break;
2998
3019
  }
2999
3020
  }
3000
- }else{
3021
+ } else {
3001
3022
 
3002
- if(data.hasOwnProperty('tobesigned')){
3023
+ if (data.hasOwnProperty('report')) {
3024
+ docmanager.validate_document_remote_done(data['report']);
3025
+ } else if (data.hasOwnProperty('tobesigned')) {
3003
3026
  docmanager.do_sign_local(data);
3004
- }else{
3027
+ } else {
3005
3028
  docmanager.remote_done(data)
3006
3029
  }
3007
3030
 
@@ -3009,7 +3032,7 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
3009
3032
  },
3010
3033
 
3011
3034
  "inicialize": function () {
3012
- this.websocket = new SocketManager(url, signatureManager, this);
3035
+ this.websocket = new SocketManager(url, signatureManager, this);
3013
3036
 
3014
3037
  },
3015
3038
  "local_done": function (data) {
@@ -3037,12 +3060,24 @@ function FirmadorLibreWS(docmanager, url, signatureManager) {
3037
3060
  alertFunction(errorInterpreter(3), gettext("Error"), "error", false, closeModalSignature);
3038
3061
  }
3039
3062
  },
3063
+
3064
+ "validate_document": function (data) {
3065
+ data["action"] = "validate_document";
3066
+ data["socket_id"] = this.socket_id;
3067
+ signatureManager.showLoading();
3068
+ try {
3069
+ this.websocket.send(JSON.stringify(data));
3070
+ } catch (e) {
3071
+ signatureManager.hideLoading();
3072
+ alertFunction(errorInterpreter(3), gettext("Error"), "error", false, closeModalSignature);
3073
+ }
3074
+ }
3040
3075
  };
3041
3076
  firmador.inicialize();
3042
3077
  return firmador;
3043
3078
  }
3044
3079
 
3045
- function DocumentClient(container, widgetId, signatureManager, url_ws) {
3080
+ function DocumentClient(container, widgetId, signatureManager, url_ws, custom_event) {
3046
3081
  const docmanager = {
3047
3082
  "widgetId": widgetId,
3048
3083
  "container": container,
@@ -3052,6 +3087,7 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
3052
3087
  "certificates": null,
3053
3088
  "doc_instance": null,
3054
3089
  "logo_url": null,
3090
+ "custom_event": custom_event,
3055
3091
 
3056
3092
  "start_sign": function (doc_instance, logo_url = null) {
3057
3093
  this.doc_instance = doc_instance;
@@ -3114,6 +3150,7 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
3114
3150
  }
3115
3151
 
3116
3152
  },
3153
+
3117
3154
  "do_sign_local": function (data) {
3118
3155
  this.localsigner.sign(data);
3119
3156
  },
@@ -3123,21 +3160,91 @@ function DocumentClient(container, widgetId, signatureManager, url_ws) {
3123
3160
  this.remotesigner.complete_sign(data);
3124
3161
  },
3125
3162
  "remote_done": function (data) {
3126
- if(data.result !== null ){
3163
+ if (data.result !== null) {
3127
3164
  const l = btoa(JSON.stringify({'token': data.result}));
3128
- this.signatureManager.doc_instance['value'] =l;
3129
- this.signatureManager.pdfvisor.urls['renderattr']="value="+l;
3130
- document.getElementById(this.signatureManager.input_id).value=l;
3165
+ this.signatureManager.doc_instance['value'] = l;
3166
+ this.signatureManager.pdfvisor.urls['renderattr'] = "value=" + l;
3167
+ document.getElementById(this.signatureManager.input_id).value = l;
3131
3168
  this.signatureManager.pdfvisor.initPDFViewer();
3132
3169
  signatureManager.hideLoading();
3170
+ document.dispatchEvent(this.custom_event);
3133
3171
  alertFunction(
3134
3172
  gettext("The signing was successfully completed."),
3135
3173
  gettext("Success"),
3136
- "success", false, function(){}
3174
+ "success", false, function () {
3175
+ }
3137
3176
  );
3138
- }
3177
+ }
3178
+ },
3179
+
3180
+ "validate_document_remote": function () {
3181
+ data = {
3182
+ "instance": this.doc_instance,
3183
+ }
3184
+ document.dispatchEvent(this.custom_event);
3185
+ //this.remotesigner.validate_document(data);
3139
3186
  },
3140
3187
 
3188
+ "validate_document_remote_done": function (reportData) {
3189
+ signatureManager.hideLoading();
3190
+ if (!reportData || typeof reportData !== 'string') {
3191
+ alertFunction(
3192
+ gettext("Please, sign the document before saving"),
3193
+ gettext("Warning"),
3194
+ "warning", false, function () {
3195
+ }
3196
+ );
3197
+ return;
3198
+ }
3199
+
3200
+ if (reportData.includes("no est&aacute; firmado digitalmente")) {
3201
+ alertFunction(
3202
+ gettext("The document is not digitally signed. Please sign the document before saving."),
3203
+ gettext("Warning"),
3204
+ "warning", false,
3205
+ function () {
3206
+ }
3207
+ );
3208
+ return;
3209
+ }
3210
+
3211
+ const firmasMatch = reportData.match(/Contiene\s*([\d]+)\s*firma/);
3212
+ let numFirmas = 0;
3213
+ if (firmasMatch && firmasMatch[1]) {
3214
+ numFirmas = parseInt(firmasMatch[1], 10);
3215
+ }
3216
+
3217
+ if (numFirmas > 0) {
3218
+ if (typeof update_signed_document === "function") {
3219
+ update_signed_document(this.doc_instance);
3220
+ } else {
3221
+ console.log("warning: update_signed_document function not defined, using default action");
3222
+ alertFunction(
3223
+ gettext(`The document was saved`),
3224
+ gettext("Success"),
3225
+ "success", false,
3226
+ function () {
3227
+ const container = this.signatureManager.container;
3228
+ const form = container.closest('form');
3229
+ if (form) {
3230
+ form.submit();
3231
+ }
3232
+ }.bind(this)
3233
+ );
3234
+ }
3235
+
3236
+ } else {
3237
+ alertFunction(
3238
+ gettext("The document is not digitally signed. Please sign the document before saving."),
3239
+ gettext("Warning"),
3240
+ "warning", false,
3241
+ function () {
3242
+ }
3243
+ );
3244
+ }
3245
+ }
3246
+
3247
+
3141
3248
  };
3142
3249
 
3143
3250
  docmanager["remotesigner"] = new FirmadorLibreWS(docmanager, url_ws, signatureManager);
@@ -229,9 +229,11 @@ function GTBaseFormModal(modal_id, datatable_element, form_config) {
229
229
  }
230
230
  if (inputfield.data().widget === "TaggingInput" || inputfield.data().widget === "EmailTaggingInput") {
231
231
  var tagifyelement = inputfield.data().tagify;
232
- tagifyelement.removeAllTags();
233
- tagifyelement.loadOriginalValues(value);
234
- done = true;
232
+ if (tagifyelement != undefined){
233
+ tagifyelement.removeAllTags();
234
+ tagifyelement.loadOriginalValues(value);
235
+ }
236
+ done = false;
235
237
  }
236
238
  if (!done) {
237
239
  inputfield.val(value);
@@ -808,6 +808,7 @@
808
808
  position: relative;
809
809
  overflow: hidden;
810
810
  border-top: 1px solid #e5e5e5;
811
+ direction: ltr;
811
812
  }
812
813
  .tl-timenav .tl-timenav-line {
813
814
  position: absolute;
@@ -2018,7 +2019,6 @@
2018
2019
  .tl-slidenav-previous .tl-slidenav-content-container,
2019
2020
  .tl-slidenav-next .tl-slidenav-content-container {
2020
2021
  width: 100px;
2021
- position: absolute;
2022
2022
  }
2023
2023
  .tl-slidenav-previous .tl-slidenav-title,
2024
2024
  .tl-slidenav-next .tl-slidenav-title,
@@ -2104,7 +2104,7 @@
2104
2104
  .tl-slidenav-next {
2105
2105
  text-align: right;
2106
2106
  margin-right: 10px;
2107
- right: 100px;
2107
+ right: 0;
2108
2108
  }
2109
2109
  .tl-slidenav-next .tl-slidenav-title,
2110
2110
  .tl-slidenav-next .tl-slidenav-description {
@@ -2118,6 +2118,7 @@
2118
2118
  }
2119
2119
  .tl-slidenav-previous {
2120
2120
  text-align: left;
2121
+ left: 0;
2121
2122
  margin-left: 10px;
2122
2123
  }
2123
2124
  .tl-slidenav-previous .tl-slidenav-icon {
@@ -2126,6 +2127,12 @@
2126
2127
  .tl-slidenav-previous .tl-slidenav-icon:before {
2127
2128
  content: "\e650";
2128
2129
  }
2130
+ [dir="rtl"] .tl-slidenav-previous {
2131
+ direction: ltr;
2132
+ }
2133
+ [dir="rtl"] .tl-slidenav-next:hover .tl-slidenav-icon {
2134
+ margin-right: -4px;
2135
+ }
2129
2136
  /* NAVIGATION HOVER
2130
2137
  ================================================== */
2131
2138
  .tl-slidenav-previous:hover .tl-slidenav-title,
@@ -2154,9 +2161,6 @@
2154
2161
  .tl-slidenav-previous:focus-visible .tl-slidenav-icon {
2155
2162
  margin-left: -4px;
2156
2163
  }
2157
- .tl-skinny .tl-slidenav-next {
2158
- right: 32px;
2159
- }
2160
2164
  .tl-skinny .tl-slidenav-next .tl-slidenav-icon {
2161
2165
  margin-left: 8px;
2162
2166
  }