From: Darren Date: Sun, 21 Apr 2013 14:19:44 +0000 (+0100) Subject: Multiple network tabs working X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fb321ba02426f8630434c718a037b0e4ea981e85;p=KiwiIRC.git Multiple network tabs working --- diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index 17815c3..f6d4fd9 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -735,6 +735,17 @@ _kiwi.model.Application = function () { return (channel_prefix.indexOf(channel_name[0]) > -1); }; + + + this.eachPanel = function (fn) { + if (typeof fn !== 'function') + return; + + _.each(this.connections, function(connection) { + _.each(connection.panels.model, fn); + }); + } + }; diff --git a/client/assets/dev/model_network.js b/client/assets/dev/model_network.js index 02a2eb2..56f64cc 100644 --- a/client/assets/dev/model_network.js +++ b/client/assets/dev/model_network.js @@ -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); }, diff --git a/client/assets/dev/model_panellist.js b/client/assets/dev/model_panellist.js index cd43e19..d48043e 100644 --- a/client/assets/dev/model_panellist.js +++ b/client/assets/dev/model_panellist.js @@ -4,8 +4,12 @@ _kiwi.model.PanelList = Backbone.Collection.extend({ comparator: function (chan) { return chan.get('name'); }, - initialize: function () { - this.view = new _kiwi.view.Tabs({el: $('#tabs')[0], model: this}); + initialize: function (network) { + + // The network this PanelList is associated with + this.network = network; + + this.view = new _kiwi.view.Tabs({model: this}); // Automatically create a server tab var server_panel = new _kiwi.model.Server({name: 'Server'}); diff --git a/client/assets/dev/view.js b/client/assets/dev/view.js index d9522a1..cc4513b 100644 --- a/client/assets/dev/view.js +++ b/client/assets/dev/view.js @@ -619,6 +619,8 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ // Model for this = _kiwi.model.PanelList _kiwi.view.Tabs = Backbone.View.extend({ + tagName: 'ul', + events: { 'click li': 'tabClick', 'click li .part': 'partClick' @@ -634,10 +636,13 @@ _kiwi.view.Tabs = Backbone.View.extend({ this.tabs_applets = $('ul.applets', this.$el); this.tabs_msg = $('ul.channels', this.$el); - _kiwi.gateway.on('change:name', function (gateway, new_val) { + this.model.network.on('change:name', function (network, new_val) { $('span', this.model.server.tab).text(new_val); }, this); + + $('#kiwi .panellist.channels').append(this.$el); }, + render: function () { var that = this; @@ -645,7 +650,7 @@ _kiwi.view.Tabs = Backbone.View.extend({ // Add the server tab first this.model.server.tab - .data('panel_id', this.model.server.cid) + .data('panel', this.model.server) .appendTo(this.tabs_msg); // Go through each panel adding its tab @@ -654,8 +659,9 @@ _kiwi.view.Tabs = Backbone.View.extend({ if (panel == that.model.server) return; panel.tab - .data('panel_id', panel.cid) - .appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg); + .data('panel', panel) + .appendTo(that.$el); + //.appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg); }); _kiwi.app.view.doLayout(); @@ -673,8 +679,9 @@ _kiwi.view.Tabs = Backbone.View.extend({ panel.tab.addClass('server'); } - panel.tab.data('panel_id', panel.cid) - .appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg); + panel.tab.data('panel', panel) + .appendTo(this.$el); + //.appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg); panel.bind('change:title', this.updateTabTitle); _kiwi.app.view.doLayout(); @@ -702,8 +709,8 @@ _kiwi.view.Tabs = Backbone.View.extend({ tabClick: function (e) { var tab = $(e.currentTarget); - - var panel = this.model.getByCid(tab.data('panel_id')); + + var panel = tab.data('panel'); if (!panel) { // A panel wasn't found for this tab... wadda fuck return; @@ -714,12 +721,12 @@ _kiwi.view.Tabs = Backbone.View.extend({ partClick: function (e) { var tab = $(e.currentTarget).parent(); - var panel = this.model.getByCid(tab.data('panel_id')); + var panel = this.model.getByCid(tab.data('panel')); // Only need to part if it's a channel // If the nicklist is empty, we haven't joined the channel as yet if (panel.isChannel() && panel.get('members').models.length > 0) { - _kiwi.gateway.part(panel.get('name')); + this.model.network.gateway.part(panel.get('name')); } else { panel.close(); }