From b649c49e64a487ac8ad347aed42336dec2e74cd7 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 25 Feb 2011 04:16:05 -0500
Subject: [PATCH] - Fix attachments uploading, broken with devel-addressbook branch merge

---
 program/js/app.js |   50 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 43be6ae..92b7a67 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3190,7 +3190,7 @@
 
     // create hidden iframe and post upload form
     if (send) {
-      this.async_upload_form(form, 'upload', function(e) {
+      var frame_name = this.async_upload_form(form, 'upload', function(e) {
         var d, content = '';
         try {
           if (this.contentDocument) {
@@ -3199,7 +3199,7 @@
             d = this.contentWindow.document;
           }
           content = d.childNodes[0].innerHTML;
-        } catch (e) {}
+        } catch (err) {}
 
         if (!content.match(/add2attachment/) && (!bw.opera || (rcmail.env.uploadframe && rcmail.env.uploadframe == e.data.ts))) {
           if (!content.match(/display_message/))
@@ -3212,7 +3212,9 @@
       });
 
       // display upload indicator and cancel button
-      var content = this.get_label('uploading');
+      var content = this.get_label('uploading'),
+        ts = frame_name.replace(/^rcmupload/, '');
+
       if (this.env.loadingicon)
         content = '<img src="'+this.env.loadingicon+'" alt="" />'+content;
       if (this.env.cancelicon)
@@ -3486,15 +3488,14 @@
     if (q == this.ksearch_value)
       return;
 
-    if (q.length < min) {
+    if (q.length && q.length < min) {
       if (!this.env.acinfo) {
-        var label = this.get_label('autocompletechars');
-        label = label.replace('$min', min);
-        this.env.acinfo = this.display_message(label);
+        this.env.acinfo = this.display_message(
+          this.get_label('autocompletechars').replace('$min', min));
       }
       return;
     }
-    else if (this.env.acinfo && q.length == min) {
+    else if (this.env.acinfo) {
       this.hide_message(this.env.acinfo);
     }
 
@@ -3948,6 +3949,7 @@
     this.env.contactfolders[key] = this.env.contactgroups[key] = prop;
 
     var link = $('<a>').attr('href', '#')
+      .attr('rel', prop.source+':'+prop.id)
       .bind('click', function() { return rcmail.command('listgroup', prop, this);})
       .html(prop.name);
     var li = $('<li>').attr('id', 'rcmli'+key.replace(this.identifier_expr, '_'))
@@ -3963,13 +3965,33 @@
   {
     this.reset_add_input();
 
-    var key = 'G'+prop.source+prop.id, link, li = this.get_folder_li(key);
+    var key = 'G'+prop.source+prop.id,
+      li = this.get_folder_li(key),
+      link;
 
-    if (li && (link = li.firstChild) && link.tagName.toLowerCase() == 'a')
+    // group ID has changed, replace link node and identifiers
+    if (li && prop.newid) {
+      var newkey = 'G'+prop.source+prop.newid;
+      li.id = String('rcmli'+newkey).replace(this.identifier_expr, '_');
+      this.env.contactfolders[newkey] = this.env.contactfolders[key];
+      this.env.group = prop.newid;
+      
+      var newprop = $.extend({}, prop);
+      newprop.id = prop.newid;
+      newprop.type = 'group';
+      
+      link = $('<a>').attr('href', '#')
+        .attr('rel', prop.source+':'+prop.newid)
+        .bind('click', function() { return rcmail.command('listgroup', newprop, this);})
+        .html(prop.name);
+      $(li).children().replaceWith(link);
+    }
+    // update displayed group name
+    else if (li && (link = li.firstChild) && link.tagName.toLowerCase() == 'a')
       link.innerHTML = prop.name;
 
     this.env.contactfolders[key].name = this.env.contactgroups[key].name = prop.name;
-    this.triggerEvent('group_update', { id:prop.id, source:prop.source, name:prop.name, li:li[0] });
+    this.triggerEvent('group_update', { id:prop.id, source:prop.source, name:prop.name, li:li[0], newid:prop.newid });
   };
 
 
@@ -5353,8 +5375,8 @@
   // post the given form to a hidden iframe
   this.async_upload_form = function(form, action, onload)
   {
-    var ts = new Date().getTime();
-    var frame_name = 'rcmupload'+ts;
+    var ts = new Date().getTime(),
+      frame_name = 'rcmupload'+ts;
 
     // have to do it this way for IE
     // otherwise the form will be posted to a new window
@@ -5379,6 +5401,8 @@
     form.action = this.url(action, { _uploadid:ts });
     form.setAttribute('enctype', 'multipart/form-data');
     form.submit();
+
+    return frame_name;
   };
   
   // starts interval for keep-alive/check-recent signal

--
Gitblit v1.9.1