Projet

Général

Profil

0001-forms-disable-autosave-while-form-is-submitted-31706.patch

Frédéric Péters, 25 mars 2019 17:41

Télécharger (2,05 ko)

Voir les différences:

Subject: [PATCH] forms: disable autosave while form is submitted (#31706)

 wcs/qommon/static/js/qommon.forms.js | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
wcs/qommon/static/js/qommon.forms.js
1 1
$(function() {
2
  var autosave_timeout_id = null;
2 3
  if ($('form[data-has-draft]').length == 1) {
3 4
    var last_auto_save = $('form[data-has-draft]').serialize();
4
    var timeout_id = null;
5 5
    function autosave() {
6
      var new_auto_save = $('form[data-has-draft]').serialize();
6
      var $form = $('form[data-has-draft]');
7
      if ($form.hasClass('disabled-during-submit')) return;
8
      var new_auto_save = $form.serialize();
7 9
      if (last_auto_save == new_auto_save) {
8
        timeout_id = window.setTimeout(autosave, 5000);
10
        autosave_timeout_id = window.setTimeout(autosave, 5000);
9 11
        return;
10 12
      }
11 13
      $.ajax({
......
18 20
          }
19 21
        },
20 22
        complete: function() {
21
          timeout_id = window.setTimeout(autosave, 5000);
23
          autosave_timeout_id = window.setTimeout(autosave, 5000);
22 24
        }
23 25
      });
24 26
    }
25
    timeout_id = window.setTimeout(autosave, 5000);
27
    autosave_timeout_id = window.setTimeout(autosave, 5000);
26 28
    $('#tracking-code a').on('click', autosave);
27 29
  }
28 30
  $('.date-pick').each(function() {
......
56 58
  });
57 59
  $('form').on('submit', function(event) {
58 60
    var $form = $(this);
61
    if (autosave_timeout_id) {
62
      window.clearTimeout(autosave_timeout_id);
63
    }
59 64
    $form.addClass('disabled-during-submit');
60 65
    if ($form.hasClass('download-button-clicked')) {
61 66
      /* form cannot be disabled for download buttons as the user will stay on
62
-