Basic channel listing
authorDarren <darren@darrenwhitlen.com>
Mon, 17 Sep 2012 17:06:11 +0000 (18:06 +0100)
committerDarren <darren@darrenwhitlen.com>
Mon, 17 Sep 2012 17:06:11 +0000 (18:06 +0100)
client_backbone/dev/model_application.js
client_backbone/dev/utils.js
client_backbone/dev/view.js
client_backbone/index.html

index 672ec7dd083a3a475994ca01806f54e84f63b21f..4af03bab105c28dff4cf21be3c595eea8f0d47f5 100644 (file)
@@ -426,6 +426,35 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         });\r
 \r
 \r
+        gw.on('onlist_start', function (data) {\r
+            if (kiwi.app.channel_list) {\r
+                kiwi.app.channel_list.view.remove();\r
+                delete kiwi.app.channel_list;\r
+            }\r
+\r
+            var panel = new kiwi.model.Applet(),\r
+                list = new ChannelList();\r
+\r
+            panel.set('title', 'Channel List');\r
+            panel.view.$el.append(list.view);\r
+            \r
+            kiwi.app.panels.add(panel);\r
+            panel.view.show();\r
+\r
+            kiwi.app.channel_list = list;\r
+        });\r
+\r
+\r
+        gw.on('onlist_channel', function (data) {\r
+            kiwi.app.channel_list.addChannel(data.chans);\r
+        });\r
+\r
+\r
+        gw.on('onlist_end', function (data) {\r
+            delete kiwi.app.channel_list;\r
+        });\r
+\r
+\r
         gw.on('onirc_error', function (data) {\r
             var panel, tmp;\r
 \r
index 26f164e42806cfe2de475bbcbe871de246889cec..a62872f57ff877b0cfdde9a3c3a507ce991cb363 100644 (file)
@@ -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 = $('<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 80bde051d87c3c9e5e0abbded21c324809701126..4e0be2ae77e854210e9fe20ba79915c1d992d3cd 100644 (file)
@@ -260,11 +260,12 @@ kiwi.view.Panel = Backbone.View.extend({
         // Show this panels memberlist\r
         var members = this.model.get("members");\r
         if (members) {\r
+            $('#memberlists').show();\r
             members.view.show();\r
             this.$container.parent().css('right', '200px');\r
         } else {\r
             // Memberlist not found for this panel, hide any active ones\r
-            $('#memberlists').children().removeClass('active');\r
+            $('#memberlists').hide().children().removeClass('active');\r
             this.$container.parent().css('right', '0');\r
         }\r
 \r
index 47bdd9f5288c80c3325b4561872507467147cd08..d771d9056c33ae63095e8ead98e3e394ca6752fa 100644 (file)
     </script>
 
 
+    <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>
+    </script>
+
+
 <script>
 /* Script loader (https://github.com/ded/script.js) */
 (function(a,b,c){typeof c["module"]!="undefined"&&c.module.exports?c.module.exports=b():typeof c["define"]!="undefined"&&c["define"]=="function"&&c.define.amd?define(a,b):c[a]=b()})("$script",function(){function p(a,b){for(var c=0,d=a.length;c<d;++c)if(!b(a[c]))return j;return 1}function q(a,b){p(a,function(a){return!b(a)})}function r(a,b,i){function o(a){return a.call?a():d[a]}function t(){if(!--n){d[m]=1,l&&l();for(var a in f)p(a.split("|"),o)&&!q(f[a],o)&&(f[a]=[])}}a=a[k]?a:[a];var j=b&&b.call,l=j?b:i,m=j?a.join(""):b,n=a.length;return setTimeout(function(){q(a,function(a){if(h[a])return m&&(e[m]=1),h[a]==2&&t();h[a]=1,m&&(e[m]=1),s(!c.test(a)&&g?g+a+".js":a,t)})},0),r}function s(c,d){var e=a.createElement("script"),f=j;e.onload=e.onerror=e[o]=function(){if(e[m]&&!/^c|loade/.test(e[m])||f)return;e.onload=e[o]=null,f=1,h[c]=2,d()},e.async=1,e.src=c,b.insertBefore(e,b.firstChild)}var a=document,b=a.getElementsByTagName("head")[0],c=/^https?:\/\//,d={},e={},f={},g,h={},i="string",j=!1,k="push",l="DOMContentLoaded",m="readyState",n="addEventListener",o="onreadystatechange";return!a[m]&&a[n]&&(a[n](l,function t(){a.removeEventListener(l,t,j),a[m]="complete"},j),a[m]="loading"),r.get=s,r.order=function(a,b,c){(function d(e){e=a.shift(),a.length?r(e,d):r(e,b,c)})()},r.path=function(a){g=a},r.ready=function(a,b,c){a=a[k]?a:[a];var e=[];return!q(a,function(a){d[a]||e[k](a)})&&p(a,function(a){return d[a]})?b():!function(a){f[a]=f[a]||[],f[a][k](b),c&&c(e)}(a.join("|")),r},r},this)