my %supported_methods = (
# ## Non-jQuery methods ##
- flash => 2, # display_flash(<TARGET>, <ARGS>)
+ flash => 2, # kivi.display_flash(<TARGET>, <ARGS>)
# ## jQuery basics ##
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:
=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.
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>
$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);
}
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>
// "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();
// 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 ##
});
// 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
// "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();
});
// 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