Commit | Line | Data |
---|---|---|
8fcd0453 D |
1 | _kiwi.model.NetworkPanelList = Backbone.Collection.extend({ |
2 | model: _kiwi.model.Network, | |
3 | ||
4 | initialize: function() { | |
5 | this.view = new _kiwi.view.NetworkTabs({model: this}); | |
6 | ||
7 | this.on('add', this.onNetworkAdd, this); | |
8 | this.on('remove', this.onNetworkRemove, this); | |
9 | ||
10 | // Current active connection / panel | |
11 | this.active_connection = undefined; | |
12 | this.active_panel = undefined; | |
13 | ||
14 | // TODO: Remove this - legacy | |
15 | this.active = undefined; | |
16 | }, | |
17 | ||
18 | getByConnectionId: function(id) { | |
19 | return this.find(function(connection){ | |
20 | return connection.get('connection_id') == id; | |
21 | }); | |
22 | }, | |
23 | ||
24 | panels: function() { | |
25 | var panels = []; | |
26 | ||
27 | this.each(function(network) { | |
28 | panels = panels.concat(network.panels.models); | |
29 | }); | |
30 | ||
31 | return panels; | |
32 | }, | |
33 | ||
34 | ||
35 | onNetworkAdd: function(network) { | |
36 | network.panels.on('active', this.onPanelActive, this); | |
37 | ||
38 | // if it's our first connection, set it active | |
39 | if (this.models.length === 1) { | |
40 | this.active_connection = network; | |
41 | this.active_panel = network.panels.server; | |
42 | ||
43 | // TODO: Remove this - legacy | |
44 | this.active = this.active_panel; | |
45 | } | |
46 | }, | |
47 | ||
48 | onNetworkRemove: function(network) { | |
49 | network.panels.off('active', this.onPanelActive, this); | |
50 | }, | |
51 | ||
52 | onPanelActive: function(panel) { | |
53 | var connection = this.getByConnectionId(panel.tab.data('connection_id')); | |
54 | this.trigger('active', panel, connection); | |
55 | ||
56 | this.active_connection = connection; | |
57 | this.active_panel = panel; | |
58 | ||
59 | // TODO: Remove this - legacy | |
60 | this.active = panel; | |
61 | } | |
62 | }); |