Client: Active panel/connection tracking
authorDarren <darren@Darrens-MacBook-Pro.local>
Mon, 22 Apr 2013 23:59:44 +0000 (00:59 +0100)
committerDarren <darren@Darrens-MacBook-Pro.local>
Mon, 22 Apr 2013 23:59:44 +0000 (00:59 +0100)
client/assets/dev/model_application.js
client/assets/dev/model_gateway.js
client/assets/dev/model_network.js
client/assets/dev/model_panellist.js
client/assets/dev/view.js

index 78199e34e60b5a62170066ffa4d3d6761cefcb75..cd7cd959796d0427c2c682f753630254a168549e 100644 (file)
@@ -35,13 +35,15 @@ _kiwi.model.Application = function () {
             // Best guess at where the kiwi server is\r
             this.detectKiwiServer();\r
 \r
-            // Holds instances of model_network\r
+            // Takes instances of model_network\r
             this.connections = new _kiwi.model.NetworkPanelList();\r
+            this.connections.on('active', this.onPanelActive, this);\r
 \r
             // The active network (reference to a this.connections element)\r
             this.active_connection = null;\r
         };\r
 \r
+\r
         this.start = function () {\r
             // Only debug if set in the querystring\r
             if (!getQueryVariable('debug')) {\r
index 25e246c4809f1b657f0a0c883cbf07d7908a9ab5..1a534c338508b44aee9704e0fd5795b00a4843ef 100644 (file)
@@ -322,7 +322,12 @@ _kiwi.model.Gateway = function () {
     *   @param  {Function}  callback    A callback function\r
     */\r
     this.sendData = function (data, callback) {\r
-        this.socket.emit('irc', {server: _kiwi.app.connections.active.get('connection_id'), data: JSON.stringify(data)}, callback);\r
+        var data_buffer = {\r
+            server: _kiwi.app.connections.active_connection.get('connection_id'),\r
+            data: JSON.stringify(data)\r
+        };\r
+        \r
+        this.socket.emit('irc', data_buffer, callback);\r
     };\r
 \r
     /**\r
index 73c936e18377626edceba763fb1e94473d77ae9a..854a9e12075cc92b8149a5bbef4f1600c57ef9bf 100644 (file)
@@ -57,7 +57,7 @@
             }, this);
 
             this.gateway.on('nick', function(event) {
-                if (event.nick === event.get('nick')) {
+                if (event.nick === this.get('nick')) {
                     this.set('nick', event.newnick);
                 }
             }, this);
index 27b067465f1647fdc41d85a57a1d3678a8909daf..01cc1e3ea9b9f6a8bd12260935b2a111f3722eb1 100644 (file)
@@ -64,10 +64,8 @@ _kiwi.model.NetworkPanelList = Backbone.Collection.extend({
         var connection = this.getByConnectionId(panel.tab.data('connection_id'));\r
         this.trigger('active', panel, connection);\r
 \r
+        this.active_connection = connection;\r
+        this.active = panel;\r
         console.log('Active connection:', connection.get('connection_id'), 'Active panel:', panel.get('name'));\r
-        this.active = connection;\r
-        connection.panels.active = panel;\r
-        \r
-        _kiwi.app.panels = connection.panels;\r
     }\r
 });
\ No newline at end of file
index b104c7c002b47a805fd840d0b1985538fdefd7e4..ca56aa51a01bc6e39de2210fcadee8e3e54b862f 100644 (file)
@@ -874,10 +874,15 @@ _kiwi.view.ControlBox = Backbone.View.extend({
         // Hold tab autocomplete data\r
         this.tabcomplete = {active: false, data: [], prefix: ''};\r
 \r
-        _kiwi.gateway.bind('change:nick', function () {\r
-            $('.nick', that.$el).text(this.get('nick'));\r
+        // When we get any nick change event for any connection, update our view just incase it's us\r
+        _kiwi.gateway.bind('onnick', function (event) {\r
+            $('.nick', that.$el).text(_kiwi.app.connections.active_connection.get('nick'));\r
+        });\r
+        _kiwi.gateway.bind('onconnect', function (event) {\r
+            $('.nick', that.$el).text(event.nick);\r
         });\r
 \r
+        // Update our nick view as we flick between connections\r
         _kiwi.app.connections.on('active', function(panel, connection) {\r
             $('.nick', that.$el).text(connection.get('nick'));\r
         });\r