This commit is contained in:
pallav_fdsi
2014-11-11 00:21:27 -05:00
3 changed files with 1992 additions and 1980 deletions
+17 -13
View File
@@ -250,7 +250,6 @@
}); });
}, },
trap_form: function(action, target) { trap_form: function(action, target) {
/* traps any LOADed form */ /* traps any LOADed form */
$('#' + target + ' form').each(function(i) { $('#' + target + ' form').each(function(i) {
@@ -258,25 +257,29 @@
if(form.hasClass('no_trap')) { if(form.hasClass('no_trap')) {
return; return;
} }
form.attr('data-w2p_target', target); form.attr('data-w2p_target', target);
var url = form.attr('action'); var url = form.attr('action');
if((url === "") || (url === "#") || (typeof url === 'undefined')) { if((url === "") || (url === "#") || (typeof url === 'undefined')) {
/* form has no action. Use component url. */ /* form has no action. Use component url. */
url = action; url = action;
} }
form.submit(function(e) { form.submit(function(e) {
web2py.disableElement(form.find(web2py.formInputClickSelector)); web2py.disableElement(form.find(web2py.formInputClickSelector));
web2py.hide_flash(); web2py.hide_flash();
web2py.ajax_page('post', url, form.serialize(), target, form); web2py.ajax_page('post', url, form.serialize(), target, form);
e.preventDefault(); e.preventDefault();
}); });
form.on('click', web2py.formInputClickSelector, function(e) {
e.preventDefault();
var input_name = $(this).attr('name');
if(input_name != undefined) {
$('<input type="hidden" />').attr('name', input_name)
.attr('value', $(this).val()).appendTo(form)
}
form.trigger('submit');
});
}); });
}, },
ajax_page: function(method, action, data, target, element) { ajax_page: function(method, action, data, target, element) {
/* element is a new parameter, but should be put be put in front */ /* element is a new parameter, but should be put be put in front */
if(element == undefined) element = $(document); if(element == undefined) element = $(document);
@@ -461,7 +464,7 @@
}, },
/* new from here */ /* new from here */
/* Form input elements bound by web2py.js */ /* Form input elements bound by web2py.js */
formInputClickSelector: 'input[type=submit]:not([name]), input[type=image]:not([name]), button[type=submit]:not([name]), button:not([type]):not([name])', formInputClickSelector: 'input[type=submit], input[type=image], button[type=submit], button:not([type])',
/* Form input elements disabled during form submission */ /* Form input elements disabled during form submission */
disableSelector: 'input, button, textarea, select', disableSelector: 'input, button, textarea, select',
/* Form input elements re-enabled after form submission */ /* Form input elements re-enabled after form submission */
@@ -487,7 +490,8 @@
* and prevent clicking on it */ * and prevent clicking on it */
disableElement: function(el) { disableElement: function(el) {
el.addClass('disabled'); el.addClass('disabled');
var method = el.prop('type') == 'submit' ? 'val' : 'html'; var method = el.is('button') ? 'html' : 'val';
//method = el.attr('name') ? 'html' : 'val';
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working..."; var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
/*store enabled state if not already disabled */ /*store enabled state if not already disabled */
if(el.data('w2p:enable-with') === undefined) { if(el.data('w2p:enable-with') === undefined) {
@@ -511,7 +515,7 @@
/* restore element to its original state which was disabled by 'disableElement' above*/ /* restore element to its original state which was disabled by 'disableElement' above*/
enableElement: function(el) { enableElement: function(el) {
var method = el.prop('type') == 'submit' ? 'val' : 'html'; var method = el.is('button') ? 'val' : 'html';
if(el.data('w2p:enable-with') !== undefined) { if(el.data('w2p:enable-with') !== undefined) {
/* set to old enabled state */ /* set to old enabled state */
el[method](el.data('w2p:enable-with')); el[method](el.data('w2p:enable-with'));
@@ -630,7 +634,7 @@
}); });
}, },
/* Disables form elements: /* Disables form elements:
- Caches element value in 'ujs:enable-with' data store - Caches element value in 'w2p:enable-with' data store
- Replaces element text with value of 'data-disable-with' attribute - Replaces element text with value of 'data-disable-with' attribute
- Sets disabled property to true - Sets disabled property to true
*/ */
@@ -651,7 +655,7 @@
}, },
/* Re-enables disabled form elements: /* Re-enables disabled form elements:
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) - Replaces element text with cached value from 'w2p:enable-with' data store (created in `disableFormElements`)
- Sets disabled property to false - Sets disabled property to false
*/ */
enableFormElements: function(form) { enableFormElements: function(form) {
@@ -685,7 +689,7 @@
}); });
$.web2py.component_handler(target); $.web2py.component_handler(target);
}, },
main_hook : function() { main_hook: function() {
var flash = $('.flash'); var flash = $('.flash');
flash.hide(); flash.hide();
if(flash.html()) web2py.flash(flash.html()); if(flash.html()) web2py.flash(flash.html());
@@ -697,7 +701,7 @@
} }
/*end of functions */ /*end of functions */
/*main hook*/ /*main hook*/
$(function () { $(function() {
web2py.main_hook(); web2py.main_hook();
}); });
+17 -13
View File
@@ -250,7 +250,6 @@
}); });
}, },
trap_form: function(action, target) { trap_form: function(action, target) {
/* traps any LOADed form */ /* traps any LOADed form */
$('#' + target + ' form').each(function(i) { $('#' + target + ' form').each(function(i) {
@@ -258,25 +257,29 @@
if(form.hasClass('no_trap')) { if(form.hasClass('no_trap')) {
return; return;
} }
form.attr('data-w2p_target', target); form.attr('data-w2p_target', target);
var url = form.attr('action'); var url = form.attr('action');
if((url === "") || (url === "#") || (typeof url === 'undefined')) { if((url === "") || (url === "#") || (typeof url === 'undefined')) {
/* form has no action. Use component url. */ /* form has no action. Use component url. */
url = action; url = action;
} }
form.submit(function(e) { form.submit(function(e) {
web2py.disableElement(form.find(web2py.formInputClickSelector)); web2py.disableElement(form.find(web2py.formInputClickSelector));
web2py.hide_flash(); web2py.hide_flash();
web2py.ajax_page('post', url, form.serialize(), target, form); web2py.ajax_page('post', url, form.serialize(), target, form);
e.preventDefault(); e.preventDefault();
}); });
form.on('click', web2py.formInputClickSelector, function(e) {
e.preventDefault();
var input_name = $(this).attr('name');
if(input_name != undefined) {
$('<input type="hidden" />').attr('name', input_name)
.attr('value', $(this).val()).appendTo(form)
}
form.trigger('submit');
});
}); });
}, },
ajax_page: function(method, action, data, target, element) { ajax_page: function(method, action, data, target, element) {
/* element is a new parameter, but should be put be put in front */ /* element is a new parameter, but should be put be put in front */
if(element == undefined) element = $(document); if(element == undefined) element = $(document);
@@ -461,7 +464,7 @@
}, },
/* new from here */ /* new from here */
/* Form input elements bound by web2py.js */ /* Form input elements bound by web2py.js */
formInputClickSelector: 'input[type=submit]:not([name]), input[type=image]:not([name]), button[type=submit]:not([name]), button:not([type]):not([name])', formInputClickSelector: 'input[type=submit], input[type=image], button[type=submit], button:not([type])',
/* Form input elements disabled during form submission */ /* Form input elements disabled during form submission */
disableSelector: 'input, button, textarea, select', disableSelector: 'input, button, textarea, select',
/* Form input elements re-enabled after form submission */ /* Form input elements re-enabled after form submission */
@@ -487,7 +490,8 @@
* and prevent clicking on it */ * and prevent clicking on it */
disableElement: function(el) { disableElement: function(el) {
el.addClass('disabled'); el.addClass('disabled');
var method = el.prop('type') == 'submit' ? 'val' : 'html'; var method = el.is('button') ? 'html' : 'val';
//method = el.attr('name') ? 'html' : 'val';
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working..."; var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
/*store enabled state if not already disabled */ /*store enabled state if not already disabled */
if(el.data('w2p:enable-with') === undefined) { if(el.data('w2p:enable-with') === undefined) {
@@ -511,7 +515,7 @@
/* restore element to its original state which was disabled by 'disableElement' above*/ /* restore element to its original state which was disabled by 'disableElement' above*/
enableElement: function(el) { enableElement: function(el) {
var method = el.prop('type') == 'submit' ? 'val' : 'html'; var method = el.is('button') ? 'val' : 'html';
if(el.data('w2p:enable-with') !== undefined) { if(el.data('w2p:enable-with') !== undefined) {
/* set to old enabled state */ /* set to old enabled state */
el[method](el.data('w2p:enable-with')); el[method](el.data('w2p:enable-with'));
@@ -630,7 +634,7 @@
}); });
}, },
/* Disables form elements: /* Disables form elements:
- Caches element value in 'ujs:enable-with' data store - Caches element value in 'w2p:enable-with' data store
- Replaces element text with value of 'data-disable-with' attribute - Replaces element text with value of 'data-disable-with' attribute
- Sets disabled property to true - Sets disabled property to true
*/ */
@@ -651,7 +655,7 @@
}, },
/* Re-enables disabled form elements: /* Re-enables disabled form elements:
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) - Replaces element text with cached value from 'w2p:enable-with' data store (created in `disableFormElements`)
- Sets disabled property to false - Sets disabled property to false
*/ */
enableFormElements: function(form) { enableFormElements: function(form) {
@@ -685,7 +689,7 @@
}); });
$.web2py.component_handler(target); $.web2py.component_handler(target);
}, },
main_hook : function() { main_hook: function() {
var flash = $('.flash'); var flash = $('.flash');
flash.hide(); flash.hide();
if(flash.html()) web2py.flash(flash.html()); if(flash.html()) web2py.flash(flash.html());
@@ -697,7 +701,7 @@
} }
/*end of functions */ /*end of functions */
/*main hook*/ /*main hook*/
$(function () { $(function() {
web2py.main_hook(); web2py.main_hook();
}); });
+17 -13
View File
@@ -250,7 +250,6 @@
}); });
}, },
trap_form: function(action, target) { trap_form: function(action, target) {
/* traps any LOADed form */ /* traps any LOADed form */
$('#' + target + ' form').each(function(i) { $('#' + target + ' form').each(function(i) {
@@ -258,25 +257,29 @@
if(form.hasClass('no_trap')) { if(form.hasClass('no_trap')) {
return; return;
} }
form.attr('data-w2p_target', target); form.attr('data-w2p_target', target);
var url = form.attr('action'); var url = form.attr('action');
if((url === "") || (url === "#") || (typeof url === 'undefined')) { if((url === "") || (url === "#") || (typeof url === 'undefined')) {
/* form has no action. Use component url. */ /* form has no action. Use component url. */
url = action; url = action;
} }
form.submit(function(e) { form.submit(function(e) {
web2py.disableElement(form.find(web2py.formInputClickSelector)); web2py.disableElement(form.find(web2py.formInputClickSelector));
web2py.hide_flash(); web2py.hide_flash();
web2py.ajax_page('post', url, form.serialize(), target, form); web2py.ajax_page('post', url, form.serialize(), target, form);
e.preventDefault(); e.preventDefault();
}); });
form.on('click', web2py.formInputClickSelector, function(e) {
e.preventDefault();
var input_name = $(this).attr('name');
if(input_name != undefined) {
$('<input type="hidden" />').attr('name', input_name)
.attr('value', $(this).val()).appendTo(form)
}
form.trigger('submit');
});
}); });
}, },
ajax_page: function(method, action, data, target, element) { ajax_page: function(method, action, data, target, element) {
/* element is a new parameter, but should be put be put in front */ /* element is a new parameter, but should be put be put in front */
if(element == undefined) element = $(document); if(element == undefined) element = $(document);
@@ -461,7 +464,7 @@
}, },
/* new from here */ /* new from here */
/* Form input elements bound by web2py.js */ /* Form input elements bound by web2py.js */
formInputClickSelector: 'input[type=submit]:not([name]), input[type=image]:not([name]), button[type=submit]:not([name]), button:not([type]):not([name])', formInputClickSelector: 'input[type=submit], input[type=image], button[type=submit], button:not([type])',
/* Form input elements disabled during form submission */ /* Form input elements disabled during form submission */
disableSelector: 'input, button, textarea, select', disableSelector: 'input, button, textarea, select',
/* Form input elements re-enabled after form submission */ /* Form input elements re-enabled after form submission */
@@ -487,7 +490,8 @@
* and prevent clicking on it */ * and prevent clicking on it */
disableElement: function(el) { disableElement: function(el) {
el.addClass('disabled'); el.addClass('disabled');
var method = el.prop('type') == 'submit' ? 'val' : 'html'; var method = el.is('button') ? 'html' : 'val';
//method = el.attr('name') ? 'html' : 'val';
var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working..."; var disable_with_message = (typeof w2p_ajax_disable_with_message != 'undefined') ? w2p_ajax_disable_with_message : "Working...";
/*store enabled state if not already disabled */ /*store enabled state if not already disabled */
if(el.data('w2p:enable-with') === undefined) { if(el.data('w2p:enable-with') === undefined) {
@@ -511,7 +515,7 @@
/* restore element to its original state which was disabled by 'disableElement' above*/ /* restore element to its original state which was disabled by 'disableElement' above*/
enableElement: function(el) { enableElement: function(el) {
var method = el.prop('type') == 'submit' ? 'val' : 'html'; var method = el.is('button') ? 'val' : 'html';
if(el.data('w2p:enable-with') !== undefined) { if(el.data('w2p:enable-with') !== undefined) {
/* set to old enabled state */ /* set to old enabled state */
el[method](el.data('w2p:enable-with')); el[method](el.data('w2p:enable-with'));
@@ -630,7 +634,7 @@
}); });
}, },
/* Disables form elements: /* Disables form elements:
- Caches element value in 'ujs:enable-with' data store - Caches element value in 'w2p:enable-with' data store
- Replaces element text with value of 'data-disable-with' attribute - Replaces element text with value of 'data-disable-with' attribute
- Sets disabled property to true - Sets disabled property to true
*/ */
@@ -651,7 +655,7 @@
}, },
/* Re-enables disabled form elements: /* Re-enables disabled form elements:
- Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`) - Replaces element text with cached value from 'w2p:enable-with' data store (created in `disableFormElements`)
- Sets disabled property to false - Sets disabled property to false
*/ */
enableFormElements: function(form) { enableFormElements: function(form) {
@@ -685,7 +689,7 @@
}); });
$.web2py.component_handler(target); $.web2py.component_handler(target);
}, },
main_hook : function() { main_hook: function() {
var flash = $('.flash'); var flash = $('.flash');
flash.hide(); flash.hide();
if(flash.html()) web2py.flash(flash.html()); if(flash.html()) web2py.flash(flash.html());
@@ -697,7 +701,7 @@
} }
/*end of functions */ /*end of functions */
/*main hook*/ /*main hook*/
$(function () { $(function() {
web2py.main_hook(); web2py.main_hook();
}); });