From 17f39e02a0d2b7ceb565258861217fa7ba6bfbcf Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 8 May 2013 16:10:32 +0200 Subject: [PATCH] client_js.js: Funktionen in namespace kivi verschoben --- SL/ClientJS.pm | 8 ++++---- SL/Controller/Base.pm | 2 +- SL/Template/Plugin/L.pm | 6 +++--- js/client_js.js | 21 ++++++++++++--------- scripts/generate_client_js_actions.tpl | 19 +++++++++++-------- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/SL/ClientJS.pm b/SL/ClientJS.pm index a04702eb3..96132cfb3 100644 --- a/SL/ClientJS.pm +++ b/SL/ClientJS.pm @@ -14,7 +14,7 @@ use Rose::Object::MakeMethods::Generic my %supported_methods = ( # ## Non-jQuery methods ## - flash => 2, # display_flash(, ) + flash => 2, # kivi.display_flash(, ) # ## jQuery basics ## @@ -217,12 +217,12 @@ with jQuery First some JavaScript code: // In the client generate an AJAX request whose 'success' handler - // calls "eval_json_response(data)": + // calls "eval_json_result(data)": var data = { action: "SomeController/the_action", id: $('#some_input_field').val() }; - $.post("controller.pl", data, eval_json_response); + $.post("controller.pl", data, eval_json_result); Now some Perl code: @@ -278,7 +278,7 @@ There are three things that need to be done for this to work: =item 1. The "client_js.js" has to be loaded before the AJAX request is started. -=item 2. The client code needs to call C with the result returned from the server. +=item 2. The client code needs to call C with the result returned from the server. =item 3. The server must use this module. diff --git a/SL/Controller/Base.pm b/SL/Controller/Base.pm index 17a1d61d7..c6977d0e1 100644 --- a/SL/Controller/Base.pm +++ b/SL/Controller/Base.pm @@ -512,7 +512,7 @@ the current request is an AJAX request as determined by L. If it is a normal request then it outputs a standard HTTP redirect header (HTTP code 302). If it is an AJAX request then it outputs an AJAX response suitable for the -C function from the L module. +C function from the L module. =item C diff --git a/SL/Template/Plugin/L.pm b/SL/Template/Plugin/L.pm index d9deef78e..5ef07b75b 100644 --- a/SL/Template/Plugin/L.pm +++ b/SL/Template/Plugin/L.pm @@ -185,7 +185,7 @@ sub ajax_submit_tag { $url = _J($url); $form_selector = _J($form_selector); - my $onclick = qq|submit_ajax_form('${url}', '${form_selector}')|; + my $onclick = qq|kivi.submit_ajax_form('${url}', '${form_selector}')|; return $self->button_tag($onclick, $text, @slurp); } @@ -580,8 +580,8 @@ clicks the dialog's ok/yes button. Creates a HTML 'input type="button"' tag with a very specific onclick handler that submits the form given by the jQuery selector C<$form_selector> to the URL C<$url> (the actual JavaScript function -called for that is C in C). The -button's label will be C<$text>. +called for that is C in +C). The button's label will be C<$text>. =item C diff --git a/js/client_js.js b/js/client_js.js index abeac1b39..0477715a8 100644 --- a/js/client_js.js +++ b/js/client_js.js @@ -4,17 +4,18 @@ // "scripts/generate_client_js_actions.pl". See the documentation for // SL/ClientJS.pm for instructions. -function display_flash(type, message) { +namespace("kivi", function(ns) { +ns.display_flash = function(type, message) { $('#flash_' + type + '_content').text(message); $('#flash_' + type).show(); -} +}; -function eval_json_result(data) { +ns.eval_json_result = function(data) { if (!data) return; if (data.error) - return display_flash('error', data.error); + return ns.display_flash('error', data.error); $(['info', 'warning', 'error']).each(function(idx, category) { $('#flash_' + category).hide(); @@ -29,7 +30,7 @@ function eval_json_result(data) { // console.log("ACTION " + action[0] + " ON " + action[1]); // ## Non-jQuery methods ## - if (action[0] == 'flash') display_flash(action[1], action[2]); + if (action[0] == 'flash') kivi.display_flash(action[1], action[2]); // ## jQuery basics ## @@ -124,13 +125,15 @@ 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) { +ns.submit_ajax_form = function(url, form_selector, additional_data) { var separator = /\?/.test(url) ? '&' : '?'; - $.post(url + separator + $(form_selector).serialize(), additional_data, eval_json_result); + $.post(url + separator + $(form_selector).serialize(), additional_data, ns.eval_json_result); return true; -} +}; + +}); // Local Variables: // mode: js diff --git a/scripts/generate_client_js_actions.tpl b/scripts/generate_client_js_actions.tpl index 46032667f..6772cd102 100644 --- a/scripts/generate_client_js_actions.tpl +++ b/scripts/generate_client_js_actions.tpl @@ -4,17 +4,18 @@ // "scripts/generate_client_js_actions.pl". See the documentation for // SL/ClientJS.pm for instructions. -function display_flash(type, message) { +namespace("kivi", function(ns) { +ns.display_flash = function(type, message) { $('#flash_' + type + '_content').text(message); $('#flash_' + type).show(); -} +}; -function eval_json_result(data) { +ns.eval_json_result = function(data) { if (!data) return; if (data.error) - return display_flash('error', data.error); + return ns.display_flash('error', data.error); $(['info', 'warning', 'error']).each(function(idx, category) { $('#flash_' + category).hide(); @@ -32,13 +33,15 @@ 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) { +ns.submit_ajax_form = function(url, form_selector, additional_data) { var separator = /\?/.test(url) ? '&' : '?'; - $.post(url + separator + $(form_selector).serialize(), additional_data, eval_json_result); + $.post(url + separator + $(form_selector).serialize(), additional_data, ns.eval_json_result); return true; -} +}; + +}); // Local Variables: // mode: js -- 2.20.1