summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-11-21 13:10:25 +0100
committerAleksander Machniak <alec@alec.pl>2013-11-21 13:10:25 +0100
commit5bd8712f71d5f5c62bb278da32e3f175ed96de36 (patch)
treeff5bbd7cf67cd0bd52d74a43055b0c7e334ae41d
parent75e52852dda9048d801b2b9738898f0326bf3be8 (diff)
Fix folders sorting procedure.
Fixes the issue where after creating a folder with name 'Abc abc' it were added before existing subfolders of folder 'Abc' and after 'Abc'.
-rw-r--r--program/js/app.js24
1 files changed, 17 insertions, 7 deletions
diff --git a/program/js/app.js b/program/js/app.js
index f36a3caa8..1f8efde03 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -5732,7 +5732,7 @@ function rcube_webmail()
if (!this.gui_objects.subscriptionlist)
return false;
- var row, n, i, tmp, tmp_name, folders, rowid, list = [], slist = [],
+ var row, n, i, tmp, tmp_name, rowid, folders = [], list = [], slist = [],
tbody = this.gui_objects.subscriptionlist.tBodies[0],
refrow = $('tr', tbody).get(1),
id = 'rcmrow'+((new Date).getTime());
@@ -5747,8 +5747,7 @@ function rcube_webmail()
row = $(refrow).clone(true);
// set ID, reset css class
- row.attr('id', id);
- row.attr('class', class_name);
+ row.attr({id: id, 'class': class_name});
// set folder name
row.find('td:first').html(display_name);
@@ -5760,10 +5759,21 @@ function rcube_webmail()
// add to folder/row-ID map
this.env.subscriptionrows[id] = [name, display_name, 0];
- // sort folders, to find a place where to insert the row
- folders = [];
- $.each(this.env.subscriptionrows, function(k,v){ folders.push(v) });
- folders.sort(function(a,b){ return a[0] < b[0] ? -1 : (a[0] > b[0] ? 1 : 0) });
+ // sort folders (to find a place where to insert the row)
+ // replace delimiter with \0 character to fix sorting
+ // issue where 'Abc Abc' would be placed before 'Abc/def'
+ var replace_from = RegExp(RegExp.escape(this.env.delimiter), 'g'),
+ replace_to = String.fromCharCode(0);
+ $.each(this.env.subscriptionrows, function(k,v) {
+ var n = v[0];
+ n = n.replace(replace_from, replace_to);
+ v.push(n);
+ folders.push(v);
+ });
+ folders.sort(function(a, b) {
+ var len = a.length - 1; n1 = a[len], n2 = b[len];
+ return n1 < n2 ? -1 : 1;
+ });
for (n in folders) {
// protected folder