From f14ef10e48b4373c5a66c199e2860ef297dbd9e8 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Wed, 23 Nov 2016 06:22:50 -0500 Subject: Toggle save button depending on editor changes and return to editor instead of history pane after saving --- view/tpl/wiki.tpl | 71 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 30 deletions(-) (limited to 'view/tpl/wiki.tpl') diff --git a/view/tpl/wiki.tpl b/view/tpl/wiki.tpl index 6418871c6..94e7c0f3e 100644 --- a/view/tpl/wiki.tpl +++ b/view/tpl/wiki.tpl @@ -71,7 +71,7 @@ - Save + Save {{$commitMsg.3}} @@ -231,35 +231,38 @@ } $('#save-page').click(function (ev) { - if (window.wiki_resource_id === '' || window.wiki_page_name === '') { - window.console.log('You must have a wiki page open in order to edit pages.'); - ev.preventDefault(); - return false; - } - var currentContent = editor.getValue(); - if (window.wiki_page_content === currentContent) { - window.console.log('No edits to save.'); - ev.preventDefault(); - return false; - } - $.post("wiki/{{$channel}}/save/page", - { content: currentContent, - commitMsg: $('#id_commitMsg').val(), - name: window.wiki_page_name, - resource_id: window.wiki_resource_id - }, - function (data) { - if (data.success) { - window.console.log('Page saved successfully.'); - window.wiki_page_content = currentContent; - $('#id_commitMsg').val(''); // Clear the commit message box - $('#wiki-get-history').click(); - } else { - alert('Error saving page.'); // TODO: Replace alerts with auto-timeout popups - window.console.log('Error saving page.'); - } - }, 'json'); - ev.preventDefault(); + if (window.wiki_resource_id === '' || window.wiki_page_name === '') { + window.console.log('You must have a wiki page open in order to edit pages.'); + ev.preventDefault(); + return false; + } + var currentContent = editor.getValue(); + if (window.wiki_page_content === currentContent) { + window.console.log('No edits to save.'); + ev.preventDefault(); + return false; + } + $.post("wiki/{{$channel}}/save/page", + { content: currentContent, + commitMsg: $('#id_commitMsg').val(), + name: window.wiki_page_name, + resource_id: window.wiki_resource_id + }, + function (data) { + if (data.success) { + window.console.log('Page saved successfully.'); + window.wiki_page_content = currentContent; + $('#id_commitMsg').val(''); // Clear the commit message box + $('#save-page').addClass('disabled'); // Disable the save button + window.editor.getSession().getUndoManager().markClean(); // Reset the undo history for the editor + window.editor.focus(); // Return focus to the editor for continued editing + // $('#wiki-get-history').click(); + } else { + alert('Error saving page.'); // TODO: Replace alerts with auto-timeout popups + window.console.log('Error saving page.'); + } + }, 'json'); + ev.preventDefault(); }); $('#delete-page').click(function (ev) { @@ -460,6 +463,14 @@ {{else}} $('#new-wiki-button').hide(); {{/if}} + // using input event instead of change since it's called with some timeout + window.editor.on("input", function() { + if(window.editor.getSession().getUndoManager().isClean()) { + $('#save-page').addClass('disabled'); + } else { + $('#save-page').removeClass('disabled'); + } + }); }); -- cgit v1.2.3