From 1a59f2edcc0df660e9a98f9c309c2f91ffc50932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 20 Jan 2016 14:28:50 +0100 Subject: [PATCH 4/4] forms: let autosave() call finish before starting a new one --- wcs/qommon/static/js/qommon.forms.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wcs/qommon/static/js/qommon.forms.js b/wcs/qommon/static/js/qommon.forms.js index 6a2559f..8815f14 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -5,9 +5,13 @@ $(function() { }); if ($('form[data-has-draft]').length == 1) { var last_auto_save = $('form[data-has-draft]').serialize(); - var timeout_id = window.setInterval(function() { + var timeout_id = null; + function autosave() { var new_auto_save = $('form[data-has-draft]').serialize(); - if (last_auto_save == new_auto_save) return; + if (last_auto_save == new_auto_save) { + timeout_id = window.setTimeout(autosave, 5000); + return; + } $.ajax({ type: 'POST', url: window.location.pathname + 'autosave', @@ -16,9 +20,11 @@ $(function() { if (json.result == 'success') { last_auto_save = new_auto_save; } + timeout_id = window.setTimeout(autosave, 5000); } }); - }, 5000); + } + timeout_id = window.setTimeout(autosave, 5000); } $('#tracking-code button').click(function() { $('input[name=savedraft]').click(); -- 2.7.0.rc3