Projet

Général

Profil

0002-js-abort-current-autosave-ajax-request-on-submit-582.patch

Benjamin Dauvergne, 28 octobre 2021 23:46

Télécharger (1,71 ko)

Voir les différences:

Subject: [PATCH 2/4] js: abort current autosave ajax request on submit
 (#58276)

 wcs/qommon/static/js/qommon.forms.js | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
wcs/qommon/static/js/qommon.forms.js
124 124
$(function() {
125 125
  var autosave_timeout_id = null;
126 126
  var autosave_is_running = false;
127
  var autosave_xhr = null;
127 128
  if ($('form[data-has-draft]').length == 1) {
128 129
    var last_auto_save = $('form[data-has-draft]').serialize();
129 130
    function autosave() {
......
135 136
        install_autosave();
136 137
        return;
137 138
      }
138
      $.ajax({
139
      autosave_xhr = $.ajax({
139 140
        type: 'POST',
140 141
        url: window.location.pathname + 'autosave',
141 142
        data: new_auto_save,
......
146 147
        },
147 148
        complete: function() {
148 149
          autosave_is_running = false;
150
          autosave_xhr = null;
149 151
          if (autosave_timeout_id !== null) {
150 152
              install_autosave();
151 153
          }
......
379 381
  });
380 382
  $('form').on('submit', function(event) {
381 383
    var $form = $(this);
384
    /* abort current autosave */
385
    if (autosave_xhr !== null) {
386
      autosave_xhr.abort();
387
      autosave_xhr = null;
388
    }
382 389
    /* prevent more autosave */
383 390
    if (autosave_timeout_id !== null) {
384 391
      window.clearTimeout(autosave_timeout_id);
385
-