diff --git a/ChangeLog b/ChangeLog index 717f27c30..2dae2cdd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2010-08-23 Wolfgang Sourdeau + * UI/WebServerResources/UIxMailEditor.js: (clickEditorSend): make + use of the iframe hack for receiving the POST's response and + interpret it as JSON, with error handling. + + * UI/WebServerResources/HTMLElement.js: (Element.allTextContent): + fetch the concatenated text content of the all the child nodes of + the element, recursively. + + * UI/WebServerResources/MailerUI.js: (initMailer): use + "UserSettings" only if we are the main window. + + * UI/MailerUI/UIxMailEditor.m (-sendAction): return a json + representation of the success of the operation, with a message if + an exception was returned. + * UI/WebServerResources/MailerUI.js: (mailListToggleMessagesRead): new method, spun from "mailListMarkMessage", which is basically replaces in a more generic way by acting on all selected messages diff --git a/UI/MailerUI/UIxMailEditor.m b/UI/MailerUI/UIxMailEditor.m index 04c4e7446..9dbe0104c 100644 --- a/UI/MailerUI/UIxMailEditor.m +++ b/UI/MailerUI/UIxMailEditor.m @@ -587,33 +587,38 @@ static NSArray *infoKeys = nil; return error; } -- (id ) sendAction +- (WOResponse *) sendAction { - id result; SOGoDraftObject *co; + NSDictionary *jsonResponse; + NSException *error; + + co = [self clientObject]; - // TODO: need to validate whether we have a To etc - /* first, save form data */ - result = (id ) [self validateForSend]; - if (!result) + error = [self validateForSend]; + if (!error) { if ([self _saveFormInfo]) - { - result = (id ) [[self clientObject] sendMail]; - if (!result) - { - co = [self clientObject]; - result = [self jsCloseWithRefreshMethod: [NSString stringWithFormat: @"refreshMessage(\"%@\", %i)", - [co sourceFolder], - [co IMAP4ID]]]; - } - } + error = [co sendMail]; else - result = [self failedToSaveFormResponse]; + error = [self failedToSaveFormResponse]; } - return result; + if (error) + jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: + @"failure", @"status", + [error reason], @"message", + nil]; + else + jsonResponse = [NSDictionary dictionaryWithObjectsAndKeys: + @"success", @"status", + [co sourceFolder], @"sourceFolder", + [co IMAP4ID], @"messageID", + nil]; + + return [self responseWithStatus: 200 + andString: [jsonResponse jsonRepresentation]]; } @end /* UIxMailEditor */ diff --git a/UI/Templates/MailerUI/UIxMailEditor.wox b/UI/Templates/MailerUI/UIxMailEditor.wox index 41e07d8e9..bad3ead4b 100644 --- a/UI/Templates/MailerUI/UIxMailEditor.wox +++ b/UI/Templates/MailerUI/UIxMailEditor.wox @@ -74,7 +74,7 @@ class="textField" var:value="subject" /> -
+
diff --git a/UI/WebServerResources/HTMLElement.js b/UI/WebServerResources/HTMLElement.js index a8454588b..57a1e4d41 100644 --- a/UI/WebServerResources/HTMLElement.js +++ b/UI/WebServerResources/HTMLElement.js @@ -8,7 +8,22 @@ Element.addMethods({ if (element.bind) element.bind(); }, - + + allTextContent: function(element) { + var content = ""; + for (var i = 0; i < element.childNodes.length; i++) { + var node = $(element.childNodes[i]); + if (node.nodeType == Node.TEXT_NODE) { + content += node.nodeValue; + } + else if (node.nodeType == Node.ELEMENT_NODE) { + content += Element.allTextContent(node); + } + } + + return content; + }, + childNodesWithTag: function(element, tagName) { element = $(element); diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index 241bdcf08..ec4e00376 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -1679,18 +1679,18 @@ function openInbox(node) { } function initMailer(event) { - // Restore sorting from user settings - if (UserSettings["Mail"] && UserSettings["Mail"]["SortingState"]) { - sorting["attribute"] = UserSettings["Mail"]["SortingState"][0]; - sorting["ascending"] = parseInt(UserSettings["Mail"]["SortingState"][1]) > 0; - if (sorting["attribute"] == 'to') sorting["attribute"] = 'from'; // initial mailbox is always the inbox - } - else { - sorting["attribute"] = "date"; - sorting["ascending"] = false; - } - if (!$(document.body).hasClassName("popup")) { + // Restore sorting from user settings + if (UserSettings && UserSettings["Mail"] && UserSettings["Mail"]["SortingState"]) { + sorting["attribute"] = UserSettings["Mail"]["SortingState"][0]; + sorting["ascending"] = parseInt(UserSettings["Mail"]["SortingState"][1]) > 0; + if (sorting["attribute"] == 'to') sorting["attribute"] = 'from'; // initial mailbox is always the inbox + } + else { + sorting["attribute"] = "date"; + sorting["ascending"] = false; + } + Mailer.dataTable = $("mailboxList"); Mailer.dataTable.addInterface(SOGoDataTableInterface); Mailer.dataTable.setRowRenderCallback(messageListCallback); diff --git a/UI/WebServerResources/UIxMailEditor.css b/UI/WebServerResources/UIxMailEditor.css index 0317abacd..f067c79d2 100644 --- a/UI/WebServerResources/UIxMailEditor.css +++ b/UI/WebServerResources/UIxMailEditor.css @@ -98,7 +98,7 @@ div#attachmentsArea margin: auto; border-left: 1px solid #888; } -hr +hr.fieldSeparator { background-color: #848284; border: 0; clear: both; diff --git a/UI/WebServerResources/UIxMailEditor.js b/UI/WebServerResources/UIxMailEditor.js index 4451d833a..83e931fd4 100644 --- a/UI/WebServerResources/UIxMailEditor.js +++ b/UI/WebServerResources/UIxMailEditor.js @@ -106,7 +106,7 @@ function insertContact(inputNode, contactName, contactEmail) { /* mail editor */ -function validateEditorInput(sender) { +function validateEditorInput() { var errortext = ""; var field; @@ -125,26 +125,63 @@ function validateEditorInput(sender) { return true; } -function clickedEditorSend(sender) { - if (document.pageform.action == "send" || !validateEditorInput(sender)) - return false; +function onValidate(event) { + var rc = false; - var input = currentAttachmentInput(); - if (input) - input.parentNode.removeChild(input); + if (document.pageform.action != "send" + && validateEditorInput()) { + var input = currentAttachmentInput(); + if (input) + input.parentNode.removeChild(input); - var toolbar = document.getElementById("toolbar"); - if (!document.busyAnim) - document.busyAnim = startAnimation(toolbar); + var toolbar = document.getElementById("toolbar"); + if (!document.busyAnim) + document.busyAnim = startAnimation(toolbar); - var lastRow = $("lastRow"); - lastRow.down("select").name = "popup_last"; + var lastRow = $("lastRow"); + lastRow.down("select").name = "popup_last"; - window.shouldPreserve = true; - document.pageform.action = "send"; - document.pageform.submit(); - - return false; + window.shouldPreserve = true; + + document.pageform.action = "send"; + + AIM.submit(document.pageform, {'onComplete' : onPostComplete}); + + rc = true; + } + + return rc; +} + +function onPostComplete(response) { + if (response && response.length > 0) { + var jsonResponse = response.evalJSON(); + if (jsonResponse["status"] == "success") { + if (window.opener && window.opener.refreshMessage) { + window.opener.refreshMessage(jsonResponse["sourceFolder"], + jsonResponse["messageID"]); + } + window.close(); + } + else { + var message = jsonResponse["message"]; + document.pageform.action = ""; + var progressImage = $("progressIndicator"); + if (progressImage) { + progressImage.parentNode.removeChild(progressImage); + } + showAlertDialog(jsonResponse["message"]); + } + } + else { + window.close(); + } +} + +function clickedEditorSend() { + if (onValidate()) { + document.pageform.submit(); + } } function currentAttachmentInput() { @@ -161,7 +198,7 @@ function currentAttachmentInput() { return input; } -function clickedEditorAttach(sender) { +function clickedEditorAttach() { var input = currentAttachmentInput(); if (!input) { var area = $("attachmentsArea"); @@ -214,7 +251,7 @@ function createAttachment(node, list) { attachment.appendChild(attachmentName); } -function clickedEditorSave(sender) { +function clickedEditorSave() { var input = currentAttachmentInput(); if (input) input.parentNode.removeChild(input); diff --git a/UI/WebServerResources/generic.js b/UI/WebServerResources/generic.js index 210d82a06..40711ae5b 100644 --- a/UI/WebServerResources/generic.js +++ b/UI/WebServerResources/generic.js @@ -1718,8 +1718,9 @@ AIM = { if (d.location.href == "about:blank") return; - if (typeof(i.onComplete) == 'function') - i.onComplete(d.body.innerHTML); + if (typeof(i.onComplete) == 'function') { + i.onComplete(Element.allTextContent(d.body)); + } } };