Move translation files from assets/locales to assets/src/translations
[KiwiIRC.git] / client / assets / src / views / channel.js
CommitLineData
50ac472f 1_kiwi.view.Channel = _kiwi.view.Panel.extend({
9b807765
D
2 events: function(){
3 var parent_events = _kiwi.view.Panel.prototype.events;
4
5 if(_.isFunction(parent_events)){
6 parent_events = parent_events();
7 }
8 return _.extend({}, parent_events, {
9 'click .msg .nick' : 'nickClick'
10 });
dfb5209c
JA
11 },
12
50ac472f
D
13 initialize: function (options) {
14 this.initializePanel(options);
15 this.model.bind('change:topic', this.topic, this);
16
7d2a2771
D
17 if (this.model.get('members')) {
18 this.model.get('members').bind('add', function (member) {
19 if (member.get('nick') === this.model.collection.network.get('nick')) {
20 this.$el.find('.initial_loader').slideUp(function () {
21 $(this).remove();
22 });
23 }
24 }, this);
25 }
660e1427 26
50ac472f
D
27 // Only show the loader if this is a channel (ie. not a query)
28 if (this.model.isChannel()) {
0d29c21f 29 this.$el.append('<div class="initial_loader" style="margin:1em;text-align:center;"> ' + _kiwi.global.i18n.translate('Joining channel..').fetch() + ' <span class="loader"></span></div>');
50ac472f
D
30 }
31 },
32
33 // Override the existing newMsg() method to remove the joining channel loader
34 newMsg: function () {
50ac472f
D
35 return this.constructor.__super__.newMsg.apply(this, arguments);
36 },
37
38 topic: function (topic) {
39 if (typeof topic !== 'string' || !topic) {
40 topic = this.model.get("topic");
41 }
42
0d29c21f 43 this.model.addMsg('', '== ' + _kiwi.global.i18n.translate('Topic for %s is: %s').fetch(this.model.get('name'), topic), 'topic');
50ac472f
D
44
45 // If this is the active channel then update the topic bar
46 if (_kiwi.app.panels().active === this) {
47 _kiwi.app.topicbar.setCurrentTopic(this.model.get("topic"));
48 }
dfb5209c
JA
49 },
50
51 // Click on a nickname
52 nickClick: function (event) {
53 var nick = $(event.currentTarget).text(),
54 members = this.model.get('members'),
55 member, query, userbox, menubox;
56
57 if (members) {
58 member = members.getByNick(nick);
59 if (member) {
dfb5209c
JA
60 userbox = new _kiwi.view.UserBox();
61 userbox.member = member;
62 userbox.channel = this.model;
63
64 if (!member.get('is_op')) {
65 userbox.$el.children('.if_op').remove();
66 }
67 menubox = new _kiwi.view.MenuBox(member.get('nick') || 'User');
68 menubox.addItem('userbox', userbox.$el);
dfb5209c 69 menubox.show();
c3c793e0 70
dfb5209c
JA
71 // Position the userbox + menubox
72 (function() {
73 var t = event.pageY,
74 m_bottom = t + menubox.$el.outerHeight(), // Where the bottom of menu will be
75 memberlist_bottom = this.$el.parent().offset().top + this.$el.parent().outerHeight();
76
77 // If the bottom of the userbox is going to be too low.. raise it
78 if (m_bottom > memberlist_bottom){
79 t = memberlist_bottom - menubox.$el.outerHeight();
80 }
81
82 // Set the new positon
83 menubox.$el.offset({
84 left: event.clientX,
85 top: t
86 });
87 }).call(this);
88 }
89 }
50ac472f 90 }
dfb5209c 91});