From 7db891ef17eacc5365cd140947ed2e6d5e8dd9ac Mon Sep 17 00:00:00 2001 From: Cory Chaplin Date: Sun, 9 Feb 2014 23:32:54 +0100 Subject: [PATCH] Fix chanlist sorting --- client/src/applets/chanlist.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/client/src/applets/chanlist.js b/client/src/applets/chanlist.js index d54339d..fb3cee3 100644 --- a/client/src/applets/chanlist.js +++ b/client/src/applets/chanlist.js @@ -36,21 +36,17 @@ icon_desc = '  ', i; - tbody.children().each(function (idx, child) { - if (that.channels[idx].channel === $(child.querySelector('.chan')).data('channel')) { - that.channels[idx].dom = tbody[0].removeChild(child); - } - }); - if (override_channels != undefined) { that.channels = override_channels; tbody.remove(); + this.sorting_channels = true; } else { that.channels = this.sortChannels(this.channels, this.order); } // Clean the sorting icon and add the new one - $('#chanlist').find('span').remove(); + $('#chanlist #users').find('span').remove(); + $('#chanlist #channels_name').find('span').remove(); switch (this.order) { case 'user_desc': default: @@ -67,6 +63,12 @@ break; } + tbody.children().each(function (idx, child) { + if (that.channels[idx].channel === $(child.querySelector('.chan')).data('channel')) { + that.channels[idx].dom = tbody[0].removeChild(child); + } + }); + for (i = 0; i < channels_length; i++) { tbody[0].appendChild(this.channels[i].dom); } @@ -120,18 +122,20 @@ }, sortChannelsClick: function(order) { - var that = this; - that.channels = this.sortChannels(this.channels, order); + var that = this, + channels = this.sortChannels(that.channels, order); - this.render(that.channels); + this.render(channels); }, sortChannels: function (channels, order) { var counter = 0, - sort_channels = []; + sort_channels = [], + new_channels = []; + // First we create a light copy of the channels object to do the sorting - _.each(this.channels, function (chan) { + _.each(channels, function (chan) { sort_channels.push({'counter': counter, 'num_users': chan.num_users, 'channel': chan.channel}); counter += 1; @@ -162,7 +166,6 @@ }); // Third, we re-shuffle the chanlist according to the sort order - var new_channels = []; _.each(sort_channels, function (chan) { new_channels.push(channels[chan.counter]); }); @@ -197,6 +200,9 @@ addChannel: function (channels) { var that = this; + // If we're sorting channels, dont rebuild the channel list + if(this.view.sorting_channels) return; + if (!_.isArray(channels)) { channels = [channels]; } -- 2.25.1