New IRC connection - don't send redundant con_num to client on connection error
[KiwiIRC.git] / client / assets / src / models / panel.js
1 _kiwi.model.Panel = Backbone.Model.extend({
2 initialize: function (attributes) {
3 var name = this.get("name") || "";
4 this.view = new _kiwi.view.Panel({"model": this, "name": name});
5 this.set({
6 "scrollback": [],
7 "name": name
8 }, {"silent": true});
9 },
10
11 closePanel: function () {
12 if (this.view) {
13 this.view.unbind();
14 this.view.remove();
15 this.view = undefined;
16 delete this.view;
17 }
18
19 var members = this.get('members');
20 if (members) {
21 members.reset([]);
22 this.unset('members');
23 }
24
25 this.get('panel_list').remove(this);
26
27 this.unbind();
28 this.destroy();
29
30 // If closing the active panel, switch to the server panel
31 if (this === _kiwi.app.panels().active) {
32 _kiwi.app.connections.active_connection.panels.server.view.show();
33 }
34 },
35
36 // Alias to closePanel() for child objects to override
37 close: function () {
38 return this.closePanel();
39 },
40
41 isChannel: function () {
42 var channel_prefix = _kiwi.gateway.get('channel_prefix'),
43 this_name = this.get('name');
44
45 if (this.isApplet() || !this_name) return false;
46 return (channel_prefix.indexOf(this_name[0]) > -1);
47 },
48
49 isQuery: function () {
50 if (!this.isChannel() && !this.isApplet() && !this.isServer()) {
51 return true;
52 }
53
54 return false;
55 },
56
57 isApplet: function () {
58 return this.applet ? true : false;
59 },
60
61 isServer: function () {
62 return this.server ? true : false;
63 },
64
65 isActive: function () {
66 return (_kiwi.app.panels().active === this);
67 }
68 });