1 _kiwi
.view
.MemberList
= Backbone
.View
.extend({
4 "click .nick": "nickClick",
5 "click .channel_info": "channelInfoClick"
8 initialize: function (options
) {
9 this.model
.bind('all', this.render
, this);
10 this.$el
.appendTo('#kiwi .memberlists');
12 // Holds meta data. User counts, etc
13 this.$meta
= $('<div class="meta"></div>').appendTo(this.$el
);
15 // The list for holding the nicks
16 this.$list
= $('<ul></ul>').appendTo(this.$el
);
22 this.model
.forEach(function (member
) {
23 member
.view
.$el
.data('member', member
);
24 that
.$list
.append(member
.view
.$el
);
28 if(this.model
.channel
.isActive()) {
35 renderMeta: function() {
36 var members_count
= this.model
.length
+ ' ' + translateText('client_applets_chanlist_users');
37 this.$meta
.text(members_count
);
40 nickClick: function (event
) {
41 var $target
= $(event
.currentTarget
).parent('li'),
42 member
= $target
.data('member');
44 _kiwi
.global
.events
.emit('nick:select', {target
: $target
, member
: member
, source
: 'nicklist'})
45 .then(_
.bind(this.openUserMenuForItem
, this, $target
));
49 // Open a user menu for the given userlist item (<li>)
50 openUserMenuForItem: function($target
) {
51 var member
= $target
.data('member'),
53 are_we_an_op
= !!this.model
.getByNick(_kiwi
.app
.connections
.active_connection
.get('nick')).get('is_op');
55 userbox
= new _kiwi
.view
.UserBox();
56 userbox
.setTargets(member
, this.model
.channel
);
57 userbox
.displayOpItems(are_we_an_op
);
59 var menu
= new _kiwi
.view
.MenuBox(member
.get('nick') || 'User');
60 menu
.addItem('userbox', userbox
.$el
);
61 menu
.showFooter(false);
63 _kiwi
.global
.events
.emit('usermenu:created', {menu
: menu
, userbox
: userbox
, user
: member
})
64 .then(_
.bind(function() {
67 var target_offset
= $target
.offset(),
68 t
= target_offset
.top
,
69 m_bottom
= t
+ menu
.$el
.outerHeight(), // Where the bottom of menu will be
70 memberlist_bottom
= this.$el
.parent().offset().top
+ this.$el
.parent().outerHeight(),
71 l
= target_offset
.left
,
72 m_right
= l
+ menu
.$el
.outerWidth(), // Where the left of menu will be
73 memberlist_right
= this.$el
.parent().offset().left
+ this.$el
.parent().outerWidth();
75 // If the bottom of the userbox is going to be too low.. raise it
76 if (m_bottom
> memberlist_bottom
){
77 t
= memberlist_bottom
- menu
.$el
.outerHeight();
80 // If the top of the userbox is going to be too high.. lower it
85 // If the right of the userbox is going off screen.. bring it in
86 if (m_right
> memberlist_right
){
87 l
= memberlist_right
- menu
.$el
.outerWidth();
90 // Set the new positon
97 .catch(_
.bind(function() {
106 channelInfoClick: function(event
) {
107 new _kiwi
.model
.ChannelInfo({channel
: this.model
.channel
});
112 $('#kiwi .memberlists').children().removeClass('active');
113 $(this.el
).addClass('active');