icon_desc = '<span class="icon-sort-down"> </span>',\r
i;\r
\r
- tbody.children().each(function (idx, child) {\r
- if (that.channels[idx].channel === $(child.querySelector('.chan')).data('channel')) {\r
- that.channels[idx].dom = tbody[0].removeChild(child);\r
- }\r
- });\r
-\r
if (override_channels != undefined) {\r
that.channels = override_channels;\r
tbody.remove();\r
+ this.sorting_channels = true;\r
} else {\r
that.channels = this.sortChannels(this.channels, this.order);\r
}\r
\r
// Clean the sorting icon and add the new one\r
- $('#chanlist').find('span').remove();\r
+ $('#chanlist #users').find('span').remove();\r
+ $('#chanlist #channels_name').find('span').remove();\r
switch (this.order) {\r
case 'user_desc':\r
default:\r
break;\r
}\r
\r
+ tbody.children().each(function (idx, child) {\r
+ if (that.channels[idx].channel === $(child.querySelector('.chan')).data('channel')) {\r
+ that.channels[idx].dom = tbody[0].removeChild(child);\r
+ }\r
+ });\r
+\r
for (i = 0; i < channels_length; i++) {\r
tbody[0].appendChild(this.channels[i].dom);\r
}\r
},\r
\r
sortChannelsClick: function(order) {\r
- var that = this;\r
- that.channels = this.sortChannels(this.channels, order);\r
+ var that = this,\r
+ channels = this.sortChannels(that.channels, order);\r
\r
- this.render(that.channels);\r
+ this.render(channels);\r
},\r
\r
sortChannels: function (channels, order) {\r
var counter = 0,\r
- sort_channels = [];\r
+ sort_channels = [],\r
+ new_channels = [];\r
+ \r
\r
// First we create a light copy of the channels object to do the sorting\r
- _.each(this.channels, function (chan) {\r
+ _.each(channels, function (chan) {\r
sort_channels.push({'counter': counter, 'num_users': chan.num_users, 'channel': chan.channel});\r
\r
counter += 1;\r
});\r
\r
// Third, we re-shuffle the chanlist according to the sort order\r
- var new_channels = [];\r
_.each(sort_channels, function (chan) {\r
new_channels.push(channels[chan.counter]);\r
});\r
addChannel: function (channels) {\r
var that = this;\r
\r
+ // If we're sorting channels, dont rebuild the channel list\r
+ if(this.view.sorting_channels) return;\r
+\r
if (!_.isArray(channels)) {\r
channels = [channels];\r
}\r