--- /dev/null
+(function () {\r
+\r
+ var View = Backbone.View.extend({\r
+ events: {\r
+ },\r
+\r
+\r
+\r
+ initialize: function (options) {\r
+ this.$el = $($('#tmpl_channel_list').html());\r
+\r
+ this.channels = [];\r
+\r
+ // Sort the table by num. users?\r
+ this.ordered = false;\r
+\r
+ // Waiting to add the table back into the DOM?\r
+ this.waiting = false;\r
+ },\r
+\r
+\r
+ render: function () {\r
+ var table = $('table', this.$el),\r
+ tbody = table.children('tbody:first').detach();\r
+ /*tbody.children().each(function (child) {\r
+ var i, chan;\r
+ child = $(child);\r
+ chan = child.children('td:first').text();\r
+ for (i = 0; i < chanList.length; i++) {\r
+ if (chanList[i].channel === chan) {\r
+ chanList[i].html = child.detach();\r
+ break;\r
+ }\r
+ }\r
+ });*/\r
+\r
+ if (this.ordered) {\r
+ this.channels.sort(function (a, b) {\r
+ return b.num_users - a.num_users;\r
+ });\r
+ }\r
+\r
+ //_.each(this.channels, function (chan) {\r
+ // tbody.append(chan.html);\r
+ //});\r
+ table.append(tbody);\r
+ }\r
+ });\r
+\r
+\r
+\r
+\r
+ kiwi.applets.Chanlist = Backbone.Model.extend({\r
+ initialize: function () {\r
+ this.set('title', 'Channel List');\r
+ this.view = new View();\r
+ },\r
+\r
+\r
+ addChannel: function (channels) {\r
+ var that = this;\r
+\r
+ if (!_.isArray(channels)) {\r
+ channels = [channels];\r
+ }\r
+ _.each(channels, function (chan) {\r
+ var html, channel;\r
+ html = '<tr><td><a class="chan">' + chan.channel + '</a></td><td class="num_users" style="text-align: center;">' + chan.num_users + '</td><td style="padding-left: 2em;">' + formatIRCMsg(chan.topic) + '</td></tr>';\r
+ chan.html = html;\r
+ that.view.channels.push(chan);\r
+ });\r
+\r
+ if (!that.view.waiting) {\r
+ that.view.waiting = true;\r
+ _.defer(function () {\r
+ that.view.render();\r
+ that.view.waiting = false;\r
+ });\r
+ }\r
+ },\r
+\r
+\r
+ dispose: function () {\r
+ this.view.channels = null;\r
+ this.view.unbind();\r
+ this.view.$el.html('');\r
+ this.view.remove();\r
+ this.view = null;\r
+ }\r
+ });\r
+\r
+\r
+})();
\ No newline at end of file
\r
__dirname + '/applet_settings.js',\r
__dirname + '/applet_nickserv.js',\r
+ __dirname + '/applet_chanlist.js',\r
\r
__dirname + '/utils.js',\r
__dirname + '/view.js'\r
// differently than others\r
applet: true,\r
\r
- loaded_applet: null,\r
\r
initialize: function (attributes) {\r
// Temporary name\r
this.set({\r
"name": name\r
}, {"silent": true});\r
+\r
+ // Holds the loaded applet\r
+ this.loaded_applet = null;\r
},\r
\r
// Load an applet within this panel\r
\r
this.view = undefined;\r
\r
+ // Call the applets dispose method if it has one\r
+ if (this.loaded_applet && this.loaded_applet.dispose) {\r
+ this.loaded_applet.dispose();\r
+ }\r
+\r
this.closePanel();\r
}\r
});
\ No newline at end of file
\r
gw.on('onlist_start', function (data) {\r
if (kiwi.app.channel_list) {\r
- kiwi.app.channel_list.view.remove();\r
+ kiwi.app.channel_list.close();\r
delete kiwi.app.channel_list;\r
}\r
\r
var panel = new kiwi.model.Applet(),\r
- list = new ChannelList();\r
+ applet = new kiwi.applets.Chanlist();\r
\r
- panel.set('title', 'Channel List');\r
- panel.view.$el.append(list.view);\r
+ panel.load(applet);\r
\r
kiwi.app.panels.add(panel);\r
panel.view.show();\r
\r
- kiwi.app.channel_list = list;\r
+ kiwi.app.channel_list = applet;\r
});\r
\r
\r
gw.on('onlist_channel', function (data) {\r
+ // TODO: Put this listener within the applet itself\r
kiwi.app.channel_list.addChannel(data.chans);\r
});\r
\r
\r
gw.on('onlist_end', function (data) {\r
+ // TODO: Put this listener within the applet itself\r
delete kiwi.app.channel_list;\r
});\r
\r
* Parses the response from the server\r
*/\r
this.parse = function (command, data) {\r
- console.log('gateway event', command, data);\r
+ //console.log('gateway event', command, data);\r
if (command !== undefined) {\r
that.trigger('on' + command, data);\r
\r
\r
closePanel: function () {\r
if (this.view) {\r
+ this.view.unbind();\r
this.view.remove();\r
+ this.view = undefined;\r
delete this.view;\r
}\r
\r
-
-
-
-
-
-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 = $('<tr><td><a class="chan">' + chan.channel + '</a></td><td class="num_users" style="text-align: center;">' + chan.num_users + '</td><td style="padding-left: 2em;">' + formatIRCMsg(chan.topic) + '</td></tr>');
- 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
*/
<script type="text/x=x-jquery-tmpl" id="tmpl_channel_list">
- <table style="margin:1em 2em;">
- <thead style="font-weight: bold;">
- <tr>
- <td>Channel Name</td>
- <td>Users</td>
- <td style="padding-left: 2em;">Topic</td>
- </tr>
- </thead>
- <tbody style="vertical-align: top;">
- </tbody>
- </table>
+ <div>
+ <table style="margin:1em 2em;">
+ <thead style="font-weight: bold;">
+ <tr>
+ <td>Channel Name</td>
+ <td>Users</td>
+ <td style="padding-left: 2em;">Topic</td>
+ </tr>
+ </thead>
+ <tbody style="vertical-align: top;">
+ </tbody>
+ </table>
+ </div>
</script>
[
'dev/applet_settings.js',
- 'dev/applet_nickserv.js'
+ 'dev/applet_nickserv.js',
+ 'dev/applet_chanlist.js'
],
[