From 6204390af16bcf50f82da61a1aefc2ad0c0adf94 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Mon, 01 May 2006 10:47:27 -0400
Subject: [PATCH] Applied patch for requesting receipts by Salvatore Ansani

---
 program/js/app.js |   94 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 67 insertions(+), 27 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index d2bf41e..0a57469 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -13,7 +13,6 @@
  
   $Id$
 */
-
 // Constants
 var CONTROL_KEY = 1;
 var SHIFT_KEY = 2;
@@ -29,6 +28,7 @@
   this.gui_objects = new Object();
   this.commands = new Object();
   this.selection = new Array();
+  this.last_selected = 0;
 
   // create public reference to myself
   rcube_webmail_client = this;
@@ -236,7 +236,7 @@
 
     // load body click event
     document.onmousedown = function(){ return rcube_webmail_client.reset_click(); };
-    document.onkeydown   = function(e){ return rcube_webmail_client.use_arrow_keys(e, msg_list_frame); };
+    document.onkeydown   = function(e){ return rcube_webmail_client.key_pressed(e, msg_list_frame); };
 
     
     // flag object as complete
@@ -268,43 +268,49 @@
     e.cancelBubble = true;
     };
 
-  // reset last clicked if user clicks on anything other than the message table
-  this.use_arrow_keys = function(e, msg_list_frame) {
+  this.key_pressed = function(e, msg_list_frame) {
     if (this.in_message_list != true) 
       return true;
-
     var keyCode = document.layers ? e.which : document.all ? event.keyCode : document.getElementById ? e.keyCode : 0;
     var mod_key = this.get_modifier(e);
-    var scroll_to = 0;
-    
-    var last_selected_row = this.list_rows[this.last_selected];
+    switch (keyCode) {
+      case 40:
+      case 38: 
+        return this.use_arrow_key(keyCode, mod_key, msg_list_frame);
+        break;
+      case 46:
+        return this.use_delete_key(keyCode, mod_key, msg_list_frame);
+        break;
+      default:
+        return true;
+    }
+  }
 
+  this.use_arrow_key = function(keyCode, mod_key, msg_list_frame) {
+    var scroll_to = 0;
     if (keyCode == 40) { // down arrow key pressed
-      var new_row = last_selected_row.obj.nextSibling;
-      while (new_row && new_row.nodeType != 1) {
-        new_row = new_row.nextSibling;
-      }
+      new_row = this.get_next_row();
       if (!new_row) return false;
       scroll_to = (Number(new_row.offsetTop) + Number(new_row.offsetHeight)) - Number(msg_list_frame.offsetHeight);
     } else if (keyCode == 38) { // up arrow key pressed
-      var new_row = last_selected_row.obj.previousSibling;
-      while (new_row && new_row.nodeType != 1) {
-        new_row = new_row.previousSibling;
-      }
+      new_row = this.get_prev_row();
       if (!new_row) return false;
       scroll_to = new_row.offsetTop;
     } else {return true;}
 	
-	if (mod_key != CONTROL_KEY)
-	  this.select_row(new_row.uid,mod_key);
+    this.select_row(new_row.uid,mod_key,true);
 
     if (((Number(new_row.offsetTop)) < (Number(msg_list_frame.scrollTop))) || 
        ((Number(new_row.offsetTop) + Number(new_row.offsetHeight)) > (Number(msg_list_frame.scrollTop) + Number(msg_list_frame.offsetHeight)))) {
       msg_list_frame.scrollTop = scroll_to;
     }
-
     return false;
   };
+  
+  this.use_delete_key = function(keyCode, mod_key, msg_list_frame){
+    this.command('delete','',this);
+    return false;
+  }
 
   // get all message rows from HTML table and init each row
   this.init_messagelist = function(msg_list)
@@ -835,14 +841,17 @@
           }
         else if (props)
            url += '&_to='+props;
-        
+
         // don't know if this is necessary...
         url = url.replace(/&_framed=1/, "");
 
         this.set_busy(true);
 
         // need parent in case we are coming from the contact frame
