From a6baead5319852b6ff7d4030b644c96e948ac61b Mon Sep 17 00:00:00 2001 From: niphlod Date: Sat, 7 Sep 2013 15:34:03 +0200 Subject: [PATCH] streamlined the "working..." status handling and added an example --- applications/admin/static/js/web2py.js | 9 ++++++--- applications/examples/static/js/web2py.js | 9 ++++++--- applications/welcome/static/js/web2py.js | 9 ++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/applications/admin/static/js/web2py.js b/applications/admin/static/js/web2py.js index 42561994..0c171be3 100644 --- a/applications/admin/static/js/web2py.js +++ b/applications/admin/static/js/web2py.js @@ -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')); diff --git a/applications/examples/static/js/web2py.js b/applications/examples/static/js/web2py.js index 42561994..0c171be3 100644 --- a/applications/examples/static/js/web2py.js +++ b/applications/examples/static/js/web2py.js @@ -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')); diff --git a/applications/welcome/static/js/web2py.js b/applications/welcome/static/js/web2py.js index 42561994..0c171be3 100644 --- a/applications/welcome/static/js/web2py.js +++ b/applications/welcome/static/js/web2py.js @@ -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'));