Multiple network tabs working
authorDarren <darren@Darrens-MacBook-Pro.local>
Sun, 21 Apr 2013 14:19:44 +0000 (15:19 +0100)
committerDarren <darren@Darrens-MacBook-Pro.local>
Sun, 21 Apr 2013 14:19:44 +0000 (15:19 +0100)
client/assets/dev/model_application.js
client/assets/dev/model_network.js
client/assets/dev/model_panellist.js
client/assets/dev/view.js

index 17815c340faec3e83b67366a48c37a17421fadda..f6d4fd98d199ac453a727071a99093395355de0c 100644 (file)
@@ -735,6 +735,17 @@ _kiwi.model.Application = function () {
             return (channel_prefix.indexOf(channel_name[0]) > -1);\r
         };\r
 \r
+\r
+\r
+        this.eachPanel = function (fn) {\r
+            if (typeof fn !== 'function')\r
+                return;\r
+\r
+            _.each(this.connections, function(connection) {\r
+                _.each(connection.panels.model, fn);\r
+            });\r
+        }\r
+\r
     };\r
 \r
 \r
index 02a2eb2e3c54e9c9a3c937f7f82b927a29cc6bab..56f64ccf9c56b0d8e9feb3ba797d6a26074167f5 100644 (file)
@@ -39,7 +39,7 @@
             this.gateway = _kiwi.global.components.Network(this.get('connection_id'));
             this.bindGatewayEvents();
 
-            this.panels = new _kiwi.model.PanelList();
+            this.panels = new _kiwi.model.PanelList(this);
         },
 
 
index cd43e19f931af844b5b8c2952afbb2f4e7d43b74..d48043eaf979c32accc7886cb759d490b7f33115 100644 (file)
@@ -4,8 +4,12 @@ _kiwi.model.PanelList = Backbone.Collection.extend({
     comparator: function (chan) {\r
         return chan.get('name');\r
     },\r
-    initialize: function () {\r
-        this.view = new _kiwi.view.Tabs({el: $('#tabs')[0], model: this});\r
+    initialize: function (network) {\r
+\r
+        // The network this PanelList is associated with\r
+        this.network = network;\r
+\r
+        this.view = new _kiwi.view.Tabs({model: this});\r
 \r
         // Automatically create a server tab\r
         var server_panel = new _kiwi.model.Server({name: 'Server'});\r
index d9522a1e6783d561ff63d0b24efbe026a3721a9a..cc4513bf0692225487a5e5f32c3bd17d45afcc4b 100644 (file)
@@ -619,6 +619,8 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
 \r
 // Model for this = _kiwi.model.PanelList\r
 _kiwi.view.Tabs = Backbone.View.extend({\r
+    tagName: 'ul',\r
+\r
     events: {\r
         'click li': 'tabClick',\r
         'click li .part': 'partClick'\r
@@ -634,10 +636,13 @@ _kiwi.view.Tabs = Backbone.View.extend({
         this.tabs_applets = $('ul.applets', this.$el);\r
         this.tabs_msg = $('ul.channels', this.$el);\r
 \r
-        _kiwi.gateway.on('change:name', function (gateway, new_val) {\r
+        this.model.network.on('change:name', function (network, new_val) {\r
             $('span', this.model.server.tab).text(new_val);\r
         }, this);\r
+\r
+        $('#kiwi .panellist.channels').append(this.$el);\r
     },\r
+\r
     render: function () {\r
         var that = this;\r
 \r
@@ -645,7 +650,7 @@ _kiwi.view.Tabs = Backbone.View.extend({
         \r
         // Add the server tab first\r
         this.model.server.tab\r
-            .data('panel_id', this.model.server.cid)\r
+            .data('panel', this.model.server)\r
             .appendTo(this.tabs_msg);\r
 \r
         // Go through each panel adding its tab\r
@@ -654,8 +659,9 @@ _kiwi.view.Tabs = Backbone.View.extend({
             if (panel == that.model.server) return;\r
 \r
             panel.tab\r
-                .data('panel_id', panel.cid)\r
-                .appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg);\r
+                .data('panel', panel)\r
+                .appendTo(that.$el);\r
+                //.appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg);\r
         });\r
 \r
         _kiwi.app.view.doLayout();\r
@@ -673,8 +679,9 @@ _kiwi.view.Tabs = Backbone.View.extend({
             panel.tab.addClass('server');\r
         }\r
 \r
-        panel.tab.data('panel_id', panel.cid)\r
-            .appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg);\r
+        panel.tab.data('panel', panel)\r
+            .appendTo(this.$el);\r
+            //.appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg);\r
 \r
         panel.bind('change:title', this.updateTabTitle);\r
         _kiwi.app.view.doLayout();\r
@@ -702,8 +709,8 @@ _kiwi.view.Tabs = Backbone.View.extend({
 \r
     tabClick: function (e) {\r
         var tab = $(e.currentTarget);\r
-\r
-        var panel = this.model.getByCid(tab.data('panel_id'));\r
+        \r
+        var panel = tab.data('panel');\r
         if (!panel) {\r
             // A panel wasn't found for this tab... wadda fuck\r
             return;\r
@@ -714,12 +721,12 @@ _kiwi.view.Tabs = Backbone.View.extend({
 \r
     partClick: function (e) {\r
         var tab = $(e.currentTarget).parent();\r
-        var panel = this.model.getByCid(tab.data('panel_id'));\r
+        var panel = this.model.getByCid(tab.data('panel'));\r
 \r
         // Only need to part if it's a channel\r
         // If the nicklist is empty, we haven't joined the channel as yet\r
         if (panel.isChannel() && panel.get('members').models.length > 0) {\r
-            _kiwi.gateway.part(panel.get('name'));\r
+            this.model.network.gateway.part(panel.get('name'));\r
         } else {\r
             panel.close();\r
         }\r