PageSourceSearch

https://www.aeecq.org/admin/360/libs/js/auto_save.js?rand_6281=880

js aeecq.org collected 2026-10-08 01:42:04 UTC 30,566 bytes, 844 lines download raw bytes

1$(document).ready(function () {
2  //autosave  //https://stackoverflow.com/questions/45402771/autosave-on-last-keyup-only-jquery-php-mysql-how
3  var timer;
4  //$('.autosave').keyup(function() {
5  //$(document).on('onblur',".autosave", function () {
6
7    //is element before or after / utilisé si on change de focus de champ avec la touche "tab"
8    function isAfter(elA, elB) {
9        return ($('*').index($(elA).last()) > $('*').index($(elB).first()));
10    }
11
12  $(document).on("keyup keypress blur change keydown", ".autosave", function (event) {
13
14    //si on change de focus de champ avec la touche "tab", on annule le switch de champ instantanné pour imposer un timer le temps que l'autosave se déclenche, voir if (event.key === 'Tab')
15    if (event.key === 'Tab'){
16        event.preventDefault();
17    }
18    event_type=event.type;
19    id_input = $(this).attr("id");
20
21    var field_name = $("#" + id_input).attr("field_name");
22    var table_name = $("#" + id_input).attr("table_name");
23    $("#" + id_input).attr("original-data", $(this).attr("self"));
24    if (timer) {
25        clearTimeout(timer);
26    }
27
28    //pour fixer le cas où l'utilisateur passe trop rapidement d'un champ à l'autre (plus vite que le timer par default) et la valeur ne s'enregistre pas
29    //donc si event.type=='focusout' , le timer est mis à 1 milisecond pour saver tout de suite la valeur quand on quite le champ
30    var wait_ms = 450;
31    if (event.type == "focusout" || event.key === 'Tab' || event.key === 'Enter' || event.key === 'keydown') {
32      wait_ms = 1;
33    }
34
35
36
37    timer = setTimeout(function (event) {
38      //validation de la correspondance des mots de passe : les id doivent être #password et #password_confirm
39      if (id_input == "password_confirm" || id_input == "password") {
40        //check si password_confirm = password
41        var password_val = $("#password").val();
42        var password_confirm_val = $("#password_confirm").val();
43        var id_elem = $("#" + id_input).attr("id_elem");
44        if (password_val == password_confirm_val) {
45          if (id_input == "password") {
46            autoSave(id_input,event_type); //on save seulement password, on ne save pas password_confirm
47          }
48          $("#autoSave_password_confirm_" + id_elem).html(
49            "Les mots de passes correspondent"
50          );
51          $("#autoSave_password_confirm_" + id_elem).removeClass(
52            "alert-danger"
53          );
54          $("#autoSave_password_confirm_" + id_elem).addClass("alert-success");
55          autoSave("password");
56        } else {
57          if (id_input == "password_confirm") {
58            $("#autoSave_password_confirm_" + id_elem).html(
59              "Les mots de passe ne correspondent pas"
60            );
61          } else {
62            $("#autoSave_password_confirm_" + id_elem).html(
63              "Confirmez le mot de passe"
64            );
65          }
66
67          $("#autoSave_password_confirm_" + id_elem).removeClass(
68            "alert-success"
69          );
70          $("#autoSave_password_confirm_" + id_elem).addClass("alert-danger");
71        }
72        $("#autoSave_password_confirm_" + id_elem).show();
73      } else if (id_input == "Login") {
74        //validation login libre
75        var self = $("#" + id_input).attr("self");
76        var input_val = $("#" + id_input).val();
77        $.post("/gi2-modules/standard/membre/client/inc/ajax_input.php", {
78          mod: "Login",
79          val: input_val,
80          self: self,
81        }).done(function (data) {
82          if (data) {
83            $("#result_ajax_Login").html(data);
84            $("#Login").val(self);
85          } else {
86            $("#result_ajax_Login").html("");
87            autoSave(id_input,event_type);
88          }
89        });
90      } else if (field_name == "nom" && table_name == "membership__company") {
91        //validation nom organisation libre
92        var self = $("#" + id_input).attr("self");
93        var input_val = $("#" + id_input).val();
94        var id_elem = $("#" + id_input).attr("id_elem"); //pour la maj de company_name des membres de la company
95        $.post("/gi2-modules/standard/membre/client/inc/ajax_input.php", {
96          mod: "membership__company_nom",
97          val: input_val,
98          id_elem: id_elem,
99          self: self,
100        }).done(function (data) {
101          if (data) {
102            $("#result_ajax_membership__company_nom").html(data);
103            $("#" + id_input).val(self);
104          } else {
105            $("#result_ajax_membership__company_nom").html("");
106            autoSave(id_input,event_type);
107          }
108        });
109      } else {
110        autoSave(id_input,event_type);
111      }
112    }, wait_ms); //wait 1000 milliseconds before triggering even.
113
114
115    //si on change de focus de champ avec la touche "tab", on attend pour que autosave se déclenche avant de focus le next element
116    if (event.key === 'Tab'){
117        var $startElement =  $("#" + id_input);
118        var $inputs = $('input[type=text]');
119        setTimeout(function() {
120            //search inputs for one that comes after starting element
121            for (var i = 0; i < $inputs.length; i++) {
122                if (isAfter($inputs[i], $startElement)) {
123                    var nextInput = $inputs[i];
124                    $(nextInput).focus();
125                    break;
126                }
127            }
128        }, 250)
129    }
130
131  });
132
133  //autosage input type select / radio (déclencheur onchange VS keyup)
134  $(document).on("change", ".autosave_select", function () {
135    id_input = $(this).attr("id");
136    if (timer) {
137      clearTimeout(timer);
138    }
139    timer = setTimeout(function (event) {
140      autoSave(id_input);
141    }, 300); //wait 1000 milliseconds before triggering even.
142  });
143  //autosave onchange (pour les btn radio type switch)
144  $(document).on("change", ".autosave_onchange", function () {
145    var elem_id = $(this).attr("id");
146
147    timer = setTimeout(function (event) {
148      autoSave(elem_id);
149    }, 300);
150  });
151  //autosave retour à l'ancienne valeur
152  $(document).on("click", ".autosave_rollback", function () {
153    var id_rollback = $(this).attr("id_rollback");
154    var val_rollback = $(this).attr("val_rollback");
155    $('#'+id_rollback).val(val_rollback);
156    $("#"+id_rollback).trigger("change");
157  });
158
159  $(document).on("click", ".autosave_delete_file",  function () {
160    id_input = $(this).attr("id");
161    $(this).siblings(".auto_upload_file[is_required='1']").attr("required", "required");
162    $(this).siblings(".voir_bouton_fichier_custom").remove(); //pour enlever le bouton voir si il existe deja
163    timer = setTimeout(function (event) {
164      autoSave(id_input);
165    }, 300);
166  });
167
168  /*VG-067836-0*/
169  $(".champ_courriel").change(function () {
170    if (this.checked) {
171      var field_name = $(this).attr("field_name");
172      var valeur_champ = $(this).val();
173      var cust_id = $(this).attr("id_elem");
174      $.post(
175        "/gi2-modules/standard/membre/admin/inc/check_courriel_champ_custom.php",
176        {
177          field_name: field_name,
178          valeur_champ: valeur_champ,
179          cust_id: cust_id,
180        }
181      ).done(function (data) {
182        if (data) {
183          //console.log(data);
184        } else {
185          //console.log(data);
186        }
187      });
188    }
189  });
190});
191
192function autoSave(id_input,event_type='') {
193  /*
194    id_input = l'id du champ html
195    id_elem = l'id dans la table
196    autosave_maj = (optionnel) met à jour la valeur modifier dans l'id specifié
197    */
198  var enctype = 0;
199  /* si champ est required alors ne pas save et garder la valeur */
200  var isRequired = $("#" + id_input).prop("required");
201  var errorSpan = $("#" + id_input).next(".required-error");
202  var ancienne_valeur = $("#" + id_input).attr("self");
203  if (errorSpan.length > 0) {
204    $("#" + id_input)
205      .next(".required-error")
206      .addClass("d-none");
207  }
208  if (
209    isRequired &&
210    event_type!='keyup' &&  //event_type!='keyup' pour permettre d'effacer la valeur pour la réécrire
211    $("#" + id_input)
212      .val()
213      .trim() === ""
214  ) {
215        if ($("#" + id_input).is("select")) {
216          var selectedOption = $("#" + id_input).find(
217            'option[value="' + ancienne_valeur + '"]'
218          );
219          selectedOption.prop("selected", true);
220        } else if (
221          $("#" + id_input).is('input[type="text"]') ||
222          $("#" + id_input).is("textarea")
223        ) {
224          $("#" + id_input).val(ancienne_valeur);
225        }
226        errorMessage = "Ce champ est obligatoire";
227        errorSpan_new =
228          '<p class="text-danger required-error">' + errorMessage + "</p>";
229        if (errorSpan.length > 0) {
230          $("#" + id_input)
231            .next(".required-error")
232            .removeClass("d-none");
233        } else {
234          $("#" + id_input).after(errorSpan_new);
235        }
236        return;
237  }
238  if ($("#" + id_input).attr("type") == "checkbox") {
239    //input type check box
240    var data_input = "";
241    var input_name = $("#" + id_input).attr("name");
242    $(":checkbox[name='" + input_name + "']").each(function () {
243      var ischecked = $(this).is(":checked");
244      if (ischecked) {
245        data_input += $(this).val() + "|";
246      }
247    });
248    enctype = "json";
249  } else if ($("#" + id_input).attr("multiple") == "multiple") {
250    //input type select MULTIPLE
251    var data_input = "";
252    var data_input_temp = "";
253    data_input_temp = $("#" + id_input).val();
254    data_input = data_input_temp.join("|");
255    enctype = "json";
256  } else if ($("#" + id_input).attr("type") == "password") {
257    if ($("#" + id_input).attr("bypassencryption") == "1")
258      enctype = 0;
259    else
260      enctype = "password";
261    var data_input = $("#" + id_input).val();
262  } else {
263    var data_input = $("#" + id_input).val();
264  }
265  if (typeof $("#" + id_input).attr("enctype") !== "undefined")
266    enctype = $("#" + id_input).attr("enctype");
267  if (typeof $("#" + id_input).attr("data-seperator") !== "undefined") {
268    // pour les champs qui sont seprare par exemple par des - ou |
269    var data_input = "";
270    var data_input_array = [];
271    var input_name = $("#" + id_input).attr("name");
272    $(":checkbox[name='" + input_name + "']").each(function () {
273      var ischecked = $(this).is(":checked");
274      if (ischecked) {
275        data_input_array.push($(this).val());
276      }
277    });
278    enctype = "";
279    data_input = data_input_array.join(
280      $("#" + id_input).attr("data-seperator")
281    );
282  }
283  if (typeof $("#" + id_input).attr("data-action") !== "undefined") {
284    var action = $("#" + id_input).attr("data-action");
285    data_input = $("#" + id_input).attr("data-value");
286    retour = $("#" + id_input).attr("data-retour"); // concerne le id du champs qui contient l image dans la page pour la mettre src=''
287  }
288  //if (data_input) {
289
290  var id_elem = $("#" + id_input).attr("id_elem");
291  var field_name = $("#" + id_input).attr("field_name");
292  var table_name = $("#" + id_input).attr("table_name");
293  var primary_key = $("#" + id_input).attr("primary_key");
294  var autosave_maj_val = $("#" + id_input).attr("primary_key");
295
296  //check si attribut spc_enctype existe
297  if (enctype == 0) {
298    var spc_enctype = $("#" + id_input).attr("spc_enctype");
299    if (typeof spc_enctype !== "undefined" && spc_enctype !== false) {
300      enctype = spc_enctype;
301    }
302  }
303
304  var GO = 1;
305  if (
306    $("#" + id_input).is('input[type="text"]') ||
307    $("#" + id_input).is("textarea") ||
308    $("#" + id_input).is('input[type="password"]')
309  ) {
310    //cas on focus un champ text/textarea/password sans changer la valeur, on met à jour seulement si la valeur est modifiée
311    GO = 0;
312    if (ancienne_valeur != data_input) {
313      //si champ text/textarea/password et ancienne_valeur!=nouvelle_valeur => GO
314      GO = 1;
315    }
316  }
317  var module_id = "";
318  if ($("#" + id_input).attr("module_id") !="") {
319      module_id = $("#" + id_input).attr("module_id");
320  }
321  data_send = {
322    id_elem: id_elem,
323    data_input: data_input,
324    field_name: field_name,
325    table_name: table_name,
326    primary_key: primary_key,
327    enctype: enctype,
328    action: action,
329    ancienne_valeur: ancienne_valeur,
330    module:module_id
331  };
332
333  if (isRequired && data_input==''){GO=0;}
334
335  if (GO == 1) {
336    $.ajax({
337      url: "/admin/360/libs/ajax/ajax_auto_save.php",
338      method: "POST",
339      data: data_send,
340      dataType: "text",
341      success: function (data) {
342        var time = showTime();
343        if (action == "delete_file") {
344          if (retour != "") $("#" + retour + " img").attr("src", "");
345          $("#" + id_input).hide();
346        }
347        $("#autoSave_" + field_name + "_" + id_elem).show();
348        setTimeout(function () {
349          $("#autoSave_" + field_name + "_" + id_elem).fadeOut(1000);
350        }, 200);
351        $("#rollback_" + field_name + "_" + id_elem).show();
352
353        if ($("#autosave_maj_" + field_name + "_" + id_elem).length) {
354          //si un element avec l'id autosave_maj... exist, on met à jour la valeur affiché
355          $("#autosave_maj_" + field_name + "_" + id_elem).html(data_input);
356        }
357        var attrib = $("#" + id_input).attr("self"); //pour les champs courriel
358        if (typeof attrib !== "undefined" && attrib !== false) {
359          $("#" + id_input).attr("self", data_input);
360        }
361
362        /** debut traitement journalisation */
363        table_name = $("#" + id_input).attr("table_name");
364
365        const isHidden = $("#" + id_input).is(":hidden");
366        const hasRadioSwitch =
367          $("#" + id_input).siblings(".toogle_switch_radio").length > 0;
368        const hasInterrupteur =
369          $("#" + id_input).siblings(".toogle_switch_interrupteur").length > 0;
370
371        const isvalidinput =
372          !isHidden || (isHidden && (hasRadioSwitch || hasInterrupteur));
373
374        const beta_inclus = [
375          "news",
376          "gi2__maintenance",
377          "cron",
378          "centre_doc__doc",
379          "centre_doc__document_file",
380          "centre_doc__liens",
381          "z_customers",
382          "z_address_book",
383          "z_custom_field_data",
384          "membership__categorie_adh",
385          "gi2__admins",
386          "rapport_perso_admin",
387          "gi2__admins_access_champs_group",
388          "gi2__admins_access_champs",
389          "membership__company",
390        ];
391        var nojournal = $("#" + id_input).attr("no-journal") == 1;
392
393        if (!nojournal && isvalidinput && beta_inclus.includes(table_name)) {
394          // a des moments jai pas les bonnes valeurs
395          id_elem = $("#" + id_input).attr("id_elem");
396          field_name = $("#" + id_input).attr("field_name");
397          table_name = $("#" + id_input).attr("table_name");
398          primary_key = $("#" + id_input).attr("primary_key");
399          original_data = $("#" + id_input).attr("original-data");
400
401          //if ($("#" + id_input).hasAttribute("org_id")) {
402            org_id = $("#" + id_input).attr("org_id");
403          //}
404          data_send = {
405            id_elem: id_elem,
406            data_input: data_input,
407            field_name: field_name,
408            table_name: table_name,
409            enctype: enctype,
410            typeinput: $("#" + id_input).attr("type"),
411            primary_key: primary_key,
412            org_id:org_id,
413          };
414          const beta_inclus = [
415            "news",
416            "gi2__maintenance",
417            "cron",
418            "centre_doc__doc",
419            "centre_doc__document_file",
420            "centre_doc__liens",
421            "z_customers",
422            "z_address_book",
423            "z_custom_field_data",
424            "gi2__admins",
425            "membership__categorie_adh",
426            "rapport_perso_admin",
427            "gi2__admins_access_champs_group",
428            "gi2__admins_access_champs",
429            'membership__company'
430          ];
431          var nojournal = $("#" + id_input).attr("no-journal") == 1;
432          if (beta_inclus.includes(table_name)) {
433            mettre_jours_journal(
434              id_input,
435              table_name,
436              $("#" + id_input).attr("name"),
437              data_send
438            );
439          }
440        }
441        /** fin traitement journalisation */
442        /* pour les champs qui ont besoin que la page soie reloadée apres qu'ils soient modifiés , ajouter reloader="1" exemple les collaborateurs et groupes de AQU */
443        var attr_realoder = $("#" + id_input).attr('reloader');
444        if (typeof attr_realoder !== 'undefined' && attr_realoder !== false && attr_realoder === '1') {
445          window.location.href = window.location.href;
446        }
447      },
448    });
449  }
450  //}
451}
452
453function showTime() {
454  var timeNow = new Date();
455  var hours = timeNow.getHours();
456  var minutes = timeNow.getMinutes();
457  var seconds = timeNow.getSeconds();
458  var timeString = "" + (hours > 12 ? hours - 12 : hours);
459  timeString += (minutes < 10 ? ":0" : ":") + minutes;
460  timeString += (seconds < 10 ? ":0" : ":") + seconds;
461  timeString += hours >= 12 ? " P.M." : " A.M.";
462  return timeString;
463}
464/*--- fonction qui permet de mettre jours le journal des actions */
465function mettre_jours_journal(id_input, table_name, input_name, data_send) {
466  data_send.original_data = $("#" + id_input).attr("original-data");
467  data_send.val_field = $("#" + id_input).val();
468  data_send.id_input = id_input;
469  data_send.from_client = $('#from_client_save').val() ? $('#from_client_save').val() : 0; //pour savoir si on est dans le client ou admin
470
471  // Try to retrieve the label of the modified field
472  label = "";
473  //console.log($("#" + id_input),$("#" + id_input).is("[label-journalisation]"))
474  if ($("#" + id_input).is("[label-journalisation]")) {
475    label = $("#" + id_input).attr("label-journalisation");
476  } else {
477    label = getLabel(id_input);
478  }
479  let optionlabel = getlabeloptions(id_input, table_name, input_name);
480
481  // Update the log with the sent data
482  if (label) data_send.label = label;
483  if (typeof optionlabel !== "undefined" && optionlabel !== "") {
484    data_send.original_data = "";
485    data_send.label_options = optionlabel;
486  }
487
488  // Perform AJAX request to update the journal
489  $.ajax({
490    url: "/admin/360/libs/ajax/ajax_auto_save_journal.php",
491    method: "POST",
492    data: data_send,
493    success: function (response) {
494      $("#" + data_send.id_input).attr("original-data", data_send.val_field);
495    },
496    error: function (xhr, status, error) {},
497  });
498}
499
500function getLabel(id_input) {
501  let label = "";
502
503  // Vérifie si l'élément parent est une étiquette
504  if (
505    $("#" + id_input)
506      .parent()
507      .is("label")
508  ) {
509    // Récupère le texte de l'étiquette
510    label = $("#" + id_input)
511      .parent()
512      .contents()
513      .filter(function () {
514        return this.nodeType === Node.TEXT_NODE;
515      })
516      .text()
517      .trim();
518
519    // Si le texte est vide, essaie de récupérer le texte de l'étiquette précédente
520    if (label === "") {
521      label = $("#" + id_input)
522        .prev()
523        .text()
524        .trim();
525    }
526  }
527  if (label === "") {
528    label = $("[for='" + id_input + "']")
529      .text()
530      .trim();
531  }
532
533  // Vérifie à nouveau si le texte est vide et essaie d'autres méthodes pour récupérer le texte
534  if (label === "") {
535    label = $("#" + id_input)
536      .prev("label")
537      .text()
538      .trim();
539  }
540
541  // Essaie de récupérer le texte à partir du nœud suivant de l'élément
542  if (label === "") {
543    const element = document.getElementById(id_input);
544
545    if (element) {
546      // Check if element exists
547      const nextText = element.nextSibling;
548
549      // Check if nextText exists and is a text node
550      if (nextText && nextText.nodeType === Node.TEXT_NODE) {
551        label = nextText.nodeValue.trim();
552      } else {
553        label = ""; // Explicitly set label to an empty string if no valid text node is found
554      }
555    }
556  }
557/*
558  // Dernière tentative de récupération du texte de l'étiquette
559  if (label === "") {
560    label = $("#" + id_input)
561      .parent()
562      .find("label")
563      .text()
564      .trim();
565  }
566  // si cest dans un tableau
567  if (label == "" || !label) {
568    // Check if the input is inside a <td>
569    var inputElement = $("#" + id_input);
570    if (inputElement.length > 1)
571      var inputElement = $(
572        "#" + id_input + "[value='" + $("#" + id_input).val() + "']"
573      );
574
575    var inputTd = inputElement.closest("td");
576
577    if (inputTd.length) {
578      // Ensure inputTd exists
579      var row = inputElement.closest("tr");
580
581      // Get the label from the first <td> in the row
582      var labelone = row.find("td:first").text().trim(); // "Session permanente"
583
584      // Check for extra text in the same <td>
585      var extraText = inputTd.text().trim();
586
587      if (extraText && extraText !== labelone) {
588        label = extraText; // Use the extra text as labels
589      } else {
590        // Get the index of the current <td> to find the corresponding header <th>
591        var index = row.find("td").index(inputTd);
592
593        // Get the header text based on the index
594        var typeLabel = inputElement
595          .closest("table")
596          .find("th")
597          .eq(index)
598          .text()
599          .trim(); // "Type"
600
601        label = labelone + " - " + typeLabel;
602      }
603    }
604  }
605  if (label === "") {
606    label = $("#" + id_input)
607      .parent()
608      .siblings("table-cell")
609      .text()
610      .trim();
611  }*/
612
613  return label;
614}
615function getlabeloptions(id_input, table_name, input_name) {
616  /*** recuperer le nom de l option si radio/select/checkbox */
617  label_options = "";
618  // Vérifiez si l'élément est une liste déroulante (select)
619  if ($("#" + id_input).is("select")) {
620    // Récupérer le texte de l'option sélectionnée et le nettoyer
621    label_options = $("#" + id_input + " option:selected")
622      .text()
623      .trim();
624  }
625
626  // Vérifier si l'élément est une case à cocher ou un bouton radio
627  if ($("#" + id_input).is(":checkbox") || $("#" + id_input).is(":radio")) {
628    // si le attribute option-journalisation est set sur les options d un checkbox
629    if (
630      $("#" + id_input).is(":checkbox") &&
631      $("#" + id_input).is("[option-journalisation]")
632    ) {
633      label_options_array = [];
634      $(":checkbox[name='" + input_name + "']:checked").each(function () {
635        label_options_array.push($(this).attr("option-journalisation"));
636      });
637
638      if (label_options_array.length > 0) {
639        label_options = label_options_array.join(" et ");
640      }
641    }
642
643    if (
644      $("#" + id_input).is(":radio") &&
645      $("#" + id_input).is("[option-journalisation]")
646    ) {
647      label_options = $("#" + id_input).attr("option-journalisation");
648    }
649  }
650  if ($("#" + id_input).siblings(".toogle_switch_interrupteur").length > 0) {
651    interrup_id = $("#" + id_input)
652      .siblings(".interuupteur_id")
653      .val();
654    if (interrup_id > 0) {
655      label_options = $("#label_interrupteur_" + interrup_id).text();
656    }
657  }
658  // verifier si cest un interrupteur
659
660  return label_options;
661}
662
663/*---------------------- auto file delete -----------------------*/ //ne pas changer le nom des id
664$(document).on("click", ".ajax_delete_file", function (e) {
665    var filename = $(this).attr("file-name") ?? "";
666
667    if(!confirm("Êtes vous sur de vouloir supprimer ce document?") || filename == "")
668        return;
669
670    var form_data = new FormData();
671    var error = "";
672    var path = $(this).attr("path");
673    var one_drive_active = $(this).attr("one_drive_active") ?? "0";
674    var element_delete = $(this).attr("delete-element") ?? "";
675
676
677    form_data.append("path", path);
678    form_data.append("file_name", filename);
679    form_data.append("one_drive_active", one_drive_active);
680
681    var ajax_request = new XMLHttpRequest();
682    ajax_request.onreadystatechange = function () {
683      if (ajax_request.readyState == XMLHttpRequest.DONE && ajax_request.responseText == "DONE") {
684        $("#" + element_delete + "").remove();
685      } else if (ajax_request.readyState == XMLHttpRequest.DONE && ajax_request.responseText == "ERROR") {
686          alert("Erreur lors de la suppression du fichier!");
687      }
688    };
689    ajax_request.open("POST", "/admin/360/libs/ajax/ajax_auto_delete_file.php");
690    ajax_request.send(form_data);
691})
692
693/*---------------------- auto upload - progress bar -----------------------*/ //ne pas changer le nom des id
694
695function _(element) {
696  return document.getElementById(element);
697}
698
699//_('select_file').onchange = function(event){
700$(document).on("change", ".auto_upload_file", function (e) {
701  var form_data = new FormData();
702  var this_input= $(this);
703  var image_number = 1;
704  var error = "";
705  var path = $(this).attr("path");
706  var one_drive_active = $(this).attr("one_drive_active") ?? "0";
707  var input_file_id = $(this).attr("id");
708  var progress_bar_id = $(this).attr("progress_bar_id");
709  var progress_bar_content_id = $(this).attr("progress_bar_content_id");
710  var result_autosave_id = $(this).attr("result_autosave_id");
711  var result_upload_id = $(this).attr("result_upload_id");
712  var liste_docs_append = $(this).attr("liste_docs_append") ?? "";
713  var identifier = $(this).attr("data-element-identifier") ?? '';
714  var forceExactFilename = $(this).attr("forceExactFilename") ?? '';
715  var allowUniqueFilename = $(this).attr("allowUniqueFilename") ?? '';
716
717
718  //for(var count = 0; count < $('#'+input_file_id).files.length; count++)  {
719  for (var count = 0; count < _(input_file_id).files.length; count++) {
720    /*if(!['image/jpeg', 'image/png', 'video/mp4'].includes(_('select_file').files[count].type)){
721            error += '<div class="alert alert-danger"><b>'+image_number+'</b> Selected File must be .jpg or .png Only.</div>';
722        } else {*/
723    form_data.append("images[]", _(input_file_id).files[count]);
724    //}
725    image_number++;
726  }
727  form_data.append("path", path);
728  form_data.append("allowUniqueFilename", allowUniqueFilename);
729  form_data.append("forceExactFilename", forceExactFilename);
730  form_data.append("one_drive_active", one_drive_active);
731
732  if (error != "") {
733    _(result_upload_id).innerHTML = error;
734    _(input_file_id).value = "";
735  } else {
736    _(progress_bar_id).style.display = "block";
737    var ajax_request = new XMLHttpRequest();
738    ajax_request.onreadystatechange = function () {
739      if (ajax_request.readyState == XMLHttpRequest.DONE) {
740        file_infos = JSON.parse(ajax_request.responseText);
741
742        $("#" + result_autosave_id + "").val(file_infos['filename']); //alert(ajax_request.responseText);
743        $("#" + result_upload_id + "").empty();
744
745        url_path = path + "" + file_infos['filename'];
746
747        if (one_drive_active == "1") {
748            url_path = file_infos['file_url'];
749        }
750
751        if (liste_docs_append != "") {
752            count_children = $("#"+liste_docs_append).children().length;
753            if (identifier != "") {
754                identifier = identifier + "_";
755            }
756            $("#"+liste_docs_append).append(`
757            <div class="row" id="ajax_delete_file_`+identifier+count_children+`">
758                <div class="col-md-1">
759                    <a class="ajax_delete_file" href="javascript:void(0)" path="${path}" delete-element="ajax_delete_file_`+identifier+count_children+`" file-name="`+file_infos['filename']+`" one_drive_active="1">
759<i class="fa-solid fa-trash-xmark"></i></a>
760                </div>
761                <div class="col-md-6">
762                    <a href="`+file_infos['file_url']+`" target="_blank">`+file_infos['filename']+`</a>
763                </div>
764                <div class="col-md-4">
765                    Date: `+file_infos['date_uploaded']+`
766                </div>
767            </div>
768            `);
769        }
770        $("#" + result_upload_id + "").siblings(".voir_bouton_fichier_custom").remove(); //pour enlever le bouton voir si il existe deja
771        $("#" + result_upload_id + "").html(
772          '<a href="' +
773            url_path +
774            '" target="_blank"  class="btn bouton_fichier_custom voir_bouton_fichier_custom" >Voir le document</a>'
775        );
776        //autosave le fichier upload
777        var id_elem = $("#" + result_autosave_id + "").attr("id_elem");
778        if (id_elem) {
779          //var id_elem=$('#result_auto_upload').attr('id_elem');
780          var data_input = $("#" + result_autosave_id + "").val();
781          var field_name = $("#" + result_autosave_id + "").attr("field_name");
782          var table_name = $("#" + result_autosave_id + "").attr("table_name");
783          var primary_key = $("#" + result_autosave_id + "").attr("primary_key");
784          var ancienne_valeur = $("#" + result_autosave_id + "").attr("self");
785
786          var module_id = "";
787          if ($("#" + result_autosave_id).attr("module_id") !="") {
788              module_id = $("#" + result_autosave_id).attr("module_id");
789          }
790          //var org_id = $("#" + id_input).attr("org_id");  //obsolette?
791          $.ajax({
792            url: "/admin/360/libs/ajax/ajax_auto_save.php",
793            method: "POST",
794            data: {
795              id_elem: id_elem,
796              data_input: data_input,
797              field_name: field_name,
798              table_name: table_name,
799              primary_key: primary_key,
800              ancienne_valeur: ancienne_valeur,
801              module: module_id,
802              //org_id: org_id,
803            },
804            dataType: "text",
805            success: function (data) {
806            if ($("#input_" + id_elem).prop("required")) {
807                $("#input_" + id_elem).prop("required", "");
808                $("#input_" + id_elem).removeAttr("required");
809            }
810
811              data_send = {
812                id_elem: id_elem,
813                data_input: data_input,
814                field_name: field_name,
815                table_name: table_name,
816                primary_key: primary_key,
817                module: module_id,
818                //org_id: org_id,
819              };
820              mettre_jours_journal(
821                result_autosave_id,
822                table_name,
823                "",
824                data_send
825              );
826            },
827          });
828        }
829      }
830    };
831    ajax_request.open("POST", "/admin/360/libs/ajax/ajax_auto_upload_file.php");
832    ajax_request.upload.addEventListener("progress", function (event) {
833      var percent_completed = Math.round((event.loaded / event.total) * 100);
834      _(progress_bar_content_id).style.width = percent_completed + "%";
835      _(progress_bar_content_id).innerHTML = percent_completed + "% completed";
836    });
837    ajax_request.addEventListener("load", function (event) {
838      _(input_file_id).value = "";
839      this_input.removeAttr("required");
840      
841    });
842    ajax_request.send(form_data);
843  }
844});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.