Translations update
[KiwiIRC.git] / client / src / views / panel.js
CommitLineData
50ac472f
D
1_kiwi.view.Panel = Backbone.View.extend({
2 tagName: "div",
c794b877 3 className: "panel",
50ac472f
D
4
5 events: {
50ac472f
D
6 },
7
8 initialize: function (options) {
9 this.initializePanel(options);
10 },
11
12 initializePanel: function (options) {
13 this.$el.css('display', 'none');
14 options = options || {};
15
16 // Containing element for this panel
17 if (options.container) {
18 this.$container = $(options.container);
19 } else {
20 this.$container = $('#kiwi .panels .container1');
21 }
22
23 this.$el.appendTo(this.$container);
24
25 this.alert_level = 0;
26
50ac472f 27 this.model.set({"view": this}, {"silent": true});
af03387c
D
28
29 this.listenTo(this.model, 'change:activity_counter', function(model, new_count) {
30 var $act = this.model.tab.find('.activity');
31
32 if (new_count > 999) {
33 $act.text('999+');
34 } else {
35 $act.text(new_count);
36 }
37
38 if (new_count === 0) {
39 $act.addClass('zero');
40 } else {
41 $act.removeClass('zero');
42 }
43 });
50ac472f
D
44 },
45
46 render: function () {
50ac472f 47 },
e1ab9643 48
50ac472f
D
49
50 show: function () {
51 var $this = this.$el;
52
53 // Hide all other panels and show this one
54 this.$container.children('.panel').css('display', 'none');
55 $this.css('display', 'block');
56
57 // Show this panels memberlist
58 var members = this.model.get("members");
59 if (members) {
626c1246 60 _kiwi.app.rightbar.show();
50ac472f
D
61 members.view.show();
62 } else {
626c1246 63 _kiwi.app.rightbar.hide();
50ac472f
D
64 }
65
66 // Remove any alerts and activity counters for this panel
67 this.alert('none');
af03387c 68 this.model.set('activity_counter', 0);
50ac472f
D
69
70 _kiwi.app.panels.trigger('active', this.model, _kiwi.app.panels().active);
71 this.model.trigger('active', this.model);
72
73 _kiwi.app.view.doLayout();
74
e90e39db
D
75 if (!this.model.isApplet())
76 this.scrollToBottom(true);
50ac472f
D
77 },
78
79
80 alert: function (level) {
81 // No need to highlight if this si the active panel
82 if (this.model == _kiwi.app.panels().active) return;
83
84 var types, type_idx;
85 types = ['none', 'action', 'activity', 'highlight'];
86
87 // Default alert level
88 level = level || 'none';
89
90 // If this alert level does not exist, assume clearing current level
91 type_idx = _.indexOf(types, level);
92 if (!type_idx) {
93 level = 'none';
94 type_idx = 0;
95 }
96
97 // Only 'upgrade' the alert. Never down (unless clearing)
98 if (type_idx !== 0 && type_idx <= this.alert_level) {
99 return;
100 }
101
102 // Clear any existing levels
103 this.model.tab.removeClass(function (i, css) {
104 return (css.match(/\balert_\S+/g) || []).join(' ');
105 });
106
107 // Add the new level if there is one
108 if (level !== 'none') {
109 this.model.tab.addClass('alert_' + level);
110 }
111
112 this.alert_level = type_idx;
113 },
114
115
116 // Scroll to the bottom of the panel
117 scrollToBottom: function (force_down) {
118 // If this isn't the active panel, don't scroll
119 if (this.model !== _kiwi.app.panels().active) return;
120
121 // Don't scroll down if we're scrolled up the panel a little
122 if (force_down || this.$container.scrollTop() + this.$container.height() > this.$el.outerHeight() - 150) {
123 this.$container[0].scrollTop = this.$container[0].scrollHeight;
124 }
125 }
126});