Commit | Line | Data |
---|---|---|
51ae0eb8 D |
1 | (function () {\r |
2 | \r | |
3 | var View = Backbone.View.extend({\r | |
4 | events: {\r | |
5 | },\r | |
6 | \r | |
7 | \r | |
8 | \r | |
9 | initialize: function (options) {\r | |
10 | this.$el = $($('#tmpl_channel_list').html());\r | |
11 | \r | |
12 | this.channels = [];\r | |
13 | \r | |
14 | // Sort the table by num. users?\r | |
15 | this.ordered = false;\r | |
16 | \r | |
17 | // Waiting to add the table back into the DOM?\r | |
18 | this.waiting = false;\r | |
19 | },\r | |
20 | \r | |
21 | \r | |
22 | render: function () {\r | |
23 | var table = $('table', this.$el),\r | |
24 | tbody = table.children('tbody:first').detach();\r | |
25 | /*tbody.children().each(function (child) {\r | |
26 | var i, chan;\r | |
27 | child = $(child);\r | |
28 | chan = child.children('td:first').text();\r | |
29 | for (i = 0; i < chanList.length; i++) {\r | |
30 | if (chanList[i].channel === chan) {\r | |
31 | chanList[i].html = child.detach();\r | |
32 | break;\r | |
33 | }\r | |
34 | }\r | |
35 | });*/\r | |
36 | \r | |
37 | if (this.ordered) {\r | |
38 | this.channels.sort(function (a, b) {\r | |
39 | return b.num_users - a.num_users;\r | |
40 | });\r | |
41 | }\r | |
42 | \r | |
85377d88 D |
43 | _.each(this.channels, function (chan) {\r |
44 | tbody.append(chan.html);\r | |
45 | });\r | |
51ae0eb8 D |
46 | table.append(tbody);\r |
47 | }\r | |
48 | });\r | |
49 | \r | |
50 | \r | |
51 | \r | |
52 | \r | |
eaaf73b0 | 53 | _kiwi.applets.Chanlist = Backbone.Model.extend({\r |
51ae0eb8 D |
54 | initialize: function () {\r |
55 | this.set('title', 'Channel List');\r | |
56 | this.view = new View();\r | |
57 | },\r | |
58 | \r | |
59 | \r | |
60 | addChannel: function (channels) {\r | |
61 | var that = this;\r | |
62 | \r | |
63 | if (!_.isArray(channels)) {\r | |
64 | channels = [channels];\r | |
65 | }\r | |
66 | _.each(channels, function (chan) {\r | |
67 | var html, channel;\r | |
c5f263ae | 68 | html = '<tr><td><a class="chan">' + _.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></tr>';\r |
51ae0eb8 D |
69 | chan.html = html;\r |
70 | that.view.channels.push(chan);\r | |
71 | });\r | |
72 | \r | |
73 | if (!that.view.waiting) {\r | |
74 | that.view.waiting = true;\r | |
75 | _.defer(function () {\r | |
76 | that.view.render();\r | |
77 | that.view.waiting = false;\r | |
78 | });\r | |
79 | }\r | |
80 | },\r | |
81 | \r | |
82 | \r | |
83 | dispose: function () {\r | |
84 | this.view.channels = null;\r | |
85 | this.view.unbind();\r | |
86 | this.view.$el.html('');\r | |
87 | this.view.remove();\r | |
88 | this.view = null;\r | |
89 | }\r | |
90 | });\r | |
91 | \r | |
92 | \r | |
93 | })(); |