From 095d05ef00674553be1d8ee693cfee26fc544510 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 18 Sep 2008 06:14:16 -0400
Subject: [PATCH] #1484805: fix next/last page buttons when new message is added to the list + remove last message

---
 program/js/list.js                  |   53 +++++++++++++++++++++-----
 program/steps/mail/check_recent.inc |    2 +
 program/js/app.js                   |    8 ++++
 3 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index 0f074f3..6ebc556 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3559,6 +3559,14 @@
     row.appendChild(col);
 
     this.message_list.insert_row(row, attop);
+
+    // remove 'old' row
+    if (attop && this.env.pagesize && this.message_list.rowcount > this.env.pagesize)
+      {
+	var uid = this.message_list.get_last_row();
+        this.message_list.remove_row(uid);
+	this.message_list.clear_selection(uid);
+      }
     };
 
 
diff --git a/program/js/list.js b/program/js/list.js
index 926d98a..6abe6a0 100644
--- a/program/js/list.js
+++ b/program/js/list.js
@@ -290,7 +290,7 @@
 
 
 /**
- * get next and previous rows that are not hidden
+ * get next/previous/last rows that are not hidden
  */
 get_next_row: function()
 {
@@ -318,8 +318,24 @@
   return new_row;
 },
 
+get_last_row: function()
+{
+  if (this.rowcount)
+    {
+    var rows = this.list.tBodies[0].rows;
 
-// selects or unselects the proper row depending on the modifier key pressed
+    for(var i=rows.length-1; i>=0; i--)
+      if(rows[i].id && String(rows[i].id).match(/rcmrow([a-z0-9\-_=]+)/i) && this.rows[RegExp.$1] != null)
+	return RegExp.$1;
+    }
+
+  return null;
+},
+
+
+/**
+ * selects or unselects the proper row depending on the modifier key pressed
+ */
 select_row: function(id, mod_key, with_mouse)
 {
   var select_before = this.selection.join(',');
@@ -482,21 +498,36 @@
 
 
 /**
- * Unselect all selected rows
+ * Unselect selected row(s)
  */
-clear_selection: function()
+clear_selection: function(id)
 {
   var num_select = this.selection.length;
-  for (var n=0; n<this.selection.length; n++)
-    if (this.rows[this.selection[n]])
+
+  // one row
+  if (id)
     {
-      this.set_classname(this.rows[this.selection[n]].obj, 'selected', false);
-      this.set_classname(this.rows[this.selection[n]].obj, 'unfocused', false);
+    for (var n=0; n<this.selection.length; n++)
+      if (this.selection[n] == id)
+        {
+	this.selection.splice(n,1);
+    	break;
+	}
+    }
+  // all rows
+  else
+    {
+    for (var n=0; n<this.selection.length; n++)
+      if (this.rows[this.selection[n]])
+        {
+        this.set_classname(this.rows[this.selection[n]].obj, 'selected', false);
+        this.set_classname(this.rows[this.selection[n]].obj, 'unfocused', false);
+        }
+    
+    this.selection = new Array();
     }
 
-  this.selection = new Array();
-  
-  if (num_select)
+  if (num_select && !this.selection.length)
     this.trigger_event('select');
 },
 
diff --git a/program/steps/mail/check_recent.inc b/program/steps/mail/check_recent.inc
index dee8ca6..e84d7ba 100644
--- a/program/steps/mail/check_recent.inc
+++ b/program/steps/mail/check_recent.inc
@@ -35,6 +35,8 @@
       $unread_count = $IMAP->messagecount(NULL, 'UNSEEN', TRUE);
 
       $OUTPUT->set_env('messagecount', $IMAP->messagecount());
+      $OUTPUT->set_env('pagesize', $IMAP->page_size);
+      $OUTPUT->set_env('pagecount', ceil($IMAP->messagecount()/$IMAP->page_size));
       $OUTPUT->command('set_unread_count', $mbox_name, $unread_count, ($mbox_name == 'INBOX'));
       $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text());
       $OUTPUT->command('set_quota', rcmail_quota_content($IMAP->get_quota()));

--
Gitblit v1.9.1