]> err.no Git - scalable-opengroupware.org/blobdiff - UI/WebServerResources/UIxMailEditor.js
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1261 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / WebServerResources / UIxMailEditor.js
index 6f8018e4f887bf20b452c89fd66ccb25b2479fdd..212f171528ca76d1f6e4902bdd284732bbfcaf06 100644 (file)
@@ -9,7 +9,6 @@ function onContactAdd() {
     urlstr += '/';
   urlstr += ("../../" + UserLogin + "/Contacts/"
              + contactSelectorAction + selectorURL);
-//   log (urlstr);
   var w = window.open(urlstr, "Addressbook",
                       "width=640,height=400,resizable=1,scrollbars=0");
   w.selector = selector;
@@ -17,7 +16,7 @@ function onContactAdd() {
   w.focus();
 
   return false;
- }
+}
 
 function addContact(tag, fullContactName, contactId, contactName, contactEmail) {
   if (!mailIsRecipient(contactEmail)) {
@@ -31,7 +30,7 @@ function addContact(tag, fullContactName, contactId, contactName, contactEmail)
     var counter = 0;
     var currentRow = $('row_' + counter);
     while (currentRow && !stop) {
-      var currentValue = $(currentRow.childNodesWithTag("span")[1]).childNodesWithTag("input")[0].value;
+      var currentValue = $(currentRow.childNodesWithTag("td")[1]).childNodesWithTag("input")[0].value;
       if (currentValue == neededOptionValue) {
         stop = true;
         insertContact($("addr_" + counter), contactName, contactEmail);
@@ -42,9 +41,10 @@ function addContact(tag, fullContactName, contactId, contactName, contactEmail)
 
     if (!stop) {
       fancyAddRow(false, "");
-      $("row_" + counter).childNodesWithTag("span")[0].childNodesWithTag("select")[0].value
+      $($("row_" + counter).childNodesWithTag("td")[0]).childNodesWithTag("select")[0].value
         = neededOptionValue;
       insertContact($("addr_" + counter), contactName, contactEmail);
+      onWindowResize(null);
     }
   }
 }
@@ -122,63 +122,82 @@ function updateInlineAttachmentList(sender, attachments) {
 /* mail editor */
 
 function validateEditorInput(sender) {
-   var errortext = "";
-   var field;
+  var errortext = "";
+  var field;
    
-   field = document.pageform.subject;
-   if (field.value == "")
-      errortext = errortext + labels.error_missingsubject + "\n";
+  field = document.pageform.subject;
+  if (field.value == "")
+    errortext = errortext + labels["error_missingsubject"] + "\n";
 
-   if (!UIxRecipientSelectorHasRecipients())
-      errortext = errortext + labels.error_missingrecipients + "\n";
+  if (!hasRecipients())
+    errortext = errortext + labels["error_missingrecipients"] + "\n";
    
-   if (errortext.length > 0) {
-      alert(labels.error_validationfailed.decodeEntities() + ":\n"
-           + errortext.decodeEntities());
-      return false;
-   }
-   return true;
+  if (errortext.length > 0) {
+    alert(labels["error_validationfailed"] + ":\n" + errortext);
+    return false;
+  }
+
+  return true;
 }
 
 function clickedEditorSend(sender) {
-   if (!validateEditorInput(sender))
-      return false;
+  if (!validateEditorInput(sender))
+    return false;
+
+  var input = currentAttachmentInput();
+  if (input)
+    input.parentNode.removeChild(input);
 
-   window.shouldPreserve = true;
-   document.pageform.action = "send";
-   document.pageform.submit();
+  var toolbar = document.getElementById("toolbar");
+  if (!document.busyAnim)
+    document.busyAnim = startAnimation(toolbar);
+   
+  window.shouldPreserve = true;
+  document.pageform.action = "send";
+  document.pageform.submit();
 
-   return false;
+  return false;
+}
+
+function currentAttachmentInput() {
+  var input = null;
+
+  var inputs = $("attachmentsArea").getElementsByTagName("input");
+  var i = 0;
+  while (!input && i < inputs.length)
+    if ($(inputs[i]).hasClassName("currentAttachment"))
+      input = inputs[i];
+    else
+      i++;
+
+  return input;
 }
 
 function clickedEditorAttach(sender) {
-  var area = $("attachmentsArea");
-  area.setStyle({ display: "block" });
-  
-  var inputs = area.getElementsByTagName("input");
-  var attachmentName = "attachment" + inputs.length;
-  var newAttachment = createElement("input", attachmentName,
-                                   "currentAttachment", null,
-                                   { type: "file",
-                                     name: attachmentName },
-                                   area);
-  Event.observe(newAttachment, "change",
-               onAttachmentChange.bindAsEventListener(newAttachment));
+  var input = currentAttachmentInput();
+  if (!input) {
+    var area = $("attachmentsArea");
+
+    if (!area.style.display) {
+      area.setStyle({ display: "block" });
+      onWindowResize(null);
+    }
+    var inputs = area.getElementsByTagName("input");
+    var attachmentName = "attachment" + inputs.length;
+    var newAttachment = createElement("input", attachmentName,
+                                     "currentAttachment", null,
+                                     { type: "file",
+                                       name: attachmentName },
+                                     area);
+    Event.observe(newAttachment, "change",
+                 onAttachmentChange.bindAsEventListener(newAttachment));
+  }
 
   return false;
 }
 
 function onAddAttachment() {
-  var area = $("attachmentsArea");
-  var inputs = area.getElementsByTagName("input");
-  var attachmentName = "attachment" + inputs.length;
-  var newAttachment = createElement("input", attachmentName,
-                                   "currentAttachment", null,
-                                   { type: "file",
-                                     name: attachmentName },
-                                   area);
-  Event.observe(newAttachment, "change",
-               onAttachmentChange.bindAsEventListener(newAttachment));
+  return clickedEditorAttach(null);
 }
 
 function onAttachmentChange(event) {
@@ -210,10 +229,16 @@ function createAttachment(node, list) {
 }
 
 function clickedEditorSave(sender) {
+  var input = currentAttachmentInput();
+  if (input)
+    input.parentNode.removeChild(input);
+
   window.shouldPreserve = true;
   document.pageform.action = "save";
   document.pageform.submit();
 
+  if (window.opener && window.open && !window.closed)
+    window.opener.refreshFolderByType('draft');
   return false;
 }
 
@@ -230,6 +255,9 @@ function initMailEditor() {
   if (listContent.length > 0)
     $("attachmentsArea").setStyle({ display: "block" });
 
+  var list = $("addressList");
+  TableKit.Resizable.init(list, {'trueResize' : true, 'keepWidth' : true});
+
   onWindowResize(null);
   Event.observe(window, "resize", onWindowResize);
   Event.observe(window, "beforeunload", onMailEditorClose);
@@ -270,7 +298,7 @@ function onRemoveAttachments() {
 
 function attachmentDeleteCallback(http) {
   if (http.readyState == 4) {
-    if (http.status == 204) {
+    if (isHttpStatus204(http.status)) {
       var node = http.callbackData;
       node.parentNode.removeChild(node);
     }
@@ -288,27 +316,56 @@ function onSelectAllAttachments() {
 
 function onWindowResize(event) {
   var textarea = document.pageform.text;
-  var windowheight = (typeof self.innerHeight == "number" ? self.innerHeight : document.body.clientHeight);
-  var textareaoffset = textarea.offsetTop;
   var rowheight = (Element.getHeight(textarea) / textarea.rows);
+  var headerarea = $("headerArea");
+  
+  var attachmentsarea = $("attachmentsArea");
+  var attachmentswidth = 0;
+  if (attachmentsarea.style.display) {
+    attachmentswidth = attachmentsarea.getWidth();
+    // Resize of attachment list is b0rken under IE7
+//    fromfield = $(document).getElementsByClassName('headerField',
+//                                                headerarea)[0];
+//    $("attachments").setStyle({ height: (headerarea.getHeight() - fromfield.getHeight() - 10) + 'px' });
+  }
+//  var subjectfield = $(document).getElementsByClassName('headerField',
+//                                                     $('subjectRow'))[0];
+//  var subjectinput = $(document).getElementsByClassName('textField',
+//                                                     $('subjectRow'))[0];
+//
+  // Resize subject field
+//  subjectinput.setStyle({ width: (window.width()
+//                               - $(subjectfield).getWidth()
+//                               - attachmentswidth
+//                               - 4 - 30) + 'px' });
+
+  // Resize address fields
+  var addresslist = $('addressList');
+  addresslist.setStyle({ width: ($(this).width() - attachmentswidth - 10) + 'px' });
+
+  // Set textarea position
+  textarea.setStyle({ 'top': (headerarea.getHeight() + headerarea.offsetTop) + 'px' });
 
-  textarea.rows = Math.round((windowheight - textareaoffset) / rowheight);
-  log ("onWindowResize new number of rows = " + textarea.rows);
+  var textareaoffset = textarea.offsetTop;
+
+  // Resize the textarea (message content)
+  textarea.rows = Math.round((window.height() - textareaoffset) / rowheight);
 }
 
 function onMailEditorClose(event) {
   if (window.shouldPreserve)
     window.shouldPreserve = false;
   else {
-    var url = "" + window.location;
-    var parts = url.split("/");
-    parts[parts.length-1] = "delete";
-    url = parts.join("/");
-
-    http = createHTTPClient();
-    http.open("POST", url, false /* not async */);
-    http.send("");
+    if (window.opener && window.opener.open && !window.opener.closed) {
+      var url = "" + window.location;
+      var parts = url.split("/");
+      parts[parts.length-1] = "delete";
+      url = parts.join("/");
+      window.opener.deleteDraft(url);
+    }
   }
+
+  Event.stopObserving(window, "beforeunload", onMailEditorClose);
 }
 
 addEvent(window, 'load', initMailEditor);