From 2ffd1291abc3590105c1dcef3b9f4577f0c57041 Mon Sep 17 00:00:00 2001 From: Darren Date: Tue, 23 Apr 2013 00:59:44 +0100 Subject: [PATCH] Client: Active panel/connection tracking --- client/assets/dev/model_application.js | 4 +++- client/assets/dev/model_gateway.js | 7 ++++++- client/assets/dev/model_network.js | 2 +- client/assets/dev/model_panellist.js | 6 ++---- client/assets/dev/view.js | 9 +++++++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index 78199e3..cd7cd95 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -35,13 +35,15 @@ _kiwi.model.Application = function () { // Best guess at where the kiwi server is this.detectKiwiServer(); - // Holds instances of model_network + // Takes instances of model_network this.connections = new _kiwi.model.NetworkPanelList(); + this.connections.on('active', this.onPanelActive, this); // The active network (reference to a this.connections element) this.active_connection = null; }; + this.start = function () { // Only debug if set in the querystring if (!getQueryVariable('debug')) { diff --git a/client/assets/dev/model_gateway.js b/client/assets/dev/model_gateway.js index 25e246c..1a534c3 100644 --- a/client/assets/dev/model_gateway.js +++ b/client/assets/dev/model_gateway.js @@ -322,7 +322,12 @@ _kiwi.model.Gateway = function () { * @param {Function} callback A callback function */ this.sendData = function (data, callback) { - this.socket.emit('irc', {server: _kiwi.app.connections.active.get('connection_id'), data: JSON.stringify(data)}, callback); + var data_buffer = { + server: _kiwi.app.connections.active_connection.get('connection_id'), + data: JSON.stringify(data) + }; + + this.socket.emit('irc', data_buffer, callback); }; /** diff --git a/client/assets/dev/model_network.js b/client/assets/dev/model_network.js index 73c936e..854a9e1 100644 --- a/client/assets/dev/model_network.js +++ b/client/assets/dev/model_network.js @@ -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); diff --git a/client/assets/dev/model_panellist.js b/client/assets/dev/model_panellist.js index 27b0674..01cc1e3 100644 --- a/client/assets/dev/model_panellist.js +++ b/client/assets/dev/model_panellist.js @@ -64,10 +64,8 @@ _kiwi.model.NetworkPanelList = Backbone.Collection.extend({ var connection = this.getByConnectionId(panel.tab.data('connection_id')); this.trigger('active', panel, connection); + this.active_connection = connection; + this.active = panel; console.log('Active connection:', connection.get('connection_id'), 'Active panel:', panel.get('name')); - this.active = connection; - connection.panels.active = panel; - - _kiwi.app.panels = connection.panels; } }); \ No newline at end of file diff --git a/client/assets/dev/view.js b/client/assets/dev/view.js index b104c7c..ca56aa5 100644 --- a/client/assets/dev/view.js +++ b/client/assets/dev/view.js @@ -874,10 +874,15 @@ _kiwi.view.ControlBox = Backbone.View.extend({ // Hold tab autocomplete data this.tabcomplete = {active: false, data: [], prefix: ''}; - _kiwi.gateway.bind('change:nick', function () { - $('.nick', that.$el).text(this.get('nick')); + // When we get any nick change event for any connection, update our view just incase it's us + _kiwi.gateway.bind('onnick', function (event) { + $('.nick', that.$el).text(_kiwi.app.connections.active_connection.get('nick')); + }); + _kiwi.gateway.bind('onconnect', function (event) { + $('.nick', that.$el).text(event.nick); }); + // Update our nick view as we flick between connections _kiwi.app.connections.on('active', function(panel, connection) { $('.nick', that.$el).text(connection.get('nick')); }); -- 2.25.1