diff --git a/app/assets/javascripts/my_modules/protocols.js.erb b/app/assets/javascripts/my_modules/protocols.js.erb index cf01d5b39..e4bd3fa4c 100644 --- a/app/assets/javascripts/my_modules/protocols.js.erb +++ b/app/assets/javascripts/my_modules/protocols.js.erb @@ -27,7 +27,7 @@ function initEditMyModuleDescription() { function initEditProtocolDescription() { $('#protocol_description_view').on('click', function(){ - TinyMCE.init('#protocol_description_textarea'); + TinyMCE.init('#protocol_description_textarea', refreshProtocolStatusBar); }); } @@ -385,27 +385,33 @@ function loadFromRepository() { } function initRefreshStatusBar() { - $("[data-role='steps-container']") - .on( - "ajax:success", - function(e, data) { - if ($(e.target).is("[data-role='edit-step-form'], [data-role='new-step-form']")) { - // Get the status bar URL - var url = $("[data-role='protocol-status-bar-url']").attr("data-url"); + // The following actions need a refresh of status bar: + // - Edit protocol description + // - Create new step + // - Edit existing step + // - Move steps up/down + // - Delete step + // - New Office file + // - Edit image + // - Office Online edit file (???) - // Fetch new updated at label - $.ajax({ - url: url, - type: "GET", - dataType: "json", - success: function (data2) { - $("[data-role='protocol-status-bar']").html(data2.html); - initLinkUpdate(); - } - }); - } + // TODO - this function will probably become reduntant +} + +function refreshProtocolStatusBar() { + // Get the status bar URL + var url = $("[data-role='protocol-status-bar-url']").attr("data-url"); + + // Fetch new updated at label + $.ajax({ + url: url, + type: "GET", + dataType: "json", + success: function (data) { + $("[data-role='protocol-status-bar']").html(data.html); + initLinkUpdate(); } - ); + }); } function initImport() { diff --git a/app/assets/javascripts/sitewide/tiny_mce.js b/app/assets/javascripts/sitewide/tiny_mce.js index a86c10a8d..f09dcda60 100644 --- a/app/assets/javascripts/sitewide/tiny_mce.js +++ b/app/assets/javascripts/sitewide/tiny_mce.js @@ -18,7 +18,7 @@ var TinyMCE = (function() { // returns a public API for TinyMCE editor return Object.freeze({ - init: function(selector, mceConfig = {}) { + init: function(selector, onSaveCallback) { var tinyMceContainer; var tinyMceInitSize; if (typeof tinyMCE !== 'undefined') { @@ -164,6 +164,7 @@ var TinyMCE = (function() { editorForm.find('.tinymce-status-badge').removeClass('hidden'); editor.remove(); editorForm.find('.tinymce-view').html(data.html).removeClass('hidden'); + if (onSaveCallback) { onSaveCallback(); } }).on('ajax:error', function(ev, data) { var model = editor.getElement().dataset.objectType; $(this).renderFormErrors(model, data.responseJSON);