From fba1f5ab813f2eb4bedc5d9c4a75e77bbaa90131 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Mon, 10 Dec 2007 10:27:19 -0500
Subject: [PATCH] New class rcube_user + send message disposition notification

---
 program/js/app.js |  156 +++++++++++++++++++++++++++------------------------
 1 files changed, 82 insertions(+), 74 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 356e27a..f0065ac 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -203,8 +203,11 @@
 
         this.set_page_buttons();
 
-        // focus this window
-        window.focus();
+        // focus main window
+        if (this.env.framed && window.parent)
+          window.parent.focus();
+        else
+          window.focus();
 
         // init message compose form
         if (this.env.action=='compose')
@@ -219,6 +222,16 @@
         {
           this.gui_objects.folderlist = this.gui_objects.mailboxlist;
           this.http_request('getunread', '');
+        }
+        
+        // ask user to send MDN
+        if (this.env.mdn_request && this.env.uid)
+        {
+          var mdnurl = '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox);
+          if (confirm(this.get_label('mdnrequest')))
+            this.http_post('sendmdn', mdnurl);
+          else
+            this.http_post('mark', mdnurl+'&_flag=mdnsent');
         }
 
         break;
@@ -938,8 +951,7 @@
         break;
 
       case 'delete-folder':
-        if (confirm(this.get_label('deletefolderconfirm')))
-          this.delete_folder(props);
+        this.delete_folder(props);
         break;
 
       }
@@ -1141,6 +1153,8 @@
       this.command('show');
     else if (list.key_pressed == list.DELETE_KEY)
       this.command('delete');
+    else
+      list.shiftkey = false;
     };
 
 
@@ -1670,7 +1684,7 @@
     var input_message = rcube_find_object('_message');
 
     // check for empty recipient
