From 2738c03e1340255baade2fd357aafbbfd1347d5e Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 13 Mar 2013 15:31:11 +0100 Subject: [PATCH] =?utf8?q?ClientJS:=20Unterst=C3=BCtzung=20f=C3=BCr=20Brow?= =?utf8?q?ser-Redirects=20("$js->redirect=5Fto")?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/ClientJS.pm | 11 +++++++++++ js/client_js.js | 9 +++++++++ scripts/generate_client_js_actions.tpl | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index 1218e4cc5..d58905e75 100644 --- a/SL/ClientJS.pm +++ b/SL/ClientJS.pm @@ -95,6 +95,9 @@ my %supported_methods = ( 'jstree:select_node' => 2, # $.jstree._reference($()).(, true) 'jstree:deselect_node' => 2, 'jstree:deselect_all' => 1, + + # ## other stuff ## + redirect_to => 1, # window.location.href = ); sub AUTOLOAD { @@ -401,6 +404,14 @@ client will then show the message in the 'error' flash. The messages of multiple calls of C on the same C<$self> will be merged. +=item C + +Redirects the browser window to the new URL by setting the JavaScript +property C. Note that +L is AJAX aware and uses this +function if the current request is an AJAX request as determined by +L. + =back =head2 JQUERY FUNCTIONS diff --git a/js/client_js.js b/js/client_js.js index b961f6591..11ef823e1 100644 --- a/js/client_js.js +++ b/js/client_js.js @@ -109,6 +109,9 @@ function eval_json_result(data) { else if (action[0] == 'jstree:deselect_node') $.jstree._reference($(action[1])).deselect_node(action[2]); else if (action[0] == 'jstree:deselect_all') $.jstree._reference($(action[1])).deselect_all(); + // ## other stuff ## + else if (action[0] == 'redirect_to') window.location.href = action[1]; + else console.log('Unknown action: ' + action[0]); }); @@ -116,6 +119,12 @@ function eval_json_result(data) { // console.log("current_content_type " + $('#current_content_type').val() + ' ID ' + $('#current_content_id').val()); } +function submit_ajax_form(url, form_selector, additional_data) { + var separator = /\?/.test(url) ? '&' : '?'; + $.post(url + separator + $(form_selector).serialize(), additional_data, eval_json_result); + return true; +} + // Local Variables: // mode: js // End: diff --git a/scripts/generate_client_js_actions.tpl b/scripts/generate_client_js_actions.tpl index 7fa7baf95..55206ea6a 100644 --- a/scripts/generate_client_js_actions.tpl +++ b/scripts/generate_client_js_actions.tpl @@ -32,6 +32,12 @@ function eval_json_result(data) { // console.log("current_content_type " + $('#current_content_type').val() + ' ID ' + $('#current_content_id').val()); } +function submit_ajax_form(url, form_selector, additional_data) { + var separator = /\?/.test(url) ? '&' : '?'; + $.post(url + separator + $(form_selector).serialize(), additional_data, eval_json_result); + return true; +} + // Local Variables: // mode: js // End: -- 2.20.1