3 var View
= Backbone
.View
.extend({
9 initialize: function (options
) {
10 this.$el
= $($('#tmpl_channel_list').html().trim());
14 // Sort the table by num. users?
17 // Waiting to add the table back into the DOM?
23 var table
= $('table', this.$el
),
24 tbody
= table
.children('tbody:first').detach(),
26 channels_length
= this.channels
.length
,
29 tbody
.children().each(function (idx
, child
) {
30 if (that
.channels
[idx
].channel
=== $(child
.querySelector('.chan')).data('channel')) {
31 that
.channels
[idx
].dom
= tbody
[0].removeChild(child
);
36 this.channels
.sort(function (a
, b
) {
37 return b
.num_users
- a
.num_users
;
41 for (i
= 0; i
< channels_length
; i
++) {
42 tbody
[0].appendChild(this.channels
[i
].dom
);
44 table
[0].appendChild(tbody
[0]);
51 var Applet
= Backbone
.Model
.extend({
52 initialize: function () {
53 this.set('title', 'Channel List');
54 this.view
= new View();
56 this.network
= _kiwi
.global
.components
.Network();
57 this.network
.on('onlist_channel', this.onListChannel
, this);
58 this.network
.on('onlist_start', this.onListStart
, this);
62 // New channels to add to our list
63 onListChannel: function (event
) {
64 this.addChannel(event
.chans
);
67 // A new, fresh channel list starting
68 onListStart: function (event
) {
69 // TODO: clear out our existing list
72 addChannel: function (channels
) {
75 if (!_
.isArray(channels
)) {
76 channels
= [channels
];
78 _
.each(channels
, function (chan
) {
80 row
= document
.createElement("tr");
81 row
.innerHTML
= '<td><a class="chan" data-channel="' + chan
.channel
+ '">' + _
.escape(chan
.channel
) + '</a></td><td class="num_users" style="text-align: center;">' + chan
.num_users
+ '</td><td style="padding-left: 2em;">' + formatIRCMsg(_
.escape(chan
.topic
)) + '</td>';
83 that
.view
.channels
.push(chan
);
86 if (!that
.view
.waiting
) {
87 that
.view
.waiting
= true;
90 that
.view
.waiting
= false;
96 dispose: function () {
97 this.view
.channels
= null;
99 this.view
.$el
.html('');
103 // Remove any network event bindings
110 _kiwi
.model
.Applet
.register('kiwi_chanlist', Applet
);