]>
Commit | Line | Data |
---|---|---|
e89c812f CP |
1 | qwebirc.ui.ConnectPane = new Class({ |
2 | Implements: [Events], | |
3 | initialize: function(parent, options) { | |
13afa38f | 4 | var callback = options.callback, initialNickname = options.initialNickname, initialChannels = options.initialChannels, autoConnect = options.autoConnect, autoNick = options.autoNick; |
e89c812f | 5 | this.options = options; |
cbd6ec8c | 6 | this.cookie = new Hash.Cookie("optconn", {duration: 3650, autoSave: false}); |
13afa38f | 7 | var uiOptions = options.uiOptions; |
65f2c94c | 8 | this.__windowName = "authgate_" + Math.floor(Math.random() * 100000); |
e89c812f CP |
9 | |
10 | var delayfn = function() { parent.set("html", "<div class=\"loading\">Loading. . .</div>"); }; | |
11 | var cb = delayfn.delay(500); | |
12 | ||
13 | var r = qwebirc.ui.RequestTransformHTML({url: qwebirc.global.staticBaseURL + "panes/connect.html", update: parent, onSuccess: function() { | |
14 | $clear(cb); | |
15 | ||
13afa38f | 16 | var rootElement = parent.getElement("[name=connectroot]"); |
e89c812f CP |
17 | this.rootElement = rootElement; |
18 | ||
19 | this.util.exec = function(n, x) { rootElement.getElements(n).each(x); }; | |
20 | var util = this.util; | |
21 | var exec = util.exec; | |
e89c812f | 22 | |
13afa38f CP |
23 | var box = (autoConnect ? "confirm" : "login"); |
24 | exec("[name=" + box + "box]", util.setVisible(true)); | |
25 | ||
26 | if(!autoConnect) { | |
614427b2 | 27 | if($defined(uiOptions.logoURL)) { |
13afa38f | 28 | var logoBar = parent.getElement("[class=bar-logo]"); |
614427b2 CP |
29 | if(uiOptions.logoURL) |
30 | logoBar.setAttribute("style", "background: url(" + uiOptions.logoURL + ") no-repeat center top; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + uiOptions.logoURL + "',sizingMethod='crop');"); | |
31 | ||
13afa38f CP |
32 | util.makeVisible(parent.getElement("[name=loginheader]")); |
33 | } else { | |
34 | util.makeVisible(parent.getElement("[name=nologologinheader]")); | |
35 | } | |
36 | } | |
66619e20 | 37 | |
cbd6ec8c CP |
38 | if(initialNickname === null && initialChannels === null) { |
39 | var n2 = this.cookie.get("nickname"); | |
40 | if(n2 !== null) | |
41 | initialNickname = n2; | |
42 | ||
43 | var c2 = this.cookie.get("autojoin"); | |
44 | if(c2 !== null) | |
45 | initialChannels = c2; | |
46 | } | |
47 | ||
48 | if(initialChannels === null) { | |
49 | initialChannels = ""; | |
50 | } | |
51 | ||
e89c812f CP |
52 | exec("[name=nickname]", util.setText(initialNickname)); |
53 | exec("[name=channels]", util.setText(initialChannels)); | |
54 | exec("[name=prettychannels]", function(node) { this.__buildPrettyChannels(node, initialChannels); }.bind(this)); | |
13afa38f | 55 | exec("[name=networkname]", util.setText(uiOptions.networkName)); |
e89c812f CP |
56 | |
57 | var focus = "connect"; | |
58 | if(autoConnect) { | |
59 | if(!autoNick) | |
60 | exec("[name=nickselected]", util.makeVisible); | |
61 | ||
62 | this.__validate = this.__validateConfirmData; | |
63 | } else { | |
64 | if(!initialNickname) { | |
65 | focus = "nickname"; | |
66 | } else if(initialNickname && !initialChannels) { | |
67 | focus = "channels"; | |
68 | } | |
69 | ||
70 | this.__validate = this.__validateLoginData; | |
71 | } | |
72 | ||
d84a2943 CP |
73 | var login = qwebirc.auth.loggedin(true); |
74 | if(login) { | |
75 | exec("[name=authname]", util.setText(login[0])); | |
65f2c94c CP |
76 | exec("[name=connectbutton]", util.makeVisible); |
77 | exec("[name=loginstatus]", util.makeVisible); | |
78 | } else { | |
79 | if(qwebirc.ui.isAuthRequired()) { | |
80 | exec("[name=loginconnectbutton]", util.makeVisible); | |
81 | if(focus == "connect") | |
82 | focus = "loginconnect"; | |
83 | } else { | |
84 | exec("[name=connectbutton]", util.makeVisible); | |
85 | exec("[name=loginbutton]", util.makeVisible); | |
86 | } | |
87 | } | |
88 | ||
00bd0d60 CP |
89 | if(window == window.top) /* don't focus when we're iframe'd */ |
90 | exec("[name=" + focus + "]", util.focus); | |
e89c812f | 91 | exec("[name=connect]", util.attachClick(this.__connect.bind(this))); |
65f2c94c | 92 | exec("[name=loginconnect]", util.attachClick(this.__loginConnect.bind(this))); |
3bf9d70e | 93 | |
65f2c94c | 94 | exec("[name=login]", util.attachClick(this.__login.bind(this))); |
3bf9d70e CP |
95 | |
96 | if(qwebirc.ui.isHideAuth()) | |
97 | exec("[name=login]", util.setVisible(false)); | |
e89c812f CP |
98 | }.bind(this)}); |
99 | r.get(); | |
100 | }, | |
101 | util: { | |
102 | makeVisible: function(x) { x.setStyle("display", ""); }, | |
65f2c94c | 103 | setVisible: function(y) { return function(x) { x.setStyle("display", y ? "" : "none"); }; }, |
2ba5d023 | 104 | focus: function(x) { try { x.focus(); } catch (e) { } }, |
e89c812f CP |
105 | attachClick: function(fn) { return function(x) { x.addListener("click", fn); } }, |
106 | setText: function(x) { return function(y) { | |
107 | if(typeof y.value === "undefined") { | |
108 | y.set("text", x); | |
109 | } else { | |
110 | y.value = x === null ? "" : x; | |
111 | } | |
112 | } } | |
113 | }, | |
114 | validate: function() { | |
115 | return this.__validate(); | |
116 | }, | |
117 | __connect: function(e) { | |
118 | new Event(e).stop(); | |
119 | var data = this.validate(); | |
120 | if(data === false) | |
121 | return; | |
66de775f | 122 | |
65f2c94c | 123 | this.__cancelLogin(); |
264025fd | 124 | this.fireEvent("close"); |
cbd6ec8c CP |
125 | this.cookie.extend(data); |
126 | this.cookie.save(); | |
e89c812f CP |
127 | this.options.callback(data); |
128 | }, | |
65f2c94c CP |
129 | __cancelLogin: function(noUIModifications) { |
130 | if(this.__cancelLoginCallback) | |
131 | this.__cancelLoginCallback(noUIModifications); | |
132 | }, | |
133 | __loginConnect: function(e) { | |
134 | new Event(e).stop(); | |
135 | if(this.validate() === false) | |
136 | return; | |
137 | ||
138 | this.__performLogin(function() { | |
139 | var data = this.validate(); | |
140 | if(data === false) { | |
141 | /* we're logged in -- show the normal join button */ | |
142 | this.util.exec("[name=connectbutton]", this.util.setVisible(true)); | |
143 | return; | |
144 | } | |
145 | ||
146 | this.fireEvent("close"); | |
147 | this.options.callback(data); | |
148 | }.bind(this), "loginconnectbutton"); | |
149 | }, | |
150 | __login: function(e) { | |
151 | new Event(e).stop(); | |
152 | ||
153 | this.__cancelLogin(true); | |
154 | ||
155 | this.__performLogin(function() { | |
156 | var focus = "connect"; | |
157 | if(!this.options.autoConnect) { | |
158 | var nick = this.rootElement.getElement("input[name=nickname]").value, chan = this.rootElement.getElement("input[name=channels]").value; | |
159 | if(!nick) { | |
160 | focus = "nickname"; | |
161 | } else if(!chan) { | |
162 | focus = "channels"; | |
163 | } | |
164 | } | |
165 | this.util.exec("[name=" + focus + "]", this.util.focus); | |
166 | }.bind(this), "login"); | |
167 | }, | |
168 | __performLogin: function(callback, calleename) { | |
65f2c94c CP |
169 | var handle = window.open("/auth", this.__windowName, "status=0,toolbar=0,location=1,menubar=0,directories=0,resizable=0,scrollbars=1,height=280,width=550"); |
170 | ||
171 | if(handle === null || handle === undefined) { | |
65f2c94c | 172 | return; |
2bc12bd6 | 173 | } |
65f2c94c CP |
174 | |
175 | var closeDetector = function() { | |
176 | if(handle.closed) | |
177 | this.__cancelLoginCallback(); | |
178 | }.bind(this); | |
179 | var closeCallback = closeDetector.periodical(100); | |
180 | ||
181 | this.__cancelLoginCallback = function(noUIModifications) { | |
182 | $clear(closeCallback); | |
183 | ||
65f2c94c CP |
184 | try { |
185 | handle.close(); | |
186 | } catch(e) { | |
187 | } | |
188 | ||
189 | if(!noUIModifications) { | |
190 | this.util.exec("[name=loggingin]", this.util.setVisible(false)); | |
191 | this.util.exec("[name=" + calleename + "]", this.util.setVisible(true)); | |
192 | } | |
193 | this.__cancelLoginCallback = null; | |
194 | }.bind(this); | |
195 | ||
d84a2943 CP |
196 | __qwebircAuthCallback = function(qticket, qticketUsername, realExpiry) { |
197 | if (typeof sessionStorage === "undefined") | |
198 | { | |
199 | alert("No session storage support in this browser -- login not supported"); | |
200 | this.__cancelLoginCallback(false); | |
201 | return; | |
202 | } | |
65f2c94c | 203 | |
65f2c94c | 204 | this.__cancelLoginCallback(true); |
d84a2943 CP |
205 | sessionStorage.setItem("qticket", qticket); |
206 | sessionStorage.setItem("qticket_username", qticketUsername); | |
207 | sessionStorage.setItem("qticket_expiry", realExpiry); | |
65f2c94c CP |
208 | |
209 | this.util.exec("[name=loggingin]", this.util.setVisible(false)); | |
210 | this.util.exec("[name=loginstatus]", this.util.setVisible(true)); | |
d84a2943 | 211 | this.util.exec("[name=authname]", this.util.setText(qticketUsername)); |
65f2c94c CP |
212 | callback(); |
213 | }.bind(this); | |
214 | ||
d84a2943 CP |
215 | this.util.exec("[name=loggingin]", this.util.setVisible(true)); |
216 | this.util.exec("[name=" + calleename + "]", this.util.setVisible(false)); | |
65f2c94c | 217 | }, |
e89c812f CP |
218 | __validateConfirmData: function() { |
219 | return {nickname: this.options.initialNickname, autojoin: this.options.initialChannels}; | |
220 | }, | |
221 | __validateLoginData: function() { | |
222 | var nick = this.rootElement.getElement("input[name=nickname]"), chan = this.rootElement.getElement("input[name=channels]"); | |
66de775f | 223 | |
e89c812f CP |
224 | var nickname = nick.value; |
225 | var chans = chan.value; | |
226 | if(chans == "#") /* sorry channel "#" :P */ | |
227 | chans = ""; | |
66de775f | 228 | |
e89c812f CP |
229 | if(!nickname) { |
230 | alert("You must supply a nickname."); | |
231 | nick.focus(); | |
232 | return false; | |
233 | } | |
66de775f | 234 | |
fc25cf01 CP |
235 | var stripped = qwebirc.global.nicknameValidator.validate(nickname); |
236 | if(stripped != nickname) { | |
237 | nick.value = stripped; | |
238 | alert("Your nickname was invalid and has been corrected; please check your altered nickname and try again."); | |
239 | nick.focus(); | |
240 | return false; | |
2f74dea9 CP |
241 | } |
242 | ||
e89c812f CP |
243 | var data = {nickname: nickname, autojoin: chans}; |
244 | return data; | |
245 | }, | |
246 | __buildPrettyChannels: function(node, channels) { | |
247 | var c = channels.split(" ")[0].split(","); | |
248 | node.appendChild(document.createTextNode("channel" + ((c.length>1)?"s":"") + " ")); | |
249 | for(var i=0;i<c.length;i++) { | |
250 | if((c.length > 1) && (i == c.length - 1)) { | |
251 | node.appendChild(document.createTextNode(" and ")); | |
252 | } else if(i > 0) { | |
253 | node.appendChild(document.createTextNode(", ")); | |
254 | } | |
255 | node.appendChild(new Element("b").set("text", c[i])); | |
2f74dea9 | 256 | } |
66de775f | 257 | } |
e89c812f | 258 | }); |
66de775f | 259 | |
e89c812f CP |
260 | qwebirc.ui.LoginBox2 = function(parentElement, callback, initialNickname, initialChannels, networkName) { |
261 | /* | |
6ce70043 CP |
262 | if(qwebirc.auth.enabled()) { |
263 | if(qwebirc.auth.passAuth()) { | |
264 | var authRow = createRow("Auth to services:"); | |
265 | var authCheckBox = qwebirc.util.createInput("checkbox", authRow, "connect_auth_to_services", false); | |
2f74dea9 | 266 | |
6ce70043 CP |
267 | var usernameBox = new Element("input"); |
268 | var usernameRow = createRow("Username:", usernameBox, {display: "none"})[0]; | |
2f74dea9 | 269 | |
6ce70043 CP |
270 | var passwordRow = createRow("Password:", null, {display: "none"}); |
271 | var passwordBox = qwebirc.util.createInput("password", passwordRow[1], "connect_auth_password"); | |
2f74dea9 | 272 | |
6ce70043 CP |
273 | authCheckBox.addEvent("click", function(e) { qwebirc.ui.authShowHide(authCheckBox, authRow, usernameBox, usernameRow, passwordRow[0]) }); |
274 | } else if(qwebirc.auth.bouncerAuth()) { | |
275 | var passwordRow = createRow("Password:"); | |
276 | var passwordBox = qwebirc.util.createInput("password", passwordRow, "connect_auth_password"); | |
277 | } | |
2f74dea9 | 278 | } |
e89c812f CP |
279 | */ |
280 | ||
66de775f CP |
281 | var connbutton = new Element("input", {"type": "submit"}); |
282 | connbutton.set("value", "Connect"); | |
2f74dea9 CP |
283 | var r = createRow(undefined, connbutton); |
284 | ||
66de775f CP |
285 | form.addEvent("submit", function(e) { |
286 | new Event(e).stop(); | |
66de775f | 287 | |
66de775f CP |
288 | var nickname = nick.value; |
289 | var chans = chan.value; | |
290 | if(chans == "#") /* sorry channel "#" :P */ | |
291 | chans = ""; | |
292 | ||
293 | if(!nickname) { | |
294 | alert("You must supply a nickname."); | |
295 | nick.focus(); | |
296 | return; | |
297 | } | |
cc608160 CP |
298 | var stripped = qwebirc.global.nicknameValidator.validate(nickname); |
299 | if(stripped != nickname) { | |
300 | nick.value = stripped; | |
301 | alert("Your nickname was invalid and has been corrected; please check your altered nickname and press Connect again."); | |
302 | nick.focus(); | |
303 | return; | |
304 | } | |
305 | ||
2f74dea9 | 306 | var data = {"nickname": nickname, "autojoin": chans}; |
6f848bbb CP |
307 | if(qwebirc.auth.enabled()) { |
308 | if(qwebirc.auth.passAuth() && authCheckBox.checked) { | |
309 | if(!usernameBox.value || !passwordBox.value) { | |
310 | alert("You must supply your username and password in auth mode."); | |
311 | if(!usernameBox.value) { | |
312 | usernameBox.focus(); | |
313 | } else { | |
314 | passwordBox.focus(); | |
315 | } | |
316 | return; | |
6ce70043 | 317 | } |
6f848bbb CP |
318 | |
319 | data["serverPassword"] = usernameBox.value + " " + passwordBox.value; | |
320 | } else if(qwebirc.auth.bouncerAuth()) { | |
321 | if(!passwordBox.value) { | |
322 | alert("You must supply a password."); | |
323 | passwordBox.focus(); | |
6ce70043 CP |
324 | return; |
325 | } | |
326 | ||
6f848bbb | 327 | data["serverPassword"] = passwordBox.value; |
6ce70043 | 328 | } |
6ce70043 | 329 | } |
6ce70043 CP |
330 | parentElement.removeChild(outerbox); |
331 | ||
2f74dea9 | 332 | callback(data); |
66de775f | 333 | }.bind(this)); |
6ce70043 | 334 | |
66de775f CP |
335 | nick.set("value", initialNickname); |
336 | chan.set("value", initialChannels); | |
337 | ||
b1a46dae | 338 | if(window == window.top) |
9a1c691c | 339 | nick.focus(); |
cad18909 | 340 | } |
2f74dea9 CP |
341 | |
342 | qwebirc.ui.authShowHide = function(checkbox, authRow, usernameBox, usernameRow, passwordRow) { | |
343 | var visible = checkbox.checked; | |
344 | var display = visible?null:"none"; | |
345 | usernameRow.setStyle("display", display); | |
346 | passwordRow.setStyle("display", display); | |
347 | ||
348 | if(visible) { | |
349 | // authRow.parentNode.setStyle("display", "none"); | |
350 | usernameBox.focus(); | |
351 | } | |
352 | } | |
65f2c94c CP |
353 | |
354 | qwebirc.ui.isAuthRequired = (function() { | |
355 | var args = qwebirc.util.parseURI(String(document.location)); | |
86100f08 | 356 | var value = $defined(args) && args.get("authrequired"); |
65f2c94c CP |
357 | return function() { |
358 | return value && qwebirc.auth.enabled(); | |
359 | }; | |
360 | })(); | |
361 | ||
3bf9d70e CP |
362 | qwebirc.ui.isHideAuth = (function() { |
363 | var args = qwebirc.util.parseURI(String(document.location)); | |
86100f08 | 364 | var value = $defined(args) && args.get("hideauth"); |
3bf9d70e CP |
365 | return function() { |
366 | return value; | |
367 | }; | |
368 | })(); | |
369 |