From ee37adbc8713cdfb2490d997c651d2316a5d2461 Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Tue, 6 Mar 2012 18:19:19 +1300 Subject: [PATCH] ENHANCEMENT: SSF-33 Binding the 'cms-link-ajax' class to a javascript function that triggers a CMS ajax method and displays a status message --- admin/javascript/LeftAndMain.Content.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/admin/javascript/LeftAndMain.Content.js b/admin/javascript/LeftAndMain.Content.js index 32a9cb426..4c125b839 100644 --- a/admin/javascript/LeftAndMain.Content.js +++ b/admin/javascript/LeftAndMain.Content.js @@ -313,4 +313,26 @@ } }); + /** + * Does an ajax loads of the link's 'href' attribute via ajax and displays any FormResponse messages from the CMS. + * Little helper to avoid repetition, and make it easy to trigger actions via a link, + * without reloading the page, changing the URL, or loading in any new panel content. + */ + $('.cms-content .cms-link-ajax').entwine({ + onclick: function(e) { + var href = this.attr('href'), url = href ? href : this.data('href'); + + jQuery.ajax({ + url: url, + // Ensure that form view is loaded (rather than whole "Content" template) + complete: function(xmlhttp, status) { + var msg = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.responseText; + if (typeof msg != "undefined" && msg != null) eval(msg); + }, + dataType: 'html' + }); + e.preventDefault(); + } + }); + })(jQuery); \ No newline at end of file