1 // Model for this = _kiwi.model.PanelList
2 _kiwi
.view
.Tabs
= Backbone
.View
.extend({
4 className
: 'panellist',
7 'click li': 'tabClick',
8 'click li .part': 'partClick'
11 initialize: function () {
12 this.model
.on("add", this.panelAdded
, this);
13 this.model
.on("remove", this.panelRemoved
, this);
14 this.model
.on("reset", this.render
, this);
16 this.model
.on('active', this.panelActive
, this);
18 // Network tabs start with a server, so determine what we are now
19 this.is_network
= false;
21 if (this.model
.network
) {
22 this.is_network
= true;
24 this.model
.network
.on('change:name', function (network
, new_val
) {
25 $('span', this.model
.server
.tab
).text(new_val
);
29 this.panel_access
= new Array();
37 if (this.is_network
) {
38 // Add the server tab first
40 .data('panel', this.model
.server
)
41 .data('connection_id', this.model
.network
.get('connection_id'))
45 // Go through each panel adding its tab
46 this.model
.forEach(function (panel
) {
47 // If this is the server panel, ignore as it's already added
48 if (this.is_network
&& panel
== that
.model
.server
)
51 panel
.tab
.data('panel', panel
);
54 panel
.tab
.data('connection_id', this.model
.network
.get('connection_id'));
56 panel
.tab
.appendTo(that
.$el
);
59 _kiwi
.app
.view
.doLayout();
62 updateTabTitle: function (panel
, new_title
) {
63 $('span', panel
.tab
).text(new_title
);
66 panelAdded: function (panel
) {
67 // Add a tab to the panel
68 panel
.tab
= $('<li><span>' + (panel
.get('title') || panel
.get('name')) + '</span><div class="activity"></div></li>');
70 if (panel
.isServer()) {
71 panel
.tab
.addClass('server');
72 panel
.tab
.addClass('icon-nonexistant');
75 panel
.tab
.data('panel', panel
);
78 panel
.tab
.data('connection_id', this.model
.network
.get('connection_id'));
80 panel
.tab
.appendTo(this.$el
);
82 panel
.bind('change:title', this.updateTabTitle
);
83 panel
.bind('change:name', this.updateTabTitle
);
86 this.panel_access
.unshift(panel
.cid
);
88 _kiwi
.app
.view
.doLayout();
90 panelRemoved: function (panel
) {
91 var connection
= _kiwi
.app
.connections
.active_connection
;
95 // If closing the active panel, switch to the last-accessed panel
96 if (this.panel_access
[0] === _kiwi
.app
.panels().active
.cid
) {
97 this.panel_access
.shift();
99 //Get the last-accessed panel model now that we removed the closed one
100 var model
= connection
.panels
.getByCid(this.panel_access
[0]);
109 _kiwi
.app
.view
.doLayout();
112 panelActive: function (panel
, previously_active_panel
) {
113 var panel_index
= _
.indexOf(this.panel_access
, panel
.cid
);
115 // Remove any existing tabs or part images
116 _kiwi
.app
.view
.$el
.find('.panellist .part').remove();
117 _kiwi
.app
.view
.$el
.find('.panellist .active').removeClass('active');
119 panel
.tab
.addClass('active');
121 // Only show the part image on non-server tabs
122 if (!panel
.isServer()) {
123 panel
.tab
.append('<span class="part icon-nonexistant"></span>');
126 if (panel_index
> -1) {
127 this.panel_access
.splice(panel_index
, 1);
130 //Make this panel the most recently accessed
131 this.panel_access
.unshift(panel
.cid
);
134 tabClick: function (e
) {
135 var tab
= $(e
.currentTarget
);
137 var panel
= tab
.data('panel');
139 // A panel wasn't found for this tab... wadda fuck
146 partClick: function (e
) {
147 var tab
= $(e
.currentTarget
).parent();
148 var panel
= tab
.data('panel');
152 // Only need to part if it's a channel
153 // If the nicklist is empty, we haven't joined the channel as yet
154 if (panel
.isChannel() && panel
.get('members').models
.length
> 0) {
155 this.model
.network
.gateway
.part(panel
.get('name'));