From 6f170902580c8cef342c0c65df1b98cbd293a79d Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Mon, 20 Jan 2014 04:18:22 -0500
Subject: [PATCH] Fix row UID handling in list widget

---
 program/js/list.js |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/program/js/list.js b/program/js/list.js
index c026ccb..c822aa4 100644
--- a/program/js/list.js
+++ b/program/js/list.js
@@ -107,11 +107,7 @@
  */
 init_row: function(row)
 {
-  var uid;
-  if (row && (uid = $(row).data('uid')))
-    row.uid = uid;
-  else if (row && String(row.id).match(this.id_regexp))
-    row.uid = RegExp.$1;
+  row.uid = this.get_row_uid(row);
 
   // make references in internal array and set event handlers
   if (row && row.uid) {
@@ -726,6 +722,19 @@
     expando.className = expanded ? 'expanded' : 'collapsed';
 },
 
+get_row_uid: function(row)
+{
+  if (row && row.uid)
+    return row.uid;
+
+  var uid;
+  if (row && (uid = $(row).data('uid')))
+    row.uid = uid;
+  else if (row && String(row.id).match(this.id_regexp))
+    row.uid = RegExp.$1;
+
+  return row.uid;
+},
 
 /**
  * get first/next/previous/last rows that are not hidden
@@ -761,11 +770,11 @@
 get_first_row: function()
 {
   if (this.rowcount) {
-    var i, len, rows = this.tbody.childNodes;
+    var i, len, uid, rows = this.tbody.childNodes;
 
     for (i=0, len=rows.length-1; i<len; i++)
-      if (rows[i].id && String(rows[i].id).match(this.id_regexp) && this.rows[RegExp.$1] != null)
-        return RegExp.$1;
+      if (rows[i].id && (uid = this.get_row_uid(rows[i])))
+        return uid;
   }
 
   return null;
@@ -774,11 +783,11 @@
 get_last_row: function()
 {
   if (this.rowcount) {
-    var i, rows = this.tbody.childNodes;
+    var i, uid, rows = this.tbody.childNodes;
 
     for (i=rows.length-1; i>=0; i--)
-      if (rows[i].id && String(rows[i].id).match(this.id_regexp) && this.rows[RegExp.$1] != null)
-        return RegExp.$1;
+      if (rows[i].id && (uid = this.get_row_uid(rows[i])))
+        return uid;
   }
 
   return null;
@@ -1351,12 +1360,9 @@
 
     // get selected rows (in display order), don't use this.selection here
     $(this.row_tagname() + '.selected', this.tbody).each(function() {
-      if (!String(this.id).match(self.id_regexp))
-        return;
+      var uid = self.get_row_uid(this), row = self.rows[uid];
 
-      var uid = RegExp.$1, row = self.rows[uid];
-
-      if ($.inArray(uid, selection) > -1)
+      if (!uid || $.inArray(uid, selection) > -1)
         return;
 
       selection.push(uid);

--
Gitblit v1.9.1