client_js.js: Funktionen in namespace kivi verschoben
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 8 May 2013 14:10:32 +0000 (16:10 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 8 May 2013 14:11:44 +0000 (16:11 +0200)
SL/ClientJS.pm
SL/Controller/Base.pm
SL/Template/Plugin/L.pm
js/client_js.js
scripts/generate_client_js_actions.tpl

index a04702e..96132cf 100644 (file)
@@ -14,7 +14,7 @@ use Rose::Object::MakeMethods::Generic
 
 my %supported_methods = (
   # ## Non-jQuery methods ##
-  flash        => 2,            # display_flash(<TARGET>, <ARGS>)
+  flash        => 2,            # kivi.display_flash(<TARGET>, <ARGS>)
 
   # ## 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<eval_json_response()> with the result returned from the server.
+=item 2. The client code needs to call C<kivi.eval_json_result()> with the result returned from the server.
 
 =item 3. The server must use this module.
 
index 17a1d61..c6977d0 100644 (file)
@@ -512,7 +512,7 @@ the current request is an AJAX request as determined by
 L<SL::Request/is_ajax>. 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<eval_json_result> function from the L<SL::ClientJS> module.
+C<kivi.eval_json_result> function from the L<SL::ClientJS> module.
 
 =item C<run_before $sub, %params>
 
index d9deef7..5ef07b7 100644 (file)
@@ -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<submit_ajax_form()> in C<js/client_js.js>). The
-button's label will be C<$text>.
+called for that is C<kivi.submit_ajax_form()> in
+C<js/client_js.js>). The button's label will be C<$text>.
 
 =item C<button_tag $onclick, $text, %attributes>
 
index abeac1b..0477715 100644 (file)
@@ -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
index 4603266..6772cd1 100644 (file)
@@ -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