1 _kiwi
.view
.Panel
= Backbone
.View
.extend({
8 initialize: function (options
) {
9 this.initializePanel(options
);
12 initializePanel: function (options
) {
13 this.$el
.css('display', 'none');
14 options
= options
|| {};
16 // Containing element for this panel
17 if (options
.container
) {
18 this.$container
= $(options
.container
);
20 this.$container
= $('#kiwi .panels .container1');
23 this.$el
.appendTo(this.$container
);
27 this.model
.set({"view": this}, {"silent": true});
37 // Hide all other panels and show this one
38 this.$container
.children('.panel').css('display', 'none');
39 $this.css('display', 'block');
41 // Show this panels memberlist
42 var members
= this.model
.get("members");
44 $('#kiwi .memberlists').removeClass('disabled');
47 // Memberlist not found for this panel, hide any active ones
48 $('#kiwi .memberlists').addClass('disabled').children().removeClass('active');
51 // Remove any alerts and activity counters for this panel
53 this.model
.tab
.find('.activity').text('0').addClass('zero');
55 _kiwi
.app
.panels
.trigger('active', this.model
, _kiwi
.app
.panels().active
);
56 this.model
.trigger('active', this.model
);
58 _kiwi
.app
.view
.doLayout();
60 this.scrollToBottom(true);
64 alert: function (level
) {
65 // No need to highlight if this si the active panel
66 if (this.model
== _kiwi
.app
.panels().active
) return;
69 types
= ['none', 'action', 'activity', 'highlight'];
71 // Default alert level
72 level
= level
|| 'none';
74 // If this alert level does not exist, assume clearing current level
75 type_idx
= _
.indexOf(types
, level
);
81 // Only 'upgrade' the alert. Never down (unless clearing)
82 if (type_idx
!== 0 && type_idx
<= this.alert_level
) {
86 // Clear any existing levels
87 this.model
.tab
.removeClass(function (i
, css
) {
88 return (css
.match(/\balert_\S+/g) || []).join(' ');
91 // Add the new level if there is one
92 if (level
!== 'none') {
93 this.model
.tab
.addClass('alert_' + level
);
96 this.alert_level
= type_idx
;
100 // Scroll to the bottom of the panel
101 scrollToBottom: function (force_down
) {
102 // If this isn't the active panel, don't scroll
103 if (this.model
!== _kiwi
.app
.panels().active
) return;
105 // Don't scroll down if we're scrolled up the panel a little
106 if (force_down
|| this.$container
.scrollTop() + this.$container
.height() > this.$el
.outerHeight() - 150) {
107 this.$container
[0].scrollTop
= this.$container
[0].scrollHeight
;