]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseui.js
Split window class into indepdent file, rename baseirc.js to baseircclient.js
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
1 var WINDOW_STATUS = 1;
2 var WINDOW_QUERY = 2;
3 var WINDOW_CHANNEL = 3;
4
5 var UI = new Class({
6 initialize: function(parentElement, windowClass, uiName) {
7 this.windows = {};
8 this.windowArray = [];
9 this.windowClass = windowClass;
10 this.parentElement = parentElement;
11 this.parentElement.addClass("qwebirc");
12 this.parentElement.addClass("qwebirc-" + uiName);
13 this.firstClient = false;
14 },
15 newClient: function(client) {
16 this.windows[client] = {}
17 var w = this.newWindow(client, WINDOW_STATUS, "Status");
18 this.selectWindow(w);
19 if(!this.firstClient) {
20 this.firstClient = true;
21 w.addLine("", "qwebirc v" + QWEBIRC_VERSION + " -- Copyright (C) 2008 Chris Porter. All rights reserved.");
22 w.addLine("", "http://webchat.quakenet.org/");
23 }
24 return w;
25 },
26 newWindow: function(client, type, name) {
27 var identifier = name;
28 if(type == WINDOW_STATUS)
29 identifier = "";
30
31 var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);
32 this.windowArray.push(w);
33
34 return w;
35 },
36 getActiveWindow: function() {
37 return this.active;
38 },
39 __setActiveWindow: function(window) {
40 this.active = window;
41 },
42 selectWindow: function(window) {
43 if(this.active)
44 this.active.deselect();
45 window.select(); /* calls setActiveWindow */
46 },
47 __closed: function(window) {
48 if(window.active) {
49 this.active = undefined;
50 if(this.windowArray.length == 1) {
51 this.windowArray = [];
52 } else {
53 var index = this.windowArray.indexOf(window);
54 if(index == 0) {
55 this.selectWindow(this.windowArray[1]);
56 } else {
57 this.selectWindow(this.windowArray[index - 1]);
58 }
59
60 this.windowArray = this.windowArray.erase(window);
61 }
62 }
63
64 delete this.windows[window.client][window.identifier];
65 },
66 loginBox: function(callback, initialNickname, initialChannels) {
67 /*
68 this shouldn't be called by overriding classes!
69 some form of user input MUST be received before an
70 IRC connection is made, else users are going to get
71 tricked into getting themselves glined
72 */
73
74 var nick = prompt("Nickname:", initialNickname);
75 if(!nick) {
76 alert("Aborted.");
77 return;
78 }
79
80 var chans = prompt("Channels (seperate by comma):", initialChannels);
81 callback({"nickname": nick, "autojoin": chans});
82 }
83 });