fixed #123 & #135: the 'compose' callback was not called on error.

This commit is contained in:
Antoine Nguyen
2011-04-27 11:37:33 +02:00
parent 7c868ae7f4
commit e0cf9e8cd9
2 changed files with 21 additions and 14 deletions
+14 -7
View File
@@ -82,14 +82,17 @@ function compose_loader(event) {
current_anchor.baseurl("compose").update();
}
function resize_window_callback(event) {
setDivHeight("id_body", $("mailheader").getSize().y, 0);
}
/*
* Callback of the 'compose' action
*/
function compose_callback(resp) {
wm_updatelisting(resp);
window.addEvent("resize", function(evt) {
setDivHeight("id_body", $("mailheader").getSize().y, 0);
});
window.addEvent("resize", resize_window_callback);
window.fireEvent("resize");
var editormode = resp.editor;
@@ -105,15 +108,19 @@ function compose_callback(resp) {
height: $(editorid).getSize().y
});
}
$$("a[name=back]").addEvent("click", loadFolder);
$$("a[name=sendmail]").addEvent("click", function(evt) {
$$("a[name=back]")
.removeEvents("click")
.addEvent("click", loadFolder);
$$("a[name=sendmail]")
.removeEvents("click")
.addEvent("click", function(evt) {
evt.stop();
$("composemail").set("send", {
onSuccess: function(resp) {
resp = JSON.decode(resp);
if (resp.status == "ko") {
wm_updatelisting(resp);
window.fireEvent("resize");
get_callback("compose")(resp);
if ($defined(resp.error)) {
infobox.error(resp.error);
}
+7 -7
View File
@@ -308,30 +308,30 @@ def send_mail(request, withctx=False, origmsg=None, posturl=None):
form = ComposeMailForm(request.POST)
error = None
ctx = None
editormode = parameters.get_user(request.user, "EDITOR")
if form.is_valid():
from email.mime.text import MIMEText
from email.utils import make_msgid, formatdate
import smtplib
subtype = parameters.get_user(request.user, "EDITOR")
body = request.POST["id_body"]
charset = "utf-8"
if subtype == "html":
if editormode == "html":
from email.mime.multipart import MIMEMultipart
msg = MIMEMultipart(_subtype="related")
submsg = MIMEMultipart(_subtype="alternative")
textbody = __html2plaintext(body)
submsg.attach(MIMEText(textbody.encode(charset),
_subtype="plain", _charset=charset))
_subtype="plain", _charset=charset))
body, images = find_images_in_body(body)
submsg.attach(MIMEText(body.encode(charset), _subtype=subtype,
_charset=charset))
submsg.attach(MIMEText(body.encode(charset), _subtype=editormode,
_charset=charset))
msg.attach(submsg)
for img in images:
msg.attach(img)
else:
msg = MIMEText(body.encode(charset), _subtype=subtype)
msg = MIMEText(body.encode(charset), _subtype=editormode)
msg["Subject"] = request.POST["subject"]
address, domain = split_mailbox(request.POST["from_"])
@@ -378,7 +378,7 @@ def send_mail(request, withctx=False, origmsg=None, posturl=None):
{"form" : form,
"body" : request.POST["id_body"].strip(),
"posturl" : posturl})
ctx = getctx("ko", level=2, error=error, listing=listing)
ctx = getctx("ko", level=2, error=error, listing=listing, editor=editormode)
if not withctx:
return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
return ctx, HttpResponse(simplejson.dumps(ctx), mimetype="application/json")