allow disabling of confirmation in js delete

This commit is contained in:
mdipierro
2015-05-02 23:16:05 -05:00
parent 54b385b321
commit 8e3925820c
3 changed files with 54 additions and 48 deletions
+23 -21
View File
@@ -490,12 +490,12 @@
* 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.is('button') ? 'html' : 'val'; var method = el.is('input') ? 'val' : 'html';
//method = el.attr('name') ? '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) {
el.data('w2p:enable-with', el[method]()); el.data('w2p_enable_with', el[method]());
} }
/*if you don't want to see "working..." on buttons, replace the following /*if you don't want to see "working..." on buttons, replace the following
* two lines with this one * two lines with this one
@@ -515,11 +515,11 @@
/* 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.is('button') ? 'val' : 'html'; var method = el.is('input') ? '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'));
el.removeData('w2p:enable-with'); el.removeData('w2p_enable_with');
} }
el.removeClass('disabled'); el.removeClass('disabled');
el.unbind('click.w2pDisable'); el.unbind('click.w2pDisable');
@@ -586,12 +586,14 @@
if(pre_call != undefined) { if(pre_call != undefined) {
eval(pre_call); eval(pre_call);
} }
if(confirm_message != undefined) { if(confirm_message) {
if(confirm_message == 'default') confirm_message = w2p_ajax_confirm_message || 'Are you sure you want to delete this object?'; if(confirm_message == 'default')
if(!web2py.confirm(confirm_message)) { confirm_message = w2p_ajax_confirm_message ||
web2py.stopEverything(e); 'Are you sure you want to delete this object?';
return; if(!web2py.confirm(confirm_message)) {
} web2py.stopEverything(e);
return;
}
} }
if(target == undefined) { if(target == undefined) {
if(method == 'GET') { if(method == 'GET') {
@@ -634,7 +636,7 @@
}); });
}, },
/* Disables form elements: /* Disables form elements:
- Caches element value in 'w2p: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
*/ */
@@ -646,8 +648,8 @@
if(disable_with == undefined) { if(disable_with == undefined) {
element.data('w2p_disable_with', element[method]()) element.data('w2p_disable_with', element[method]())
} }
if(element.data('w2p:enable-with') === undefined) { if(element.data('w2p_enable_with') === undefined) {
element.data('w2p:enable-with', element[method]()); element.data('w2p_enable_with', element[method]());
} }
element[method](element.data('w2p_disable_with')); element[method](element.data('w2p_disable_with'));
element.prop('disabled', true); element.prop('disabled', true);
@@ -655,16 +657,16 @@
}, },
/* Re-enables disabled form elements: /* Re-enables disabled form elements:
- Replaces element text with cached value from 'w2p: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) {
form.find(web2py.enableSelector).each(function() { form.find(web2py.enableSelector).each(function() {
var element = $(this), var element = $(this),
method = element.is('button') ? 'html' : 'val'; method = element.is('button') ? 'html' : 'val';
if(element.data('w2p:enable-with')) { if(element.data('w2p_enable_with')) {
element[method](element.data('w2p:enable-with')); element[method](element.data('w2p_enable_with'));
element.removeData('w2p:enable-with'); element.removeData('w2p_enable_with');
} }
element.prop('disabled', false); element.prop('disabled', false);
}); });
@@ -730,4 +732,4 @@ web2py_event_handlers = jQuery.web2py.event_handlers;
web2py_trap_link = jQuery.web2py.trap_link; web2py_trap_link = jQuery.web2py.trap_link;
web2py_calc_entropy = jQuery.web2py.calc_entropy; web2py_calc_entropy = jQuery.web2py.calc_entropy;
*/ */
/* compatibility code - end*/ /* compatibility code - end*/
+23 -21
View File
@@ -490,12 +490,12 @@
* 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.is('button') ? 'html' : 'val'; var method = el.is('input') ? 'val' : 'html';
//method = el.attr('name') ? '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) {
el.data('w2p:enable-with', el[method]()); el.data('w2p_enable_with', el[method]());
} }
/*if you don't want to see "working..." on buttons, replace the following /*if you don't want to see "working..." on buttons, replace the following
* two lines with this one * two lines with this one
@@ -515,11 +515,11 @@
/* 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.is('button') ? 'val' : 'html'; var method = el.is('input') ? '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'));
el.removeData('w2p:enable-with'); el.removeData('w2p_enable_with');
} }
el.removeClass('disabled'); el.removeClass('disabled');
el.unbind('click.w2pDisable'); el.unbind('click.w2pDisable');
@@ -586,12 +586,14 @@
if(pre_call != undefined) { if(pre_call != undefined) {
eval(pre_call); eval(pre_call);
} }
if(confirm_message != undefined) { if(confirm_message) {
if(confirm_message == 'default') confirm_message = w2p_ajax_confirm_message || 'Are you sure you want to delete this object?'; if(confirm_message == 'default')
if(!web2py.confirm(confirm_message)) { confirm_message = w2p_ajax_confirm_message ||
web2py.stopEverything(e); 'Are you sure you want to delete this object?';
return; if(!web2py.confirm(confirm_message)) {
} web2py.stopEverything(e);
return;
}
} }
if(target == undefined) { if(target == undefined) {
if(method == 'GET') { if(method == 'GET') {
@@ -634,7 +636,7 @@
}); });
}, },
/* Disables form elements: /* Disables form elements:
- Caches element value in 'w2p: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
*/ */
@@ -646,8 +648,8 @@
if(disable_with == undefined) { if(disable_with == undefined) {
element.data('w2p_disable_with', element[method]()) element.data('w2p_disable_with', element[method]())
} }
if(element.data('w2p:enable-with') === undefined) { if(element.data('w2p_enable_with') === undefined) {
element.data('w2p:enable-with', element[method]()); element.data('w2p_enable_with', element[method]());
} }
element[method](element.data('w2p_disable_with')); element[method](element.data('w2p_disable_with'));
element.prop('disabled', true); element.prop('disabled', true);
@@ -655,16 +657,16 @@
}, },
/* Re-enables disabled form elements: /* Re-enables disabled form elements:
- Replaces element text with cached value from 'w2p: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) {
form.find(web2py.enableSelector).each(function() { form.find(web2py.enableSelector).each(function() {
var element = $(this), var element = $(this),
method = element.is('button') ? 'html' : 'val'; method = element.is('button') ? 'html' : 'val';
if(element.data('w2p:enable-with')) { if(element.data('w2p_enable_with')) {
element[method](element.data('w2p:enable-with')); element[method](element.data('w2p_enable_with'));
element.removeData('w2p:enable-with'); element.removeData('w2p_enable_with');
} }
element.prop('disabled', false); element.prop('disabled', false);
}); });
@@ -730,4 +732,4 @@ web2py_event_handlers = jQuery.web2py.event_handlers;
web2py_trap_link = jQuery.web2py.trap_link; web2py_trap_link = jQuery.web2py.trap_link;
web2py_calc_entropy = jQuery.web2py.calc_entropy; web2py_calc_entropy = jQuery.web2py.calc_entropy;
*/ */
/* compatibility code - end*/ /* compatibility code - end*/
+8 -6
View File
@@ -586,12 +586,14 @@
if(pre_call != undefined) { if(pre_call != undefined) {
eval(pre_call); eval(pre_call);
} }
if(confirm_message != undefined) { if(confirm_message) {
if(confirm_message == 'default') confirm_message = w2p_ajax_confirm_message || 'Are you sure you want to delete this object?'; if(confirm_message == 'default')
if(!web2py.confirm(confirm_message)) { confirm_message = w2p_ajax_confirm_message ||
web2py.stopEverything(e); 'Are you sure you want to delete this object?';
return; if(!web2py.confirm(confirm_message)) {
} web2py.stopEverything(e);
return;
}
} }
if(target == undefined) { if(target == undefined) {
if(method == 'GET') { if(method == 'GET') {