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
);
35 if (this.is_network
) {
36 // Add the server tab first
38 .data('panel', this.model
.server
)
39 .data('connection_id', this.model
.network
.get('connection_id'))
43 // Go through each panel adding its tab
44 this.model
.forEach(function (panel
) {
45 // If this is the server panel, ignore as it's already added
46 if (this.is_network
&& panel
== that
.model
.server
)
49 panel
.tab
.data('panel', panel
);
52 panel
.tab
.data('connection_id', this.model
.network
.get('connection_id'));
54 panel
.tab
.appendTo(that
.$el
);
57 _kiwi
.app
.view
.doLayout();
60 updateTabTitle: function (panel
, new_title
) {
61 $('span', panel
.tab
).text(new_title
);
64 panelAdded: function (panel
) {
65 // Add a tab to the panel
66 panel
.tab
= $('<li><span>' + (panel
.get('title') || panel
.get('name')) + '</span><div class="activity"></div></li>');
68 if (panel
.isServer()) {
69 panel
.tab
.addClass('server');
70 panel
.tab
.addClass('icon-nonexistant');
73 panel
.tab
.data('panel', panel
);
76 panel
.tab
.data('connection_id', this.model
.network
.get('connection_id'));
78 panel
.tab
.appendTo(this.$el
);
80 panel
.bind('change:title', this.updateTabTitle
);
81 panel
.bind('change:name', this.updateTabTitle
);
83 _kiwi
.app
.view
.doLayout();
85 panelRemoved: function (panel
) {
89 _kiwi
.app
.view
.doLayout();
92 panelActive: function (panel
, previously_active_panel
) {
93 // Remove any existing tabs or part images
94 _kiwi
.app
.view
.$el
.find('.panellist .part').remove();
95 _kiwi
.app
.view
.$el
.find('.panellist .active').removeClass('active');
97 panel
.tab
.addClass('active');
99 // Only show the part image on non-server tabs
100 if (!panel
.isServer()) {
101 panel
.tab
.append('<span class="part icon-nonexistant"></span>');
105 tabClick: function (e
) {
106 var tab
= $(e
.currentTarget
);
108 var panel
= tab
.data('panel');
110 // A panel wasn't found for this tab... wadda fuck
117 partClick: function (e
) {
118 var tab
= $(e
.currentTarget
).parent();
119 var panel
= tab
.data('panel');
123 // Only need to part if it's a channel
124 // If the nicklist is empty, we haven't joined the channel as yet
125 if (panel
.isChannel() && panel
.get('members').models
.length
> 0) {
126 this.model
.network
.gateway
.part(panel
.get('name'));