-        parent.window.location.href = url;
+        if (this.env.framed)
+          parent.location.href = url;
+        else
+          location.href = url;
         break;    
 
       case 'send':
@@ -1093,7 +1102,7 @@
     if (!this.in_selection_before)
     {
 	  var mod_key = this.get_modifier(e);
-	  this.select_row(id,mod_key);
+	  this.select_row(id,mod_key,false);
     }
     
     if (this.selection.length)
@@ -1121,7 +1130,7 @@
     
     // unselects currently selected row    
     if (!this.drag_active && this.in_selection_before==id)
-      this.select_row(id,mod_key);
+      this.select_row(id,mod_key,false);
 
     this.drag_start = false;
     this.in_selection_before = false;
@@ -1195,6 +1204,25 @@
   /*********     (message) list functionality      *********/
   /*********************************************************/
 
+  // get next and previous rows that are not hidden
+  this.get_next_row = function(){
+    var last_selected_row = this.list_rows[this.last_selected];
+    var new_row = last_selected_row.obj.nextSibling;
+    while (new_row && (new_row.nodeType != 1 || new_row.style.display == 'none')) {
+      new_row = new_row.nextSibling;
+    }
+    return new_row;
+  }
+  
+  this.get_prev_row = function(){
+    var last_selected_row = this.list_rows[this.last_selected];
+    var new_row = last_selected_row.obj.previousSibling;
+    while (new_row && (new_row.nodeType != 1 || new_row.style.display == 'none')) {
+      new_row = new_row.previousSibling;
+    }
+    return new_row;
+  }
+  
   // highlight/unhighlight a row
   this.highlight_row = function(id, multiple)
     {
@@ -1213,7 +1241,7 @@
       if (!this.in_selection(id))  // select row
         {
         this.selection[this.selection.length] = id;
-        this.set_classname(this.list_rows[id].obj, 'selected', true);        
+        this.set_classname(this.list_rows[id].obj, 'selected', true);    
         }
       else  // unselect row
         {
@@ -1241,7 +1269,7 @@
 
 
 // selects or unselects the proper row depending on the modifier key pressed
-  this.select_row = function(id,mod_key)  { 
+  this.select_row = function(id,mod_key,with_arrow)  { 
   	if (!mod_key) {
       this.shift_start = id;
   	  this.highlight_row(id, false);
@@ -1252,7 +1280,8 @@
           break; }
         case CONTROL_KEY: { 
           this.shift_start = id;
-          this.highlight_row(id, true); 
+		  if (!with_arrow)
+            this.highlight_row(id, true); 
           break; 
           }
         case CONTROL_SHIFT_KEY: { 
@@ -1265,7 +1294,9 @@
           }
       }
 	}
-	this.last_selected = id;
+	if (this.last_selected != 0) { this.set_classname(this.list_rows[this.last_selected].obj, 'focused', false);}
+    this.last_selected = id;
+    this.set_classname(this.list_rows[id].obj, 'focused', true);        
   };
 
   this.shift_select = function(id, control) {
@@ -1370,6 +1401,7 @@
   // list messages of a specific mailbox
   this.list_mailbox = function(mbox, page, sort)
     {
+    this.last_selected = 0;
     var add_url = '';
     var target = window;
 
@@ -1508,6 +1540,10 @@
         if (this.message_rows[id].obj)
           this.message_rows[id].obj.style.display = 'none';
         }
+      next_row = this.get_next_row();
+      prev_row = this.get_prev_row();
+      new_row = (next_row) ? next_row : prev_row;
+      this.select_row(new_row.uid,false,false);
       }
       
     var lock = false;
@@ -1548,6 +1584,10 @@
           this.message_rows[id].obj.style.display = 'none';
         }
       }
+      next_row = this.get_next_row();
+      prev_row = this.get_prev_row();
+      new_row = (next_row) ? next_row : prev_row;
+      this.select_row(new_row.uid,false,false);
 
     // send request to server
     this.http_request('delete', '_uid='+a_uids.join(',')+'&_mbox='+escape(this.env.mailbox)+'&_from='+(this.env.action ? this.env.action : ''));

--
Gitblit v1.9.1