redirect(...) now works on ajax responses, thanks Anthony
This commit is contained in:
@@ -1 +1 @@
|
||||
Version 2.00.0 (2012-08-08 09:43:04) dev
|
||||
Version 2.00.0 (2012-08-08 10:05:06) dev
|
||||
|
||||
@@ -44,6 +44,12 @@ function web2py_event_handlers() {
|
||||
doc.on('keyup', 'input.double, input.decimal', function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[\.,](?=[0-9]*[\.,])/g,'').reverse();});
|
||||
var confirm_message = (typeof w2p_ajax_confirm_message != 'undefined') ? w2p_ajax_confirm_message : "Are you sure you want to delete this object?";
|
||||
doc.on('click', "input[type='checkbox'].delete", function(){if(this.checked) if(!confirm(confirm_message)) this.checked=false;});
|
||||
doc.ajaxSuccess(function(e, xhr) {
|
||||
var redirect=xhr.getResponseHeader('web2py-redirect-location');
|
||||
if (redirect != null) {
|
||||
window.location = redirect;
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
jQuery(function() {
|
||||
|
||||
@@ -44,6 +44,12 @@ function web2py_event_handlers() {
|
||||
doc.on('keyup', 'input.double, input.decimal', function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[\.,](?=[0-9]*[\.,])/g,'').reverse();});
|
||||
var confirm_message = (typeof w2p_ajax_confirm_message != 'undefined') ? w2p_ajax_confirm_message : "Are you sure you want to delete this object?";
|
||||
doc.on('click', "input[type='checkbox'].delete", function(){if(this.checked) if(!confirm(confirm_message)) this.checked=false;});
|
||||
doc.ajaxSuccess(function(e, xhr) {
|
||||
var redirect=xhr.getResponseHeader('web2py-redirect-location');
|
||||
if (redirect != null) {
|
||||
window.location = redirect;
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
jQuery(function() {
|
||||
|
||||
@@ -44,6 +44,12 @@ function web2py_event_handlers() {
|
||||
doc.on('keyup', 'input.double, input.decimal', function(){this.value=this.value.reverse().replace(/[^0-9\-\.,]|[\-](?=.)|[\.,](?=[0-9]*[\.,])/g,'').reverse();});
|
||||
var confirm_message = (typeof w2p_ajax_confirm_message != 'undefined') ? w2p_ajax_confirm_message : "Are you sure you want to delete this object?";
|
||||
doc.on('click', "input[type='checkbox'].delete", function(){if(this.checked) if(!confirm(confirm_message)) this.checked=false;});
|
||||
doc.ajaxSuccess(function(e, xhr) {
|
||||
var redirect=xhr.getResponseHeader('web2py-redirect-location');
|
||||
if (redirect != null) {
|
||||
window.location = redirect;
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
jQuery(function() {
|
||||
|
||||
+9
-4
@@ -119,13 +119,18 @@ class HTTP(BaseException):
|
||||
return self.message
|
||||
|
||||
|
||||
def redirect(location, how=303):
|
||||
def redirect(location, how=303, type=None):
|
||||
from gluon import current
|
||||
type = type or ('client' if current.request.ajax else 'http')
|
||||
if not location:
|
||||
return
|
||||
location = location.replace('\r', '%0D').replace('\n', '%0A')
|
||||
raise HTTP(how,
|
||||
'You are being redirected <a href="%s">here</a>' % location,
|
||||
Location=location)
|
||||
if type == 'client':
|
||||
raise HTTP(200, **{'web2py-redirect-location': location})
|
||||
else:
|
||||
raise HTTP(how,
|
||||
'You are being redirected <a href="%s">here</a>' % location,
|
||||
Location=location)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user