Projet

Général

Profil

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

Benjamin Dauvergne, 27 octobre 2021 09:54

Télécharger (2,23 ko)

Voir les différences:

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

 wcs/qommon/static/js/qommon.forms.js | 25 ++++++++++++++++++++++---
 1 file changed, 22 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
      $('body').addClass('autosaving');
136 137
      $.ajax({
137 138
        type: 'POST',
138 139
        url: window.location.pathname + 'autosave',
......
143 144
          }
144 145
        },
145 146
        complete: function() {
146
          autosave_timeout_id = window.setTimeout(autosave, 5000);
147
          $('body').removeClass('autosaving');
148
          if (autosave_timeout_id !== null) {
149
              install_autosave();
150
          }
147 151
        }
148 152
      });
149 153
    }
150
    autosave_timeout_id = window.setTimeout(autosave, 5000);
154

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

  
161
    $(document).on('mouseover scroll keydown', function() {
162
        if (autosave_timeout_id !== null && ! $('body').hasClass('autosaving')) {
163
            install_autosave();
164
        }
165
    );
166

  
167
    install_autosave();
168

  
151 169
    $('#tracking-code a').on('click', autosave);
152 170
    $(document).on('wcs:set-last-auto-save', function() {
153 171
      last_auto_save = $('form[data-has-draft]').serialize();
......
362 380
    var $form = $(this);
363 381
    if (autosave_timeout_id) {
364 382
      window.clearTimeout(autosave_timeout_id);
383
      autosave_timeout_id = null;
365 384
    }
366 385
    $form.addClass('disabled-during-submit');
367 386
    if ($form.hasClass('download-button-clicked')) {
368
-