mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
* Added result messages about folder operations,
* Better display (I hope) of those messages. see #55
This commit is contained in:
@@ -8,4 +8,4 @@ class WebmailErrorMiddleware(object):
|
||||
if not isinstance(exception, WebmailError):
|
||||
return None
|
||||
return ajax_response(request, status="ko",
|
||||
error=str(exception), norefresh=True)
|
||||
respmsg=str(exception), norefresh=True)
|
||||
|
||||
@@ -51,7 +51,7 @@ var FdMenu = new Class({
|
||||
onSuccess: function(resp) {
|
||||
if (resp.status == "ok") {
|
||||
var dfolder = this.current_folder + "/";
|
||||
infobox.info(gettext("Folder deleted."));
|
||||
|
||||
if (dfolder == current_anchor.base) {
|
||||
var pfolder = ((this.current_folder.split(".")).slice(0, -1)).join(".");
|
||||
if (pfolder == "") {
|
||||
@@ -59,9 +59,11 @@ var FdMenu = new Class({
|
||||
}
|
||||
current_anchor.baseurl(pfolder, 1);
|
||||
}
|
||||
current_anchor.update.delay(500, current_anchor, 1);
|
||||
current_anchor.loading_message = gettext("Folder deleted");
|
||||
current_anchor.loading_color = "green";
|
||||
current_anchor.update(1);
|
||||
} else {
|
||||
infobox.error(gettext("Failed to delete folder"));
|
||||
infobox.error(resp.error);
|
||||
infobox.hide(2);
|
||||
}
|
||||
}.bind(this)
|
||||
|
||||
+13
-13
@@ -8,6 +8,7 @@ from django.utils import simplejson
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib import messages
|
||||
from modoboa.admin.models import Mailbox
|
||||
from modoboa.lib import parameters, _render, _render_error, \
|
||||
getctx, is_not_localadmin, _render_to_string, split_mailbox, \
|
||||
@@ -459,7 +460,7 @@ def newfolder(request, tplname="webmail/folder.html"):
|
||||
pf = request.POST.has_key("parent_folder") \
|
||||
and request.POST["parent_folder"] or None
|
||||
mbc.create_folder(form.cleaned_data["name"], pf)
|
||||
return ajax_response(request, ajaxnav=True)
|
||||
return ajax_response(request, ajaxnav=True, respmsg=_("Folder created"))
|
||||
|
||||
ctx["form"] = form
|
||||
ctx["selected"] = None
|
||||
@@ -487,17 +488,16 @@ def editfolder(request, tplname="webmail/folder.html"):
|
||||
and request.POST["parent_folder"] or None
|
||||
ctx["selected"] = pf
|
||||
oldname, oldparent = separate_folder(request.POST["oldname"])
|
||||
try:
|
||||
extra = {}
|
||||
if form.cleaned_data["name"] != oldname \
|
||||
or (pf is not None and pf != oldparent):
|
||||
newname = form.cleaned_data["name"] if pf is None \
|
||||
else "%s.%s" % (pf, form.cleaned_data["name"])
|
||||
mbc.rename_folder(request.POST["oldname"], newname)
|
||||
extra["url"] = newname
|
||||
return ajax_response(request, ajaxnav=True, **extra)
|
||||
except Exception:
|
||||
pass
|
||||
extra = {}
|
||||
if form.cleaned_data["name"] != oldname \
|
||||
or (pf is not None and pf != oldparent):
|
||||
newname = form.cleaned_data["name"] if pf is None \
|
||||
else "%s.%s" % (pf, form.cleaned_data["name"])
|
||||
mbc.rename_folder(request.POST["oldname"], newname)
|
||||
extra["url"] = newname
|
||||
return ajax_response(request, ajaxnav=True,
|
||||
respmsg=_("Folder modified"), **extra)
|
||||
|
||||
ctx["form"] = form
|
||||
return ajax_response(request, status="ko", template=tplname, **ctx)
|
||||
|
||||
@@ -519,4 +519,4 @@ def delfolder(request):
|
||||
mbc = IMAPconnector(user=request.user.username,
|
||||
password=request.session["password"])
|
||||
mbc.delete_folder(request.GET["name"])
|
||||
return ajax_response(request, status="ko")
|
||||
return ajax_response(request)
|
||||
|
||||
+3
-3
@@ -74,7 +74,7 @@ def getctx(status, level=1, callback=None, **kwargs):
|
||||
ctx[kw] = v
|
||||
return ctx
|
||||
|
||||
def ajax_response(request, status="ok", error=None,
|
||||
def ajax_response(request, status="ok", respmsg=None,
|
||||
url="", ajaxnav=False, norefresh=False,
|
||||
template=None, **kwargs):
|
||||
"""Ajax response shortcut
|
||||
@@ -97,8 +97,8 @@ def ajax_response(request, status="ok", error=None,
|
||||
else:
|
||||
content = ""
|
||||
jsonctx = {"status" : status, "content" : content}
|
||||
if error is not None:
|
||||
jsonctx["error"] = error
|
||||
if respmsg is not None:
|
||||
jsonctx["respmsg"] = respmsg
|
||||
if ajaxnav:
|
||||
jsonctx["ajaxnav"] = True
|
||||
if url != "":
|
||||
|
||||
+9
-2
@@ -54,8 +54,8 @@ function check_anchor() {
|
||||
|
||||
var query = current_anchor.serialized.substring(1);
|
||||
|
||||
infobox.show(gettext("Loading..."), {
|
||||
profile: "gray",
|
||||
infobox.show(current_anchor.loading_message, {
|
||||
profile: current_anchor.loading_color,
|
||||
spinner: true
|
||||
});
|
||||
new Request.JSON({url: query, noCache : true, onSuccess: function(resp) {
|
||||
@@ -63,6 +63,7 @@ function check_anchor() {
|
||||
callbacks[callback](resp);
|
||||
infobox.info(gettext("Done"));
|
||||
infobox.hide(1);
|
||||
current_anchor.reset_loading_infos();
|
||||
}}).get();
|
||||
};
|
||||
|
||||
@@ -84,6 +85,12 @@ function HashWrapper(deflocation) {
|
||||
this.base = '';
|
||||
this.serialized = null;
|
||||
|
||||
this.reset_loading_infos = function() {
|
||||
this.loading_message = gettext("Loading...");
|
||||
this.loading_color = "gray";
|
||||
};
|
||||
this.reset_loading_infos();
|
||||
|
||||
this.reset = function() {
|
||||
this.base = null;
|
||||
this.params.empty();
|
||||
|
||||
+5
-1
@@ -54,7 +54,7 @@ function ajax_submit(event) {
|
||||
|
||||
if (response.status == "ko") {
|
||||
if ($defined(response.norefresh) && response.norefresh == true) {
|
||||
$("error").set("html", response.error);
|
||||
$("error").set("html", response.respmsg);
|
||||
} else {
|
||||
$(document.body).set("html", response.content);
|
||||
$(document.body).addEvent("submit", ajax_submit);
|
||||
@@ -63,6 +63,10 @@ function ajax_submit(event) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($defined(response.respmsg)) {
|
||||
parent.current_anchor.loading_message = response.respmsg;
|
||||
parent.current_anchor.loading_color = "green";
|
||||
}
|
||||
if ($defined(response.ajaxnav)) {
|
||||
if ($defined(response.url)) {
|
||||
parent.current_anchor.baseurl(response.url, 1);
|
||||
|
||||
Reference in New Issue
Block a user