]> jfr.im git - irc/quakenet/qwebirc.git/blame_incremental - js/ui/baseui.js
Whoops.
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
... / ...
CommitLineData
1var WINDOW_STATUS = 1;
2var WINDOW_QUERY = 2;
3var WINDOW_CHANNEL = 3;
4var WINDOW_CUSTOM = 4;
5var WINDOW_CONNECT = 5;
6var CUSTOM_CLIENT = "custom";
7
8var BaseUI = new Class({
9 Implements: [Events, Options],
10 options: {
11 appTitle: "QuakeNet Web IRC",
12 singleWindow: true
13 },
14 initialize: function(parentElement, windowClass, uiName, options) {
15 this.setOptions(options);
16
17 this.windows = {};
18 this.windows[CUSTOM_CLIENT] = {};
19 this.windowArray = [];
20 this.windowClass = windowClass;
21 this.parentElement = parentElement;
22 this.parentElement.addClass("qwebirc");
23 this.parentElement.addClass("qwebirc-" + uiName);
24 this.firstClient = false;
25 this.commandhistory = new CommandHistory();
26 },
27 newClient: function(client) {
28 this.windows[client] = {}
29 var w = this.newWindow(client, WINDOW_STATUS, "Status");
30 this.selectWindow(w);
31 if(!this.firstClient) {
32 this.firstClient = true;
33 w.addLine("", "qwebirc v" + QWEBIRC_VERSION);
34 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
35 w.addLine("", "http://webchat.quakenet.org/");
36 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
37 }
38 return w;
39 },
40 newWindow: function(client, type, name) {
41 var identifier = name;
42 if(type == WINDOW_STATUS)
43 identifier = "";
44
45 var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);
46 this.windowArray.push(w);
47
48 return w;
49 },
50 getActiveWindow: function() {
51 return this.active;
52 },
53 __setActiveWindow: function(window) {
54 this.active = window;
55 },
56 selectWindow: function(window) {
57 if(this.active)
58 this.active.deselect();
59 window.select(); /* calls setActiveWindow */
60 document.title = window.name + " - " + this.options.appTitle;
61 },
62 __closed: function(window) {
63 if(window.active) {
64 this.active = undefined;
65 if(this.windowArray.length == 1) {
66 this.windowArray = [];
67 } else {
68 var index = this.windowArray.indexOf(window);
69 if(index == -1) {
70 return;
71 } else if(index == 0) {
72 this.selectWindow(this.windowArray[1]);
73 } else {
74 this.selectWindow(this.windowArray[index - 1]);
75 }
76
77 this.windowArray = this.windowArray.erase(window);
78 }
79 }
80
81 delete this.windows[window.client][window.identifier];
82 },
83 /*
84 this shouldn't be called by overriding classes!
85 they should implement their own!
86 some form of user input MUST be received before an
87 IRC connection is made, else users are going to get
88 tricked into getting themselves glined
89 */
90 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
91 GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
92 /*if(autoConnect) {
93 var c = initialChannels.split(",");
94 var ctext;
95
96 if(c.length > 1) {
97 var last = c.pop();
98 ctext = c.join(", ") + " and " + last;
99 } else {
100 ctext = c[0];
101 }
102
103 var nicktext;
104 if(autoNick) {
105 nicktext = "";
106 } else {
107 nicktext = " (as '" + initialNickname + "')"
108 }
109 if(confirm("Connect to IRC and join channels " + ctext + nicktext + "?"))
110 callback({"nickname": initialNickname, "autojoin": initialChannels});
111 return;
112 }
113
114 var nick = prompt("Nickname:", initialNickname);
115 if(!nick) {
116 alert("Aborted.");
117 return;
118 }
119
120 var chans = prompt("Channels (seperate by comma):", initialChannels);
121 callback({"nickname": nick, "autojoin": chans});
122 */
123 }
124});
125
126var UI = new Class({
127 Extends: BaseUI,
128 initialize: function(parentElement, windowClass, uiName, options) {
129 this.parent(parentElement, windowClass, uiName, options);
130 window.addEvent("keydown", function(x) {
131 if(!x.alt)
132 return;
133
134 if(x.key == "a" || x.key == "A") {
135 new Event(x).stop();
136 for(var i=0;i<this.windowArray.length;i++) {
137 if(this.windowArray[i].hilighted) {
138 this.selectWindow(this.windowArray[i]);
139 break;
140 }
141 }
142 } else if(x.key >= '0' && x.key <= '9') {
143 new Event(x).stop();
144
145 number = x.key - '0';
146 if(number == 0)
147 number = 10
148
149 number = number - 1;
150
151 if(number >= this.windowArray.length)
152 return;
153
154 this.selectWindow(this.windowArray[number]);
155 }
156 }.bind(this));
157 },
158 newCustomWindow: function(name, select, type) {
159 if(!type)
160 type = WINDOW_CUSTOM;
161
162 var w = this.newWindow(CUSTOM_CLIENT, type, name);
163 w.addEvent("close", function(w) {
164 delete this.windows[name];
165 }.bind(this));
166
167 if(select)
168 this.selectWindow(w);
169
170 return w;
171 },
172 embeddedWindow: function() {
173 if(this.embedded) {
174 this.selectWindow(this.embedded)
175 return;
176 }
177
178 this.embedded = this.newCustomWindow("Embedded wizard", true);
179 this.embedded.addEvent("close", function() {
180 this.embedded = null;
181 }.bind(this));
182
183 var ew = new WebmasterGuide({parent: this.embedded.lines});
184 ew.addEvent("close", function() {
185 this.embedded.close();
186 }.bind(this));
187 },
188 urlDispatcher: function(name) {
189 if(name == "embedded")
190 return this.embeddedWindow.bind(this);
191
192 return null;
193 }
194});
195
196var NewLoginUI = new Class({
197 Extends: UI,
198 loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
199 this.postInitialize();
200 var w = this.newCustomWindow("Connect", true, WINDOW_CONNECT);
201 var callback = function(args) {
202 w.close();
203 callbackfn(args);
204 };
205
206 GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick);
207 }
208});