Projet

Général

Profil

0003-js-prevent-autosave-while-user-is-active-58208.patch

Benjamin Dauvergne, 27 octobre 2021 09:20

Télécharger (1,99 ko)

Voir les différences:

Subject: [PATCH 3/3] js: prevent autosave while user is active (#58208)

 wcs/qommon/static/js/qommon.forms.js | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
wcs/qommon/static/js/qommon.forms.js
130 130
      if ($form.hasClass('disabled-during-submit')) return;
131 131
      var new_auto_save = $form.serialize();
132 132
      if (last_auto_save == new_auto_save) {
133
        autosave_timeout_id = window.setTimeout(autosave, 5000);
133
        install_autosave();
134 134
        return;
135 135
      }
136 136
      $.ajax({
......
143 143
          }
144 144
        },
145 145
        complete: function() {
146
          autosave_timeout_id = window.setTimeout(autosave, 5000);
146
          if (autosave_timeout_id !== null) {
147
              install_autosave();
148
          }
147 149
        }
148 150
      });
149 151
    }
150
    autosave_timeout_id = window.setTimeout(autosave, 5000);
152

  
153
    function install_autosave() {
154
       // debounce
155
       window.clearTimeout(autosave_timeout_id);
156
       autosave_timeout_id = window.setTimeout(autosave, 8000);
157
    }
158

  
159
    $(document).on('mouseover scroll keydown', function() { if (autosave_timeout_id !== null) { install_autosave(); });
160

  
161
    install_autosave();
162

  
151 163
    $('#tracking-code a').on('click', autosave);
152 164
    $(document).on('wcs:set-last-auto-save', function() {
153 165
      last_auto_save = $('form[data-has-draft]').serialize();
......
362 374
    var $form = $(this);
363 375
    if (autosave_timeout_id) {
364 376
      window.clearTimeout(autosave_timeout_id);
377
      autosave_timeout_id = null;
365 378
    }
366 379
    $form.addClass('disabled-during-submit');
367 380
    if ($form.hasClass('download-button-clicked')) {
368
-