mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Simple hack to catch redirections after an ajax request. It is not a clean and perfect solution but it should address most cases.
fix #181
This commit is contained in:
@@ -30,7 +30,7 @@ function actioncallback(resp) {
|
||||
}
|
||||
|
||||
function actionclick(evt) {
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url: evt.target.get("href"),
|
||||
onSuccess: actioncallback
|
||||
}).get();
|
||||
|
||||
@@ -14,7 +14,7 @@ function removefilter(evt) {
|
||||
if (!confirm(gettext("Remove this filter?"))) {
|
||||
return;
|
||||
}
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url: this.get("href"),
|
||||
onSuccess: function(response) {
|
||||
if (response.status == "ok") {
|
||||
@@ -72,7 +72,7 @@ function loadfs(response) {
|
||||
* (remove, activate)
|
||||
*/
|
||||
function send_command(cmd, extracb) {
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url: cmd,
|
||||
onSuccess: function(response) {
|
||||
if (response.status == "ko") {
|
||||
@@ -116,7 +116,7 @@ function savefs(evt) {
|
||||
if (!check_prereqs(evt, gettext("Save changes?"))) {
|
||||
return;
|
||||
}
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url: $("feditor").get("action"),
|
||||
method: $("feditor").get("method"),
|
||||
data: $("feditor").toQueryString(),
|
||||
@@ -177,7 +177,7 @@ function activatefs(evt) {
|
||||
|
||||
function toggle_filter_state(event) {
|
||||
event.stop();
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url: this.get("href"),
|
||||
onSuccess: function(response) {
|
||||
if (response.status == "ok") {
|
||||
@@ -193,7 +193,7 @@ function toggle_filter_state(event) {
|
||||
|
||||
function move_filter(event) {
|
||||
event.stop();
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url: this.get("href"),
|
||||
onSuccess: function(response) {
|
||||
$("filters_list").set("html", response.content);
|
||||
|
||||
@@ -68,8 +68,8 @@ window.addEvent("domready", function() {
|
||||
if (p == "") {
|
||||
return;
|
||||
}
|
||||
new Request.JSON({url : url + "?" + p, noCache: true,
|
||||
onSuccess : getgraph_callback}).get();
|
||||
new Request.JSON.mdb({url : url + "?" + p, noCache: true,
|
||||
onSuccess : getgraph_callback}).get();
|
||||
};
|
||||
|
||||
{% if user.is_superuser %}
|
||||
|
||||
@@ -691,6 +691,9 @@ def html2plaintext(content):
|
||||
return plaintext
|
||||
|
||||
def get_current_url(request):
|
||||
if not request.session.has_key("folder"):
|
||||
return ""
|
||||
|
||||
res = "%s?page=%s" % (request.session["folder"], request.session["page"])
|
||||
for p in ["criteria", "pattern", "order"]:
|
||||
if p in request.session.keys():
|
||||
|
||||
@@ -46,7 +46,7 @@ var FdMenu = new Class({
|
||||
if (!confirm(gettext("Delete folder?"))) {
|
||||
return;
|
||||
}
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url: evt.target.get("href"),
|
||||
method: "GET",
|
||||
onSuccess: function(resp) {
|
||||
|
||||
@@ -219,13 +219,17 @@ function refreshFolder() {
|
||||
profile : "gray",
|
||||
spinner : true
|
||||
});
|
||||
new Request.JSON({url: query, noCache : true, onSuccess: function(resp) {
|
||||
var callback = ($defined(resp.callback)) ? resp.callback : "default";
|
||||
new Request.JSON.mdb({
|
||||
url: query,
|
||||
noCache : true,
|
||||
onSuccess: function(resp) {
|
||||
var callback = ($defined(resp.callback)) ? resp.callback : "default";
|
||||
|
||||
current_anchor.get_callback(callback)(resp);
|
||||
infobox.info(gettext("Done"));
|
||||
infobox.hide(1);
|
||||
}}).get();
|
||||
current_anchor.get_callback(callback)(resp);
|
||||
infobox.info(gettext("Done"));
|
||||
infobox.hide(1);
|
||||
}
|
||||
}).get();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -240,7 +244,7 @@ function simple_request(url, params) {
|
||||
profile: "gray",
|
||||
spinner: true
|
||||
});
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url : url,
|
||||
onSuccess : function(response) {
|
||||
if (response.status == "ok") {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<script type="text/javascript">
|
||||
function del_attachment(evt) {
|
||||
evt.stop();
|
||||
new Request.JSON({
|
||||
new Request.JSON.mdb({
|
||||
url: this.get("href"),
|
||||
onSuccess: function(resp) {
|
||||
this.getParent().dispose();
|
||||
|
||||
+8
-1
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
from django.http import Http404
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from modoboa.admin.models import Extension
|
||||
|
||||
class ExtControlMiddleware(object):
|
||||
@@ -15,3 +15,10 @@ class ExtControlMiddleware(object):
|
||||
if ext.enabled:
|
||||
return None
|
||||
raise Http404
|
||||
|
||||
class AjaxLoginRedirect(object):
|
||||
def process_response(self, request, response):
|
||||
if request.is_ajax():
|
||||
if type(response) == HttpResponseRedirect:
|
||||
response.status_code = 278
|
||||
return response
|
||||
|
||||
@@ -88,6 +88,7 @@ MIDDLEWARE_CLASSES = (
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'modoboa.lib.middleware.AjaxLoginRedirect',
|
||||
'modoboa.lib.middleware.ExtControlMiddleware',
|
||||
'modoboa.extensions.webmail.middleware.WebmailErrorMiddleware',
|
||||
)
|
||||
|
||||
@@ -206,6 +206,9 @@ var AnchorNavigation = new Class({
|
||||
new Request.JSON({
|
||||
url: query,
|
||||
noCache : true,
|
||||
onComplete: function() {
|
||||
ajax_login_redirect();
|
||||
},
|
||||
onSuccess: function(resp) {
|
||||
var callback = ($defined(resp.callback)) ? resp.callback : "default";
|
||||
this.callbacks[callback](resp);
|
||||
|
||||
+1
-1
@@ -229,4 +229,4 @@ saveparams = function(id, message) {
|
||||
}
|
||||
}).send();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Collection of functions that are accessible to every page.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Simple function that redirect ajax requests to the login page if
|
||||
* the status code received with a response is equal to 278.
|
||||
*/
|
||||
function ajax_login_redirect() {
|
||||
if (this.status != 278) {
|
||||
return;
|
||||
}
|
||||
var params = "?next=" + window.location.pathname;
|
||||
|
||||
window.location.href =
|
||||
this.xhr.getResponseHeader("Location").replace(/\?.*$/, params);
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple wrapper around Request.JSON. We just ensure that
|
||||
* redirections are correctly catched. (on session timeout for
|
||||
* example)
|
||||
*/
|
||||
Request.JSON.mdb = new Class({
|
||||
Extends: Request.JSON,
|
||||
|
||||
options: {
|
||||
onComplete: ajax_login_redirect
|
||||
}
|
||||
});
|
||||
@@ -13,7 +13,9 @@ domadminform_init = function() {
|
||||
{% url domains as doms_url %}
|
||||
new Request({
|
||||
url: "{% url domains %}" + domid + "/rawmboxes/?target=permissions",
|
||||
method: "get", onSuccess: function(data) {
|
||||
method: "get",
|
||||
onComplete: ajax_login_redirect,
|
||||
onSuccess: function(data) {
|
||||
$("id_user").set("html", data);
|
||||
$("id_user").options[0].setProperty("selected", "selected");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ function init_form() {
|
||||
new Autocompleter.Request.JSON("id_targets",
|
||||
"{% url admin.views.mailboxes_search %}", {
|
||||
postVar: "search",
|
||||
minLength: 3
|
||||
minLength: 3,
|
||||
onComplete: ajax_login_redirect
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<script src="{{ MEDIA_URL }}js/mootools.js" type="text/javascript"></script>
|
||||
<script src="{{ MEDIA_URL }}js/mootools-more.js" type="text/javascript"></script>
|
||||
<script src="{{ MEDIA_URL }}js/SqueezeBox.js" type="text/javascript"></script>
|
||||
<script src="{{ MEDIA_URL }}js/utils.js" type="text/javascript"></script>
|
||||
{% url django.views.i18n.javascript_catalog as catalog_url %}
|
||||
<script type="text/javascript" src="{{ catalog_url }}"></script>
|
||||
{% block html_head %}{% endblock %}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<script src="{{ MEDIA_URL }}js/SqueezeBox.js" type="text/javascript"></script>
|
||||
<script src="{{ MEDIA_URL }}js/infobox.js" type="text/javascript"></script>
|
||||
<script src="{{ MEDIA_URL }}js/common.js" type="text/javascript"></script>
|
||||
<script src="{{ MEDIA_URL }}js/utils.js" type="text/javascript"></script>
|
||||
{% url django.views.i18n.javascript_catalog as catalog_url %}
|
||||
<script type="text/javascript" src="{{ catalog_url }}"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
Reference in New Issue
Block a user