-    if (input_to && !rcube_check_email(input_to.value, true))
+    if (input_to && !rcube_check_email(input_to.value.replace(/^\s+/, '').replace(/[\s,;]+$/, ''), true))
       {
       alert(this.get_label('norecipientwarning'));
       input_to.focus();
@@ -2406,10 +2420,20 @@
   this.init_subscription_list = function()
     {
     var p = this;
-    this.subscription_list = new rcube_list_widget(this.gui_objects.subscriptionlist, {multiselect:false, draggable:true, keyboard:false});
+    this.subscription_list = new rcube_list_widget(this.gui_objects.subscriptionlist, {multiselect:false, draggable:true, keyboard:false, toggleselect:true});
     this.subscription_list.addEventListener('select', function(o){ p.subscription_select(o); });
     this.subscription_list.addEventListener('dragstart', function(o){ p.drag_active = true; });
     this.subscription_list.addEventListener('dragend', function(o){ p.subscription_move_folder(o); });
+    this.subscription_list.row_init = function (row)
+      {
+      var anchors = row.obj.getElementsByTagName('A');
+      if (anchors[0])
+        anchors[0].onclick = function() { p.rename_folder(row.id); return false; };
+      if (anchors[1])
+        anchors[1].onclick = function() { p.delete_folder(row.id); return false; };
+      row.obj.onmouseover = function() { p.focus_subscription(row.id); };
+      row.obj.onmouseout = function() { p.unfocus_subscription(row.id); };
+      }
     this.subscription_list.init();
     }
 
@@ -2462,56 +2486,51 @@
 
   this.focus_subscription = function(id)
     {
-    var row;
+    var row, folder;
     var reg = RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
-    if (this.drag_active && this.check_droptarget(id) &&
-        (id != this.env.folder.replace(reg, '')) &&
-        (!id.match(new RegExp('^'+RegExp.escape(this.env.folder+this.env.delimiter)))) &&
-        (row = document.getElementById(this.get_folder_row_id(id))))
-      if (find_in_array(this.env.defaultfolders, id)>=0)
+
+    if (this.drag_active && (row = document.getElementById(id)))
+      if (this.env.subscriptionrows[id] &&
+          (folder = this.env.subscriptionrows[id][0]))
         {
-        if (this.env.folder.replace(reg, '')!='')
+        if (this.check_droptarget(folder) &&
+            (folder != this.env.folder.replace(reg, '')) &&
+            (!folder.match(new RegExp('^'+RegExp.escape(this.env.folder+this.env.delimiter)))))
           {
-          this.set_env('dstfolder', this.env.delimiter);
-          this.set_classname(this.subscription_list.frame, 'droptarget', true);
+          this.set_env('dstfolder', folder);
+          this.set_classname(row, 'droptarget', true);
           }
         }
-      else
+      else if (this.env.folder.match(new RegExp(RegExp.escape(this.env.delimiter))))
         {
-        this.set_env('dstfolder', id);
-        this.set_classname(row, 'droptarget', true);
+        this.set_env('dstfolder', this.env.delimiter);
+        this.set_classname(this.subscription_list.frame, 'droptarget', true);
         }
     }
 
 
   this.unfocus_subscription = function(id)
     {
-    var row;
-    if (row = document.getElementById(this.get_folder_row_id(id)))
-      {
+      var row;
       this.set_env('dstfolder', null);
-      if (find_in_array(this.env.defaultfolders, id)>=0)
-        this.set_classname(this.subscription_list.frame, 'droptarget', false);
-      else
+      if (this.env.subscriptionrows[id] &&
+          (row = document.getElementById(id)))
         this.set_classname(row, 'droptarget', false);
-      }
+      else
+        this.set_classname(this.subscription_list.frame, 'droptarget', false);
     }
 
 
   this.subscription_select = function(list)
     {
-    var id;
-    if (id = list.get_single_selection())
-      {
-      if (this.env.subscriptionrows['rcmrow'+id])
-        {
-        var folder = this.env.subscriptionrows['rcmrow'+id][0];
-        if (find_in_array(this.env.defaultfolders, folder)!=0)
-          this.set_env('folder', folder);
-        }
-      else
-        list.clear_selection();
-      }
+    var id, folder;
+    if ((id = list.get_single_selection()) &&
+        this.env.subscriptionrows['rcmrow'+id] &&
+        (folder = this.env.subscriptionrows['rcmrow'+id][0]) &&
+        (find_in_array(this.env.defaultfolders, folder)!=0))
+      this.set_env('folder', folder);
+    else
+      this.set_env('folder', null);
     };
 
 
@@ -2527,7 +2546,7 @@
       this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.folder)+'&_folder_newname='+urlencode(newname));
       }
     this.drag_active = false;
-    this.unfocus_subscription(this.env.dstfolder);
+    this.unfocus_subscription(this.get_folder_row_id(this.env.dstfolder));
     };
 
 
@@ -2550,23 +2569,11 @@
     };
 
 
-  // entry point for folder renaming
-  this.rename_folder = function(props)
-    {
-    var form, oldname, newname;
-    
-    // rename a specific mailbox
-    if (props)
-      this.edit_foldername(props);
-    };
-
-
-  // start editing the mailbox name.
+  // start renaming the mailbox name.
   // this will replace the name string with an input field
-  this.edit_foldername = function(folder)
+  this.rename_folder = function(id)
     {
     var temp, row, form;
-    var id = this.get_folder_row_id(folder);
 
     // reset current renaming
   if (temp = this.edit_folder)
@@ -2576,14 +2583,15 @@
       return;
     }
 
