[Svn] r3021 - in trunk/roundcubemail/program: js steps/mail

trac at roundcube.net trac at roundcube.net
Tue Oct 6 08:55:08 CEST 2009


Author: thomasb
Date: 2009-10-06 01:55:08 -0500 (Tue, 06 Oct 2009)
New Revision: 3021

Modified:
   trunk/roundcubemail/program/js/app.js
   trunk/roundcubemail/program/js/editor_images.js
   trunk/roundcubemail/program/steps/mail/attachments.inc
   trunk/roundcubemail/program/steps/mail/compose.inc
Log:
Hold attachment info in a js list in order to simplify things + codestyle

Modified: trunk/roundcubemail/program/js/app.js
===================================================================
--- trunk/roundcubemail/program/js/app.js	2009-10-06 06:08:14 UTC (rev 3020)
+++ trunk/roundcubemail/program/js/app.js	2009-10-06 06:55:08 UTC (rev 3021)
@@ -2172,14 +2172,11 @@
       }
 
     // check if all files has been uploaded
-    if (this.gui_objects.attachmentlist) {
-      var list = this.gui_objects.attachmentlist.getElementsByTagName("li");
-      for (i=0;i<list.length;i++)
-        if (!String(list[i].id).match(/^rcmfile/))
-          {
-          alert(this.get_label('notuploadedwarning'));
-          return false;
-          }
+    for (var key in this.env.attachments) {
+      if (typeof this.env.attachments[key] == 'object' && !this.env.attachments[key].complete) {
+        alert(this.get_label('notuploadedwarning'));
+        return false;
+      }
     }
     
     // display localized warning for missing subject
@@ -2464,23 +2461,23 @@
       // handle upload errors, parsing iframe content in onload
       var fr = document.getElementsByName(frame_name)[0];
       $(fr).bind('load', {ts:ts}, function(e) {
-	var content = '';
+        var content = '';
         try {
           if (this.contentDocument) {
-	    var d = this.contentDocument;
-	  } else if (this.contentWindow) {
-	    var d = this.contentWindow.document;
-	  }
-	  content = d.childNodes[0].innerHTML;
+            var d = this.contentDocument;
+          } else if (this.contentWindow) {
+            var d = this.contentWindow.document;
+          }
+          content = d.childNodes[0].innerHTML;
         } catch (e) {}
 
-	if (!String(content).match(/add2attachment/) && (!bw.opera || (rcmail.env.uploadframe && rcmail.env.uploadframe == e.data.ts))) {
-	  rcmail.display_message(rcmail.get_label('fileuploaderror'), 'error');
-	  rcmail.remove_from_attachment_list(e.data.ts);
+        if (!String(content).match(/add2attachment/) && (!bw.opera || (rcmail.env.uploadframe && rcmail.env.uploadframe == e.data.ts))) {
+          rcmail.display_message(rcmail.get_label('fileuploaderror'), 'error');
+          rcmail.remove_from_attachment_list(e.data.ts);
         }
-	// Opera hack: handle double onload
-	if (bw.opera)
-	  rcmail.env.uploadframe = e.data.ts;
+        // Opera hack: handle double onload
+        if (bw.opera)
+          rcmail.env.uploadframe = e.data.ts;
       });
 
       form.target = frame_name;
@@ -2496,7 +2493,7 @@
         content = '<img src="'+this.env.loadingicon+'" alt="" />'+content;
       if (this.env.cancelicon)
         content = '<a title="'+this.get_label('cancel')+'" onclick="return rcmail.cancel_attachment_upload(\''+ts+'\', \''+frame_name+'\');" href="#cancelupload"><img src="'+this.env.cancelicon+'" alt="" /></a>'+content;
-      this.add2attachment_list(ts, content);
+      this.add2attachment_list(ts, { name:'', html:content, complete:false });
       }
     
     // set reference to the form object
@@ -2506,26 +2503,35 @@
 
   // add file name to attachment list
   // called from upload page
-  this.add2attachment_list = function(name, content, upload_id)
-    {
+  this.add2attachment_list = function(name, att, upload_id)
+  {
     if (!this.gui_objects.attachmentlist)
       return false;
     
+    var li = $('<li>').attr('id', name).html(att.html);
     var indicator;
+    
     // replace indicator's li
     if (upload_id && (indicator = document.getElementById(upload_id))) {
-      var li = document.createElement('li');
-      $(li).attr('id', name).html(content);
-      indicator.parentNode.replaceChild(li, indicator);
-      } else { // add new li
-      $('<li>').attr('id', name).html(content).appendTo(this.gui_objects.attachmentlist);
-      }
+      li.replaceAll(indicator);
+    }
+    else { // add new li
+      li.appendTo(this.gui_objects.attachmentlist);
+    }
     
+    if (upload_id && this.env.attachments[upload_id])
+      delete this.env.attachments[upload_id];
+    
+    this.env.attachments[name] = att;
+    
     return true;
-    };
+  };
 
   this.remove_from_attachment_list = function(name)
