/
channel_tab.js
59 lines (48 loc) · 1.54 KB
/
channel_tab.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var ChannelTabView = Backbone.View.extend({
className: 'channel',
events: {
'click': 'setActive'
},
initialize: function() {
this.model.stream.bind('add', this.updateUnreadCounts, this);
this.model.bind('destroy', this.close, this);
},
render: function() {
var tmpl = ich.channel({name: this.model.get('name')});
$(this.el).html(tmpl);
return this;
},
setActive: function() {
irc.chatWindows.setActive(this.model);
$(this.el).addClass('active')
.siblings().removeClass('active');
this.removeUnread();
},
updateUnreadCounts: function(msg) {
console.log('unread count updated')
var unread = this.model.get('unread');
var unreadMentions = this.model.get('unreadMentions');
// TODO: do something more sensible here than remove/readd elements
$(this.el).children('.unread, .unread_mentions').remove();
if (unread > 0)
$(this.el).append(ich.unread({unread: unread}));
if (unreadMentions > 0)
$(this.el).append(ich.unread_mentions({unread_mentions: unreadMentions}));
},
removeUnread: function() {
$(this.el).children('.unread, .unread_mentions').remove();
this.model.set({unread: 0, unreadMentions: 0});
},
close: function() {
// Focus on next frame if this one has the focus
if ($(this.el).hasClass('active')) {
// Go to previous frame unless it's status
if ($(this.el).prev().text().trim() !== 'status') {
$(this.el).prev().click();
} else {
$(this.el).next().click();
}
}
this.remove();
}
});