1 _kiwi
.model
.PanelList
= Backbone
.Collection
.extend({
2 model
: _kiwi
.model
.Panel
,
4 comparator: function (chan
) {
5 return chan
.get('name');
7 initialize: function (elements
, network
) {
10 // The network this PanelList is associated with
11 this.network
= network
;
13 this.view
= new _kiwi
.view
.Tabs({model
: this});
15 // Holds the active panel
18 // Keep a tab on the active panel
19 this.bind('active', function (active_panel
) {
20 this.active
= active_panel
;
23 this.bind('add', function(panel
) {
24 panel
.set('panel_list', this);
30 getByName: function (name
) {
31 if (typeof name
!== 'string') return;
33 return this.find(function (c
) {
34 return name
.toLowerCase() === c
.get('name').toLowerCase();
41 _kiwi
.model
.NetworkPanelList
= Backbone
.Collection
.extend({
42 model
: _kiwi
.model
.Network
,
44 initialize: function() {
45 this.view
= new _kiwi
.view
.NetworkTabs({model
: this});
47 this.on('add', this.onNetworkAdd
, this);
48 this.on('remove', this.onNetworkRemove
, this);
50 // Current active connection / panel
51 this.active_connection
= undefined;
52 this.active_panel
= undefined;
54 // TODO: Remove this - legacy
55 this.active
= undefined;
58 getByConnectionId: function(id
) {
59 return this.find(function(connection
){
60 return connection
.get('connection_id') == id
;
67 this.each(function(network
) {
68 panels
= panels
.concat(network
.panels
.models
);
75 onNetworkAdd: function(network
) {
76 network
.panels
.on('active', this.onPanelActive
, this);
78 // if it's our first connection, set it active
79 if (this.models
.length
=== 1) {
80 this.active_connection
= network
;
81 this.active_panel
= network
.panels
.server
;
83 // TODO: Remove this - legacy
84 this.active
= this.active_panel
;
88 onNetworkRemove: function(network
) {
89 network
.panels
.off('active', this.onPanelActive
, this);
92 onPanelActive: function(panel
) {
93 var connection
= this.getByConnectionId(panel
.tab
.data('connection_id'));
94 this.trigger('active', panel
, connection
);
96 this.active_connection
= connection
;
97 this.active_panel
= panel
;
99 // TODO: Remove this - legacy