From 95482c49d1e4f5e54f7743b0e6abe41d2932c0a9 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 26 Jan 2019 15:37:49 -0700 Subject: [PATCH] Prevent notes from being double-created with multiple clicks on Save --- www/js/editnote.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/www/js/editnote.js b/www/js/editnote.js index 52099b3..d871990 100644 --- a/www/js/editnote.js +++ b/www/js/editnote.js @@ -4,7 +4,18 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +var save_in_progress = false; + function saveme(callback) { + if (save_in_progress) { + console.log("Warning: save already in progress, doing nothing."); + return; + } + app.toast.create({ + text: '   Saving...', + closeTimeout: 2 * 60 * 1000 // two whole minutes should be enough for *any* connection. + }).open(); + save_in_progress = true; sync(); // update textareas with correct content var noteid = $("#note_content").data("noteid"); @@ -20,10 +31,11 @@ function saveme(callback) { NOTES.set(note); NOTES.syncAll(function () { app.toast.create({ - text: 'Note saved.', - closeTimeout: 2000 + text: '   Note saved.', + closeTimeout: 3000 }).open(); $("#orig_content").val(note.content); + save_in_progress = false; if (typeof callback == "function") { callback(); } @@ -33,6 +45,7 @@ function saveme(callback) { closeTimeout: 2000 }).open(); $("#orig_content").val(note.content); + save_in_progress = false; if (typeof callback == "function") { callback(); }