-    {
+  {
+    if (this.env.attachments[name])
+      delete this.env.attachments[name];
+    
     if (!this.gui_objects.attachmentlist)
       return false;
 
@@ -2533,11 +2539,11 @@
     for (i=0;i<list.length;i++)
       if (list[i].id == name)
         this.gui_objects.attachmentlist.removeChild(list[i]);
-    };
+  };
 
   this.remove_attachment = function(name)
     {
-    if (name)
+    if (name && this.env.attachments[name])
       this.http_post('remove-attachment', '_file='+urlencode(name));
 
     return true;
@@ -2570,11 +2576,11 @@
       var addurl = '';
       if (this.message_list) {
         this.message_list.clear();
-	if (this.env.search_mods) {
+        if (this.env.search_mods) {
           var head_arr = new Array();
           for (var n in this.env.search_mods)
-	    head_arr.push(n);
-	  addurl += '&_headers='+head_arr.join(',');
+            head_arr.push(n);
+          addurl += '&_headers='+head_arr.join(',');
           }
         } else if (this.contact_list) {
         this.contact_list.clear(true);

Modified: trunk/roundcubemail/program/js/editor_images.js
===================================================================
--- trunk/roundcubemail/program/js/editor_images.js	2009-10-06 06:08:14 UTC (rev 3020)
+++ trunk/roundcubemail/program/js/editor_images.js	2009-10-06 06:55:08 UTC (rev 3021)
@@ -1,22 +1,12 @@
 
 var rc_client = tinyMCEPopup.getParam("rc_client");
-if (rc_client.gui_objects.attachmentlist)
+if (rc_client.env.attachments)
 {
    var tinyMCEImageList = new Array();
-   var attachElems = rc_client.gui_objects.attachmentlist.getElementsByTagName("li");
-   for (i = 0; i < attachElems.length; i++)
+   for (var id in rc_client.env.attachments)
    {
-      var liElem = attachElems[i];
-      var fname = attachElems[i].id;
-      for (j = 0; j < liElem.childNodes.length; j++)
-      {
-         if (liElem.childNodes[j].nodeName == "#text")
-         {
-            fname = liElem.childNodes[j].nodeValue;
-         }
-      }
-      
-      if (fname.match(/\.(bmp|gif|png|jpg|jpeg)$/))
-        tinyMCEImageList.push([fname, rc_client.env.comm_path+'&_action=display-attachment&_file='+attachElems[i].id]);
+      var att = rc_client.env.attachments[id];
+      if (att.complete && att.mimetype.indexOf('image/') == 0)
+        tinyMCEImageList.push([att.name, rc_client.env.comm_path+'&_action=display-attachment&_file='+id]);
    }
 };

Modified: trunk/roundcubemail/program/steps/mail/attachments.inc
===================================================================
--- trunk/roundcubemail/program/steps/mail/attachments.inc	2009-10-06 06:08:14 UTC (rev 3020)
+++ trunk/roundcubemail/program/steps/mail/attachments.inc	2009-10-06 06:55:08 UTC (rev 3021)
@@ -111,7 +111,11 @@
 
       $content .= Q($attachment['name']);
       
-      $OUTPUT->command('add2attachment_list', "rcmfile$id", $content, $uploadid);
+      $OUTPUT->command('add2attachment_list', "rcmfile$id", array(
+        'html' => $content,
+        'name' => $attachment['name'],
+        'mimetype' => $attachment['mimetype'],
+        'complete' => true), $uploadid);
     }
     else {  // upload failed
       $err = $_FILES['_attachments']['error'][$i];

Modified: trunk/roundcubemail/program/steps/mail/compose.inc
===================================================================
--- trunk/roundcubemail/program/steps/mail/compose.inc	2009-10-06 06:08:14 UTC (rev 3020)
+++ trunk/roundcubemail/program/steps/mail/compose.inc	2009-10-06 06:55:08 UTC (rev 3021)
@@ -781,6 +781,7 @@
     $attrib['id'] = 'rcmAttachmentList';
   
   $out = "\n";
+  $jslist = array();
   
   if (is_array($_SESSION['compose']['attachments']))
   {
@@ -798,12 +799,14 @@
       if (empty($a_prop))
         continue;
       
-      $out .= html::tag('li', array('id' => "rcmfile".$id),
+      $out .= html::tag('li', array('id' => 'rcmfile'.$id),
         html::a(array(
             'href' => "#delete",
             'title' => rcube_label('delete'),
             'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%s', this)", JS_OBJECT_NAME, $id)),
           $button) . Q($a_prop['name']));
+        
+        $jslist['rcmfile'.$id] = array('name' => $a_prop['name'], 'complete' => true, 'mimetype' => $a_prop['mimetype']);
     }
   }
 
@@ -814,6 +817,7 @@
   if ($attrib['loadingicon'])
     $OUTPUT->set_env('loadingicon', $CONFIG['skin_path'] . $attrib['loadingicon']);
 
+  $OUTPUT->set_env('attachments', $jslist);
   $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
     
   return html::tag('ul', $attrib, $out, html::$common_attrib);

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list