Tabs now a list of network tabs
[KiwiIRC.git] / client / assets / dev / model_panellist.js
1 _kiwi.model.PanelList = Backbone.Collection.extend({
2 model: _kiwi.model.Panel,
3
4 comparator: function (chan) {
5 return chan.get('name');
6 },
7 initialize: function (elements, network) {
8
9 // The network this PanelList is associated with
10 this.network = network;
11
12 this.view = new _kiwi.view.Tabs({model: this});
13
14 // Holds the active panel
15 this.active = null;
16
17 // Keep a tab on the active panel
18 this.bind('active', function (active_panel) {
19 this.active = active_panel;
20 }, this);
21 },
22
23
24
25 getByName: function (name) {
26 if (typeof name !== 'string') return;
27
28 return this.find(function (c) {
29 return name.toLowerCase() === c.get('name').toLowerCase();
30 });
31 }
32 });
33
34
35
36 _kiwi.model.NetworkPanelList = Backbone.Collection.extend({
37 model: _kiwi.model.Network,
38
39 initialize: function() {
40 this.view = new _kiwi.view.NetworkTabs({model: this});
41
42 this.on('add', this.onNetworkAdd, this);
43 this.on('remove', this.onNetworkRemove, this);
44
45 // Current active panel
46 this.active = undefined;
47 this.active_connection = undefined;
48 },
49
50 getByConnectionId: function(id) {
51 return this.find(function(connection){
52 return connection.get('connection_id') == id;
53 });
54 },
55
56
57 onNetworkAdd: function(network) {
58 network.panels.on('active', this.onPanelActive, this);
59 },
60
61 onNetworkRemove: function(network) {
62 network.panels.off('active', this.onPanelActive, this);
63 },
64
65 onPanelActive: function(panel) {
66 var connection = this.getByConnectionId(panel.tab.data('connection_id'));
67 this.trigger('active', panel, connection);
68
69 this.active_connection = connection;
70 this.active = panel;
71 }
72 });