Chanlist applet
authorDarren <darren@darrenwhitlen.com>
Sat, 6 Oct 2012 14:52:58 +0000 (15:52 +0100)
committerDarren <darren@darrenwhitlen.com>
Sat, 6 Oct 2012 14:52:58 +0000 (15:52 +0100)
client_backbone/dev/applet_chanlist.js [new file with mode: 0644]
client_backbone/dev/build.js
client_backbone/dev/model_applet.js
client_backbone/dev/model_application.js
client_backbone/dev/model_gateway.js
client_backbone/dev/model_panel.js
client_backbone/dev/utils.js
client_backbone/index.html

diff --git a/client_backbone/dev/applet_chanlist.js b/client_backbone/dev/applet_chanlist.js
new file mode 100644 (file)
index 0000000..78ac676
--- /dev/null
@@ -0,0 +1,93 @@
+(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
index 58b4c5f9cffde12c0bdabf46f5fb08ca61b45b5d..a8270fa8146b0ce2f173af6fa24b199f064d1f9d 100755 (executable)
@@ -28,6 +28,7 @@ var src = concat([
 \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
index 836c1d1ea70b8a8c103e8e1df96bb48935d6ce2d..cf337e636d2691cb7ae18082bcdd964f5181ae86 100755 (executable)
@@ -3,7 +3,6 @@ kiwi.model.Applet = kiwi.model.Panel.extend({
     // differently than others\r
     applet: true,\r
 \r
-    loaded_applet: null,\r
 \r
     initialize: function (attributes) {\r
         // Temporary name\r
@@ -13,6 +12,9 @@ kiwi.model.Applet = kiwi.model.Panel.extend({
         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
@@ -69,6 +71,11 @@ kiwi.model.Applet = kiwi.model.Panel.extend({
         \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
index d54d0188e4c772cd541157e91efa4cf93fb56e52..23a0bd23b2a3f8473479386d4050160964b84ef5 100755 (executable)
@@ -537,29 +537,30 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
 \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
index 45b2b24ac29bbcd860b8b6fd55384f7319484819..8cd3e876ffac7b84b6aa39d6f0e06882a822e478 100755 (executable)
@@ -152,7 +152,7 @@ kiwi.model.Gateway = function () {
     *   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
index d0b598c299095c883a9451a410cd6be649127618..a14724b2149737e08e76e0ae478b6c7cba8195ce 100755 (executable)
@@ -56,7 +56,9 @@ kiwi.model.Panel = Backbone.Model.extend({
 \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
index 5ba669adec2b5a388b6936b6fb0df49b285e785f..de64451bbf1f583cb1052003bdf23e264dd80473 100755 (executable)
@@ -208,80 +208,6 @@ 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 = $('<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
  */
index 2e63bd7031800178562d3173aed0e8a2b0aa4418..da9da8b2f18baadb4391ecfd65a4f05c61635fe3 100755 (executable)
 
 
     <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'
                 ],
 
                 [