]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/connect.js
1 qwebirc
.ui
.ConnectPane
= new Class({
3 initialize: function(parent
, options
) {
4 var callback
= options
.callback
, initialNickname
= options
.initialNickname
, initialChannels
= options
.initialChannels
, autoConnect
= options
.autoConnect
, autoNick
= options
.autoNick
;
5 this.options
= options
;
6 var uiOptions
= options
.uiOptions
;
7 this.__windowName
= "authgate_" + Math
.floor(Math
.random() * 100000);
9 var delayfn = function() { parent
.set("html", "<div class=\"loading\">Loading. . .</div>"); };
10 var cb
= delayfn
.delay(500);
12 var r
= qwebirc
.ui
.RequestTransformHTML({url: qwebirc
.global
.staticBaseURL
+ "panes/connect.html", update: parent
, onSuccess: function() {
15 var rootElement
= parent
.getElement("[name=connectroot]");
16 this.rootElement
= rootElement
;
18 this.util
.exec = function(n
, x
) { rootElement
.getElements(n
).each(x
); };
22 var box
= (autoConnect
? "confirm" : "login");
23 exec("[name=" + box
+ "box]", util
.setVisible(true));
26 if($defined(uiOptions
.logoURL
)) {
27 var logoBar
= parent
.getElement("[class=bar-logo]");
29 logoBar
.setAttribute("style", "background: url(" + uiOptions
.logoURL
+ ") no-repeat center top; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + uiOptions
.logoURL
+ "',sizingMethod='crop');");
31 util
.makeVisible(parent
.getElement("[name=loginheader]"));
33 util
.makeVisible(parent
.getElement("[name=nologologinheader]"));
37 exec("[name=nickname]", util
.setText(initialNickname
));
38 exec("[name=channels]", util
.setText(initialChannels
));
39 exec("[name=prettychannels]", function(node
) { this.__buildPrettyChannels(node
, initialChannels
); }.bind(this));
40 exec("[name=networkname]", util
.setText(uiOptions
.networkName
));
42 var focus
= "connect";
45 exec("[name=nickselected]", util
.makeVisible
);
47 this.__validate
= this.__validateConfirmData
;
49 if(!initialNickname
) {
51 } else if(initialNickname
&& !initialChannels
) {
55 this.__validate
= this.__validateLoginData
;
58 if(qwebirc
.auth
.loggedin()) {
59 exec("[name=authname]", util
.setText(qwebirc
.auth
.loggedin()));
60 exec("[name=connectbutton]", util
.makeVisible
);
61 exec("[name=loginstatus]", util
.makeVisible
);
63 if(qwebirc
.ui
.isAuthRequired()) {
64 exec("[name=loginconnectbutton]", util
.makeVisible
);
65 if(focus
== "connect")
66 focus
= "loginconnect";
68 exec("[name=connectbutton]", util
.makeVisible
);
69 exec("[name=loginbutton]", util
.makeVisible
);
73 if(window
== window
.top
) /* don't focus when we're iframe'd */
74 exec("[name=" + focus
+ "]", util
.focus
);
75 exec("[name=connect]", util
.attachClick(this.__connect
.bind(this)));
76 exec("[name=loginconnect]", util
.attachClick(this.__loginConnect
.bind(this)));
78 exec("[name=login]", util
.attachClick(this.__login
.bind(this)));
80 if(qwebirc
.ui
.isHideAuth())
81 exec("[name=login]", util
.setVisible(false));
86 makeVisible: function(x
) { x
.setStyle("display", ""); },
87 setVisible: function(y
) { return function(x
) { x
.setStyle("display", y
? "" : "none"); }; },
88 focus: function(x
) { x
.focus(); },
89 attachClick: function(fn
) { return function(x
) { x
.addListener("click", fn
); } },
90 setText: function(x
) { return function(y
) {
91 if(typeof y
.value
=== "undefined") {
94 y
.value
= x
=== null ? "" : x
;
98 validate: function() {
99 return this.__validate();
101 __connect: function(e
) {
103 var data
= this.validate();
107 this.__cancelLogin();
108 this.fireEvent("close");
109 this.options
.callback(data
);
111 __cancelLogin: function(noUIModifications
) {
112 if(this.__cancelLoginCallback
)
113 this.__cancelLoginCallback(noUIModifications
);
115 __loginConnect: function(e
) {
117 if(this.validate() === false)
120 this.__performLogin(function() {
121 var data
= this.validate();
123 /* we're logged in -- show the normal join button */
124 this.util
.exec("[name=connectbutton]", this.util
.setVisible(true));
128 this.fireEvent("close");
129 this.options
.callback(data
);
130 }.bind(this), "loginconnectbutton");
132 __login: function(e
) {
135 this.__cancelLogin(true);
137 this.__performLogin(function() {
138 var focus
= "connect";
139 if(!this.options
.autoConnect
) {
140 var nick
= this.rootElement
.getElement("input[name=nickname]").value
, chan
= this.rootElement
.getElement("input[name=channels]").value
;
147 this.util
.exec("[name=" + focus
+ "]", this.util
.focus
);
148 }.bind(this), "login");
150 __performLogin: function(callback
, calleename
) {
151 Cookie
.write("jslogin", "1");
153 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");
155 if(handle
=== null || handle
=== undefined) {
156 Cookie
.dispose("jslogin");
157 // Cookie.write("redirect", document.location);
158 // window.location = "auth?";
162 var closeDetector = function() {
164 this.__cancelLoginCallback();
166 var closeCallback
= closeDetector
.periodical(100);
168 this.__cancelLoginCallback = function(noUIModifications
) {
169 $clear(closeCallback
);
171 Cookie
.dispose("jslogin");
178 if(!noUIModifications
) {
179 this.util
.exec("[name=loggingin]", this.util
.setVisible(false));
180 this.util
.exec("[name=" + calleename
+ "]", this.util
.setVisible(true));
182 this.__cancelLoginCallback
= null;
185 this.util
.exec("[name=loggingin]", this.util
.setVisible(true));
186 this.util
.exec("[name=" + calleename
+ "]", this.util
.setVisible(false));
188 __qwebircAuthCallback = function(username
, expiry
, serverNow
) {
189 this.__cancelLoginCallback(true);
191 var now
= new Date().getTime();
192 var offset
= (serverNow
* 1000) - now
;
193 var ourExpiry
= expiry
* 1000 - offset
;
194 Cookie
.write("ticketexpiry", ourExpiry
)
196 this.util
.exec("[name=loggingin]", this.util
.setVisible(false));
197 this.util
.exec("[name=loginstatus]", this.util
.setVisible(true));
198 this.util
.exec("[name=authname]", this.util
.setText(username
));
203 __validateConfirmData: function() {
204 return {nickname: this.options
.initialNickname
, autojoin: this.options
.initialChannels
};
206 __validateLoginData: function() {
207 var nick
= this.rootElement
.getElement("input[name=nickname]"), chan
= this.rootElement
.getElement("input[name=channels]");
209 var nickname
= nick
.value
;
210 var chans
= chan
.value
;
211 if(chans
== "#") /* sorry channel "#" :P */
215 alert("You must supply a nickname.");
220 var stripped
= qwebirc
.global
.nicknameValidator
.validate(nickname
);
221 if(stripped
!= nickname
) {
222 nick
.value
= stripped
;
223 alert("Your nickname was invalid and has been corrected; please check your altered nickname and try again.");
228 var data
= {nickname: nickname
, autojoin: chans
};
231 __buildPrettyChannels: function(node
, channels
) {
232 var c
= channels
.split(" ")[0].split(",");
233 node
.appendChild(document
.createTextNode("channel" + ((c
.length
>1)?"s":"") + " "));
234 for(var i
=0;i
<c
.length
;i
++) {
235 if((c
.length
> 1) && (i
== c
.length
- 1)) {
236 node
.appendChild(document
.createTextNode(" and "));
238 node
.appendChild(document
.createTextNode(", "));
240 node
.appendChild(new Element("b").set("text", c
[i
]));
245 qwebirc
.ui
.LoginBox2 = function(parentElement
, callback
, initialNickname
, initialChannels
, networkName
) {
247 if(qwebirc.auth.enabled()) {
248 if(qwebirc.auth.passAuth()) {
249 var authRow = createRow("Auth to services:");
250 var authCheckBox = qwebirc.util.createInput("checkbox", authRow, "connect_auth_to_services", false);
252 var usernameBox = new Element("input");
253 var usernameRow = createRow("Username:", usernameBox, {display: "none"})[0];
255 var passwordRow = createRow("Password:", null, {display: "none"});
256 var passwordBox = qwebirc.util.createInput("password", passwordRow[1], "connect_auth_password");
258 authCheckBox.addEvent("click", function(e) { qwebirc.ui.authShowHide(authCheckBox, authRow, usernameBox, usernameRow, passwordRow[0]) });
259 } else if(qwebirc.auth.bouncerAuth()) {
260 var passwordRow = createRow("Password:");
261 var passwordBox = qwebirc.util.createInput("password", passwordRow, "connect_auth_password");
266 var connbutton
= new Element("input", {"type": "submit"});
267 connbutton
.set("value", "Connect");
268 var r
= createRow(undefined, connbutton
);
270 form
.addEvent("submit", function(e
) {
273 var nickname
= nick
.value
;
274 var chans
= chan
.value
;
275 if(chans
== "#") /* sorry channel "#" :P */
279 alert("You must supply a nickname.");
283 var stripped
= qwebirc
.global
.nicknameValidator
.validate(nickname
);
284 if(stripped
!= nickname
) {
285 nick
.value
= stripped
;
286 alert("Your nickname was invalid and has been corrected; please check your altered nickname and press Connect again.");
291 var data
= {"nickname": nickname
, "autojoin": chans
};
292 if(qwebirc
.auth
.enabled()) {
293 if(qwebirc
.auth
.passAuth() && authCheckBox
.checked
) {
294 if(!usernameBox
.value
|| !passwordBox
.value
) {
295 alert("You must supply your username and password in auth mode.");
296 if(!usernameBox
.value
) {
304 data
["serverPassword"] = usernameBox
.value
+ " " + passwordBox
.value
;
305 } else if(qwebirc
.auth
.bouncerAuth()) {
306 if(!passwordBox
.value
) {
307 alert("You must supply a password.");
312 data
["serverPassword"] = passwordBox
.value
;
315 parentElement
.removeChild(outerbox
);
320 nick
.set("value", initialNickname
);
321 chan
.set("value", initialChannels
);
323 if(window
== window
.top
)
327 qwebirc
.ui
.authShowHide = function(checkbox
, authRow
, usernameBox
, usernameRow
, passwordRow
) {
328 var visible
= checkbox
.checked
;
329 var display
= visible
?null:"none";
330 usernameRow
.setStyle("display", display
);
331 passwordRow
.setStyle("display", display
);
334 // authRow.parentNode.setStyle("display", "none");
339 qwebirc
.ui
.isAuthRequired
= (function() {
340 var args
= qwebirc
.util
.parseURI(String(document
.location
));
341 var value
= $defined(args
) && args
.get("authrequired");
343 return value
&& qwebirc
.auth
.enabled();
347 qwebirc
.ui
.isHideAuth
= (function() {
348 var args
= qwebirc
.util
.parseURI(String(document
.location
));
349 var value
= $defined(args
) && args
.get("hideauth");