From 3ff1a6f83d3c7e5ca1292b86f05c6ce122210cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=CC=81n=20Mikla=CC=81s=CC=8C?= Date: Wed, 29 May 2019 19:55:04 +0200 Subject: [PATCH] Skip auto saving when moving through history of changes [MAILPOET-1976] --- assets/js/src/newsletter_editor/components/save.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/assets/js/src/newsletter_editor/components/save.js b/assets/js/src/newsletter_editor/components/save.js index eb4f4e9e07..5d5de278d1 100644 --- a/assets/js/src/newsletter_editor/components/save.js +++ b/assets/js/src/newsletter_editor/components/save.js @@ -11,6 +11,7 @@ import _ from 'underscore'; var Module = {}; var saveTimeout; +var skipNextAutoSave; // Save editor contents to server Module.save = function () { @@ -292,6 +293,10 @@ Module.autoSave = function () { Module._cancelAutosave(); saveTimeout = setTimeout(function () { + if (skipNextAutoSave) { + skipNextAutoSave = false; + return; + } App.getChannel().request('save').always(function () { Module._cancelAutosave(); }); @@ -305,6 +310,10 @@ Module._cancelAutosave = function () { saveTimeout = undefined; }; +Module.onHistoryUpdate = function onHistoryUpdate() { + skipNextAutoSave = true; +}; + Module.beforeExitWithUnsavedChanges = function (e) { var message; var event; @@ -325,6 +334,7 @@ App.on('before:start', function (BeforeStartApp) { var Application = BeforeStartApp; Application.save = Module.save; Application.getChannel().on('autoSave', Module.autoSave); + Application.getChannel().on('historyUpdate', Module.onHistoryUpdate); window.onbeforeunload = Module.beforeExitWithUnsavedChanges;