From: Moritz Bunkus Date: Wed, 13 Mar 2013 14:31:11 +0000 (+0100) Subject: ClientJS: Unterstützung für Browser-Redirects ("$js->redirect_to") X-Git-Tag: release-3.1.0beta1~521 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=2738c03e1340255baade2fd357aafbbfd1347d5e;p=kivitendo-erp.git ClientJS: Unterstützung für Browser-Redirects ("$js->redirect_to") --- 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: