From 511ac27620174b979b95e0482cd2421e40658ed9 Mon Sep 17 00:00:00 2001 From: Helmy Giacoman Date: Thu, 2 Mar 2017 11:13:48 -0600 Subject: [PATCH] BK-2174 Turn off autosave by default in editor to avoid saving revision issues I moved the place where we enable the editor autosave function. It now can be easily customised from instances --- lib/booktype/apps/edit/static/edit/js/booktype/edit.js | 4 ++-- lib/booktype/apps/edit/static/edit/js/booktype/editor.js | 4 ---- lib/booktype/apps/edit/templates/edit/edit_config.html | 1 + lib/booktype/apps/edit/views.py | 5 +++++ lib/booktype/constants.py | 6 ++++++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/booktype/apps/edit/static/edit/js/booktype/edit.js b/lib/booktype/apps/edit/static/edit/js/booktype/edit.js index d504f01da..925a16918 100644 --- a/lib/booktype/apps/edit/static/edit/js/booktype/edit.js +++ b/lib/booktype/apps/edit/static/edit/js/booktype/edit.js @@ -332,13 +332,13 @@ }); // Autosave chapter - if (win.booktype.editor.data.settings.config.edit.autosave.enabled) { + if (win.booktype.editor.autosave.enabled) { setInterval(function () { var $editor = Aloha.getEditableById('contenteditor'); if (!_.isUndefined($editor) && $editor && $editor.isModified()) { win.booktype.editor.edit.saveContent({minor: true}) } - }, win.booktype.editor.data.settings.config.edit.autosave.delay * 1000); + }, win.booktype.editor.autosave.delay * 1000); } // Tabs diff --git a/lib/booktype/apps/edit/static/edit/js/booktype/editor.js b/lib/booktype/apps/edit/static/edit/js/booktype/editor.js index 3d9d34ba3..9d258ea68 100644 --- a/lib/booktype/apps/edit/static/edit/js/booktype/editor.js +++ b/lib/booktype/apps/edit/static/edit/js/booktype/editor.js @@ -76,10 +76,6 @@ 'TABLE': ['horizontalline', 'pbreak', 'indent-left', 'indent-right'], 'PRE': ['insertImage', 'insertLink', 'horizontalline', 'pbreak', 'indent-left', 'indent-right'], 'ALL': ['insertImage', 'insertLink', 'horizontalline', 'pbreak', 'indent-left', 'indent-right'] - }, - 'autosave': { - 'enabled': true, - 'delay': 10 } }, 'media': { diff --git a/lib/booktype/apps/edit/templates/edit/edit_config.html b/lib/booktype/apps/edit/templates/edit/edit_config.html index d4580dac8..ed016b42c 100644 --- a/lib/booktype/apps/edit/templates/edit/edit_config.html +++ b/lib/booktype/apps/edit/templates/edit/edit_config.html @@ -17,6 +17,7 @@ window.booktype.sputnikDispatcherURL = "{% url 'sputnik_dispatcher' %}"; window.booktype.activeProfile = "{{ ACTIVE_PROFILE }}"; window.booktype.editor.historyURL = "{% url 'edit:history' book.url_title %}"; + window.booktype.editor.autosave = {{ autosave|safe }} window.booktype.bookSettingsURL = "{% url 'edit:settings' book.url_title %}"; var settings = { diff --git a/lib/booktype/apps/edit/views.py b/lib/booktype/apps/edit/views.py index 47fbf5edb..0b4bf9531 100644 --- a/lib/booktype/apps/edit/views.py +++ b/lib/booktype/apps/edit/views.py @@ -463,6 +463,11 @@ def get_context_data(self, **kwargs): context['is_owner'] = book.owner == self.request.user context['publish_options'] = config.get_configuration('PUBLISH_OPTIONS') + context['autosave'] = json.dumps({ + 'enabled': config.get_configuration('EDITOR_AUTOSAVE_ENABLED'), + 'delay': config.get_configuration('EDITOR_AUTOSAVE_DELAY') + }) + return context def get_login_url(self): diff --git a/lib/booktype/constants.py b/lib/booktype/constants.py index d93ad7a98..a1e3d80f6 100644 --- a/lib/booktype/constants.py +++ b/lib/booktype/constants.py @@ -120,6 +120,12 @@ MOBI_DOCUMENT_WIDTH = 2480 EPUB_DOCUMENT_WIDTH = 2480 +# editor stuff here +EDITOR_AUTOSAVE_ENABLED = False # disabled by default +EDITOR_AUTOSAVE_DELAY = 60 # time in seconds + +# end editor stuff + EPUB_NOT_ALLOWED_TAGS = ( # 'strip' - drop tag, leave content # 'drop' - drop tag, drop content