From 254d5ef32b7ec45a48abd43f19c84168dabe13d1 Mon Sep 17 00:00:00 2001 From: alecpl Date: Fri, 20 May 2011 10:38:44 +0000 Subject: - Improve performence of folder manager operations by moving subscriptions table operations (like adding/updateing/moving folders) into client-side - no need to invoke LIST, do sorting in browser - This change should also handle better situations when working with replicated IMAP backend (e.g.Cyrus Murder) --- program/js/app.js | 261 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 168 insertions(+), 93 deletions(-) (limited to 'program/js/app.js') diff --git a/program/js/app.js b/program/js/app.js index a114c80d6..ea54b0b78 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -4016,7 +4016,6 @@ function rcube_webmail() this.triggerEvent('group_update', { id:prop.id, source:prop.source, name:prop.name, li:li[0], newid:prop.newid }); }; - this.init_edit_field = function(col, elem) { if (!elem) @@ -4179,21 +4178,6 @@ function rcube_webmail() /********* user settings methods *********/ /*********************************************************/ - 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, 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) { - row.obj.onmouseover = function() { p.focus_subscription(row.id); }; - row.obj.onmouseout = function() { p.unfocus_subscription(row.id); }; - }; - this.subscription_list.init(); - }; - // preferences section select and load options frame this.section_select = function(list) { @@ -4258,6 +4242,26 @@ function rcube_webmail() return true; }; + + /*********************************************************/ + /********* folder manager methods *********/ + /*********************************************************/ + + 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, 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) { + row.obj.onmouseover = function() { p.focus_subscription(row.id); }; + row.obj.onmouseout = function() { p.unfocus_subscription(row.id); }; + }; + this.subscription_list.init(); + }; + this.focus_subscription = function(id) { var row, folder, @@ -4347,91 +4351,183 @@ function rcube_webmail() } }; - // add a new folder to the subscription list by cloning a folder row - this.add_folder_row = function(name, display_name, replace, before) + // Add folder row to the table and initialize it + this.add_folder_row = function (name, display_name, protected, subscribed, skip_init) { if (!this.gui_objects.subscriptionlist) return false; - // find not protected folder - var refid; - for (var rid in this.env.subscriptionrows) { - if (this.env.subscriptionrows[rid]!=null && !this.env.subscriptionrows[rid][2]) { - refid = rid; - break; - } - } - - var refrow, form, + var row, n, i, tmp, folders, len, list = [], slist = [], tbody = this.gui_objects.subscriptionlist.tBodies[0], - id = 'rcmrow'+(tbody.childNodes.length+1), - selection = this.subscription_list.get_single_selection(); - - if (replace && replace.id) { - id = replace.id; - refid = replace.id; - } + refrow = $('tr', tbody).get(0), + id = 'rcmrow'+((new Date).getTime()); - if (!id || !refid || !(refrow = document.getElementById(refid))) { + if (!refrow) { // Refresh page if we don't have a table row to clone this.goto_url('folders'); return false; } // clone a table row if there are existing rows - var row = this.clone_table_row(refrow); - row.id = id; + row = $(refrow).clone(true); + row.attr('id', id); - if (before && (before = this.get_folder_row_id(before))) - tbody.insertBefore(row, document.getElementById(before)); - else - tbody.appendChild(row); + // set folder name + row.find('td:first').html(display_name); - if (replace) - tbody.removeChild(replace); + // update subscription checkbox + $('input[name="_subscribed[]"]', row).val(name) + .prop({checked: subscribed ? true : false, disabled: protected ? true : false}); // add to folder/row-ID map - this.env.subscriptionrows[row.id] = [name, display_name, 0]; + this.env.subscriptionrows[id] = [name, display_name, 0]; + + // sort folders, to find a place where to insert the row + folders = this.env.subscriptionrows; + for (n in folders) { + // protected folder + if (folders[n][2]) { + slist.push(folders[n][0]); + tmp = folders[n][0]+this.env.delimiter; + } + // protected folder's child + else if (tmp && folders[n][0].indexOf(tmp) == 0) + slist.push(folders[n][0]); + // other + else { + list.push(folders[n][0]); + tmp = null; + } + } + list.sort(); + // make sure protected folders (and their subs) are on top + list = slist.concat(list); - // set folder name - row.cells[0].innerHTML = display_name; + // find folder position after sorting + for (n=0, len=list.length; n 0) { + for (i=level; i>0; i--) + dispname = dispname.replace(/^    /, ''); + } + else { + for (i=level; i<0; i++) + dispname = '    ' + dispname; + } + row.find('td:first').html(dispname); + this.env.subscriptionrows[id][1] = dispname; + } + } + + // update list widget + this.init_subscription_list(); }; // remove the table row of a specific mailbox from the table - // (the row will not be removed, just hidden) - this.remove_folder_row = function(folder) + this.remove_folder_row = function(folder, subs) { - var row, id = this.get_folder_row_id(folder); + var n, len, list = [], id = this.get_folder_row_id(folder); + + // get subfolders if any + if (subs) + list = this.get_subfolders(folder); + + // remove old row + this._remove_folder_row(id); - if (id && (row = document.getElementById(id))) - row.style.display = 'none'; + // remove subfolders + for (n=0, len=list.length; n