-    if (id && (row = document.getElementById(id)))
+    if (id && this.env.subscriptionrows[id] && (row = document.getElementById(id)))
       {
       var reg = new RegExp('.*['+RegExp.escape(this.env.delimiter)+']');
       this.name_input = document.createElement('INPUT');
-      this.name_input.value = folder.replace(reg, '');
+      this.name_input.value = this.env.subscriptionrows[id][1].replace(reg, '');
       this.name_input.style.width = '100%';
+      
       reg = new RegExp('['+RegExp.escape(this.env.delimiter)+']?[^'+RegExp.escape(this.env.delimiter)+']+$');
-      this.name_input.setAttribute('parent', folder.replace(reg, ''));
+      this.name_input.__parent = this.env.subscriptionrows[id][0].replace(reg, '');
       this.name_input.onkeypress = function(e){ rcmail.name_input_keypress(e); };
       
       row.cells[0].replaceChild(this.name_input, row.cells[0].firstChild);
@@ -2621,9 +2629,9 @@
       var newname = this.name_input ? this.name_input.value : null;
       if (this.edit_folder && newname)
         {
-        if (this.name_input.getAttribute('parent') && this.name_input.getAttribute('parent')!='')
-          newname = this.name_input.getAttribute('parent')+this.env.delimiter+newname;
-          this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname));
+        if (this.name_input.__parent)
+          newname = this.name_input.__parent + this.env.delimiter + newname;
+        this.http_post('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname));
         }
       }
     // escape
@@ -2633,15 +2641,18 @@
 
 
   // delete a specific mailbox with all its messages
-  this.delete_folder = function(folder)
+  this.delete_folder = function(id)
     {
+    var folder = this.env.subscriptionrows[id][0];
+
     if (this.edit_folder)
       this.reset_folder_rename();
-    
-    if (folder)
-      this.http_post('delete-folder', '_mboxes='+urlencode(folder));
 
-    this.set_env('folder', null);
+    if (folder && confirm(this.get_label('deletefolderconfirm')))
+      {
+      this.http_post('delete-folder', '_mboxes='+urlencode(folder));
+      this.set_env('folder', null);
+      }
     };
 
 
@@ -2658,7 +2669,8 @@
 
     var refrow, form;
     var tbody = this.gui_objects.subscriptionlist.tBodies[0];
-    var id = replace && replace.id ? replace.id : tbody.childNodes.length+1;
+    var id = replace && replace.id ? replace.id : 'rcmrow'+(tbody.childNodes.length+1);
+    var selection = this.subscription_list.get_single_selection();
 
     if (!id || !(refrow = document.getElementById(refid)))
       {
@@ -2669,7 +2681,7 @@
       {
       // clone a table row if there are existing rows
       var row = this.clone_table_row(refrow);
-      row.id = 'rcmrow'+id;
+      row.id = id;
       if (replace)
         tbody.replaceChild(row, replace);
       else
@@ -2687,11 +2699,6 @@
       row.cells[1].firstChild.checked = true;
       }
        
-    if (row.cells[2] && row.cells[2].firstChild.tagName=='A')
-      row.cells[2].firstChild.onclick = new Function(this.ref+".command('rename-folder','"+name.replace('\'','\\\'')+"')");
-    if (row.cells[3] && row.cells[3].firstChild.tagName=='A')
-      row.cells[3].firstChild.onclick = new Function(this.ref+".command('delete-folder','"+name.replace('\'','\\\'')+"')");
-
     // add new folder to rename-folder list and clear input field
     if (!replace && (form = this.gui_objects.editform))
       {
@@ -2703,9 +2710,11 @@
 
     this.sort_subscription_list();
     this.init_subscription_list();
+    if (selection && document.getElementById('rcmrow'+selection))
+      this.subscription_list.select_row(selection);
 
-    if (document.getElementById('rcmrow'+id).scrollIntoView)
-      document.getElementById('rcmrow'+id).scrollIntoView();
+    if (document.getElementById(id).scrollIntoView)
+      document.getElementById(id).scrollIntoView();
     };
 
 
@@ -2717,7 +2726,6 @@
     
     // replace an existing table row (if found)
     this.add_folder_row(newfolder, display_name, row);
-    this.env.subscriptionrows[id] = null;
     
     // rename folder in rename-folder dropdown
     var form, elm;
@@ -3487,7 +3495,7 @@
       }
 
     this.set_busy(true, 'checkingmail');
-    this.http_request('check-recent', '_t='+(new Date().getTime()), true);
+    this.http_request('check-recent', (this.env.search_request ? '_search='+this.env.search_request+'&' : '') + '_t='+(new Date().getTime()), true);
     };
 
 

--
Gitblit v1.9.1