Projet

Général

Profil

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

Benjamin Dauvergne, 27 octobre 2021 09:11

Télécharger (1,57 ko)

Voir les différences:

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

 wcs/qommon/static/js/qommon.forms.js | 15 ++++++++++++---
 1 file changed, 12 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
        debounce_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
          debounce_autosave();
147 147
        }
148 148
      });
149 149
    }
150
    autosave_timeout_id = window.setTimeout(autosave, 5000);
150

  
151
    function debounce_autosave() {
152
       window.clearTimeout(autosave_timeout_id);
153
       autosave_timeout_id = window.setTimeout(autosave, 8000);
154
    }
155

  
156
    $(document).on('mouseover scroll keydown', debounce_autosave);
157

  
158
    debounce_autosave();
159

  
151 160
    $('#tracking-code a').on('click', autosave);
152 161
    $(document).on('wcs:set-last-auto-save', function() {
153 162
      last_auto_save = $('form[data-has-draft]').serialize();
154
-