From: Darren Date: Mon, 17 Sep 2012 17:06:11 +0000 (+0100) Subject: Basic channel listing X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=21536e7be7166129a27c03d44ecb5049bb70397e;p=KiwiIRC.git Basic channel listing --- diff --git a/client_backbone/dev/model_application.js b/client_backbone/dev/model_application.js index 672ec7d..4af03ba 100644 --- a/client_backbone/dev/model_application.js +++ b/client_backbone/dev/model_application.js @@ -426,6 +426,35 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { }); + gw.on('onlist_start', function (data) { + if (kiwi.app.channel_list) { + kiwi.app.channel_list.view.remove(); + delete kiwi.app.channel_list; + } + + var panel = new kiwi.model.Applet(), + list = new ChannelList(); + + panel.set('title', 'Channel List'); + panel.view.$el.append(list.view); + + kiwi.app.panels.add(panel); + panel.view.show(); + + kiwi.app.channel_list = list; + }); + + + gw.on('onlist_channel', function (data) { + kiwi.app.channel_list.addChannel(data.chans); + }); + + + gw.on('onlist_end', function (data) { + delete kiwi.app.channel_list; + }); + + gw.on('onirc_error', function (data) { var panel, tmp; diff --git a/client_backbone/dev/utils.js b/client_backbone/dev/utils.js index 26f164e..a62872f 100644 --- a/client_backbone/dev/utils.js +++ b/client_backbone/dev/utils.js @@ -204,6 +204,84 @@ function InputPreProcessor () { + + + + + + + + + +function ChannelList () { + /*globals Utilityview */ + var chanList, view, table, obj, renderTable, waiting; + chanList = []; + + view = $($('#tmpl_channel_list').html()); + table = view; //$('table', view); + + waiting = false; + /** + * @inner + */ + renderTable = function () { + var tbody; + tbody = table.children('tbody:first').detach(); + /*tbody.children().each(function (child) { + var i, chan; + child = $(child); + chan = child.children('td:first').text(); + for (i = 0; i < chanList.length; i++) { + if (chanList[i].channel === chan) { + chanList[i].html = child.detach(); + break; + } + } + });*/ + _.each(chanList, function (chan) { + chan.html = $(chan.html).appendTo(tbody); + }); + table = table.append(tbody); + waiting = false; + }; + /** + * @lends ChannelList + */ + return { + /** + * Adds a channel or channels to the list + * @param {Object} channels The channel or Array of channels to add + */ + addChannel: function (channels) { + if (!_.isArray(channels)) { + channels = [channels]; + } + _.each(channels, function (chan) { + var html, channel; + html = $('' + chan.channel + '' + chan.num_users + '' + formatIRCMsg(chan.topic) + ''); + chan.html = html; + chanList.push(chan); + }); + chanList.sort(function (a, b) { + return b.num_users - a.num_users; + }); + if (!waiting) { + waiting = true; + _.defer(renderTable); + } + }, + + view: view + }; +} + + + + + + + /** * Convert HSL to RGB formatted colour */ diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index 80bde05..4e0be2a 100644 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -260,11 +260,12 @@ kiwi.view.Panel = Backbone.View.extend({ // Show this panels memberlist var members = this.model.get("members"); if (members) { + $('#memberlists').show(); members.view.show(); this.$container.parent().css('right', '200px'); } else { // Memberlist not found for this panel, hide any active ones - $('#memberlists').children().removeClass('active'); + $('#memberlists').hide().children().removeClass('active'); this.$container.parent().css('right', '0'); } diff --git a/client_backbone/index.html b/client_backbone/index.html index 47bdd9f..d771d90 100644 --- a/client_backbone/index.html +++ b/client_backbone/index.html @@ -86,6 +86,21 @@ + + +