streamlined the "working..." status handling and added an example

This commit is contained in:
niphlod
2013-09-07 15:34:03 +02:00
parent 31a5e28f9a
commit a6baead531
3 changed files with 18 additions and 9 deletions

View File

@@ -250,14 +250,13 @@
},
trap_form: function (action, target) {
/* traps any LOADed form */
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
$('#' + target + ' form').each(function (i) {
var form = $(this);
form.attr('data-w2p_target', target);
if(!form.hasClass('no_trap')) {
/* should be there by default */
form.find(web2py.formInputClickSelector).attr('data-w2p_disable_with', disable_with_message);
form.submit(function (e) {
web2py.disableElement(form.find(web2py.formInputClickSelector));
web2py.hide_flash();
web2py.ajax_page('post', action, form.serialize(), target, form);
e.preventDefault();
@@ -475,10 +474,14 @@
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
/*store enabled state*/
el.data('w2p:enable-with', el[method]());
/* little addition by default*/
/*if you don't want to see "working..." on buttons, replace the following
* two lines with this one
* el.data('w2p_disable_with', el[method]());
*/
if((el.data('w2p_disable_with') == 'default') || (el.data('w2p_disable_with') === undefined)) {
el.data('w2p_disable_with', disable_with_message);
}
/* set to disabled state*/
el[method](el.data('w2p_disable_with'));

View File

@@ -250,14 +250,13 @@
},
trap_form: function (action, target) {
/* traps any LOADed form */
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
$('#' + target + ' form').each(function (i) {
var form = $(this);
form.attr('data-w2p_target', target);
if(!form.hasClass('no_trap')) {
/* should be there by default */
form.find(web2py.formInputClickSelector).attr('data-w2p_disable_with', disable_with_message);
form.submit(function (e) {
web2py.disableElement(form.find(web2py.formInputClickSelector));
web2py.hide_flash();
web2py.ajax_page('post', action, form.serialize(), target, form);
e.preventDefault();
@@ -475,10 +474,14 @@
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
/*store enabled state*/
el.data('w2p:enable-with', el[method]());
/* little addition by default*/
/*if you don't want to see "working..." on buttons, replace the following
* two lines with this one
* el.data('w2p_disable_with', el[method]());
*/
if((el.data('w2p_disable_with') == 'default') || (el.data('w2p_disable_with') === undefined)) {
el.data('w2p_disable_with', disable_with_message);
}
/* set to disabled state*/
el[method](el.data('w2p_disable_with'));

View File

@@ -250,14 +250,13 @@
},
trap_form: function (action, target) {
/* traps any LOADed form */
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
$('#' + target + ' form').each(function (i) {
var form = $(this);
form.attr('data-w2p_target', target);
if(!form.hasClass('no_trap')) {
/* should be there by default */
form.find(web2py.formInputClickSelector).attr('data-w2p_disable_with', disable_with_message);
form.submit(function (e) {
web2py.disableElement(form.find(web2py.formInputClickSelector));
web2py.hide_flash();
web2py.ajax_page('post', action, form.serialize(), target, form);
e.preventDefault();
@@ -475,10 +474,14 @@
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
/*store enabled state*/
el.data('w2p:enable-with', el[method]());
/* little addition by default*/
/*if you don't want to see "working..." on buttons, replace the following
* two lines with this one
* el.data('w2p_disable_with', el[method]());
*/
if((el.data('w2p_disable_with') == 'default') || (el.data('w2p_disable_with') === undefined)) {
el.data('w2p_disable_with', disable_with_message);
}
/* set to disabled state*/
el[method](el.data('w2p_disable_with'));