Add server + client versions to CTCP VERSION reply
[KiwiIRC.git] / client / src / views / panel.js
1 _kiwi.view.Panel = Backbone.View.extend({
2 tagName: "div",
3 className: "panel",
4
5 events: {
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
27 this.model.set({"view": this}, {"silent": true});
28 },
29
30 render: function () {
31 },
32
33
34 show: function () {
35 var $this = this.$el;
36
37 // Hide all other panels and show this one
38 this.$container.children('.panel').css('display', 'none');
39 $this.css('display', 'block');
40
41 // Show this panels memberlist
42 var members = this.model.get("members");
43 if (members) {
44 $('#kiwi .right_bar').removeClass('disabled');
45 members.view.show();
46 } else {
47 // Memberlist not found for this panel, hide any active ones
48 $('#kiwi .right_bar').addClass('disabled').children().removeClass('active');
49 }
50
51 // Remove any alerts and activity counters for this panel
52 this.alert('none');
53 this.model.tab.find('.activity').text('0').addClass('zero');
54
55 _kiwi.app.panels.trigger('active', this.model, _kiwi.app.panels().active);
56 this.model.trigger('active', this.model);
57
58 _kiwi.app.view.doLayout();
59
60 if (!this.model.isApplet())
61 this.scrollToBottom(true);
62 },
63
64
65 alert: function (level) {
66 // No need to highlight if this si the active panel
67 if (this.model == _kiwi.app.panels().active) return;
68
69 var types, type_idx;
70 types = ['none', 'action', 'activity', 'highlight'];
71
72 // Default alert level
73 level = level || 'none';
74
75 // If this alert level does not exist, assume clearing current level
76 type_idx = _.indexOf(types, level);
77 if (!type_idx) {
78 level = 'none';
79 type_idx = 0;
80 }
81
82 // Only 'upgrade' the alert. Never down (unless clearing)
83 if (type_idx !== 0 && type_idx <= this.alert_level) {
84 return;
85 }
86
87 // Clear any existing levels
88 this.model.tab.removeClass(function (i, css) {
89 return (css.match(/\balert_\S+/g) || []).join(' ');
90 });
91
92 // Add the new level if there is one
93 if (level !== 'none') {
94 this.model.tab.addClass('alert_' + level);
95 }
96
97 this.alert_level = type_idx;
98 },
99
100
101 // Scroll to the bottom of the panel
102 scrollToBottom: function (force_down) {
103 // If this isn't the active panel, don't scroll
104 if (this.model !== _kiwi.app.panels().active) return;
105
106 // Don't scroll down if we're scrolled up the panel a little
107 if (force_down || this.$container.scrollTop() + this.$container.height() > this.$el.outerHeight() - 150) {
108 this.$container[0].scrollTop = this.$container[0].scrollHeight;
109 }
110 }
111 });