]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/panes/connect.js
Add nickname validation.
[irc/quakenet/qwebirc.git] / js / ui / panes / connect.js
CommitLineData
2cad083e 1qwebirc.ui.GenericLoginBox = function(parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick, networkName) {
66de775f 2 if(autoConnect) {
2cad083e 3 qwebirc.ui.ConfirmBox(parentElement, callback, initialNickname, initialChannels, autoNick, networkName);
66de775f 4 } else {
2cad083e 5 qwebirc.ui.LoginBox(parentElement, callback, initialNickname, initialChannels, networkName);
66de775f
CP
6 }
7}
8
fb661c98
CP
9qwebirc.ui.AuthLogin = function(e) {
10 var cookie = Cookie.write("redirect", document.location);
fbe5af77 11 document.location = qwebirc.global.dynamicBaseURL + "auth/";
fb661c98
CP
12 new Event(e).stop();
13}
14
2cad083e 15qwebirc.ui.ConfirmBox = function(parentElement, callback, initialNickname, initialChannels, autoNick, networkName) {
d3ab254a
CP
16 var outerbox = new Element("table");
17 outerbox.addClass("qwebirc-centrebox");
18 parentElement.appendChild(outerbox);
19 var tbody = new Element("tbody");
20 outerbox.appendChild(tbody);
21 var tr = new Element("tr");
22 tbody.appendChild(tr);
23 var td = new Element("td");
24 tr.appendChild(td);
25
90b89aee 26 var box = new Element("table");
e1a91a8a 27 box.addClass("qwebirc-confirmbox");
d3ab254a 28 td.appendChild(box);
66de775f 29
95ce57b3
CP
30 var tbody = new Element("tbody");
31 box.appendChild(tbody);
32
90b89aee 33 var tr = new Element("tr");
95ce57b3 34 tbody.appendChild(tr);
90b89aee
CP
35 tr.addClass("tr1");
36
37 var text = new Element("td");
38 tr.appendChild(text);
39
66de775f
CP
40 var nick = new Element("b");
41 nick.set("text", initialNickname);
42
290c60db 43 var c = initialChannels.split(" ")[0].split(",");
66de775f 44
2cad083e 45 text.appendChild(document.createTextNode("To connect to " + networkName + " IRC and join channel" + ((c.length>1)?"s":"") + " "));
290c60db
CP
46
47 for(var i=0;i<c.length;i++) {
48 if((c.length > 1) && (i == c.length - 1)) {
49 text.appendChild(document.createTextNode(" and "));
50 } else if(i > 0) {
51 text.appendChild(document.createTextNode(", "));
52 }
53 text.appendChild(new Element("b").set("text", c[i]));
54
66de775f
CP
55 }
56
66de775f
CP
57 if(!autoNick) {
58 text.appendChild(document.createTextNode(" as "));
59 text.appendChild(nick);
2cad083e
CP
60 }
61
66de775f 62 text.appendChild(document.createTextNode(" click 'Connect'."));
74caeb3e 63 text.appendChild(new Element("br"));
6ce70043 64 if(qwebirc.auth.enabled() && qwebirc.auth.quakeNetAuth() && !qwebirc.auth.loggedin())
74caeb3e
CP
65 text.appendChild(document.createTextNode("If you'd like to connect using your Q auth click 'Log in'."));
66
90b89aee 67 var tr = new Element("tr");
95ce57b3 68 tbody.appendChild(tr);
90b89aee 69 tr.addClass("tr2");
66de775f 70
90b89aee
CP
71 var td = new Element("td");
72 tr.appendChild(td);
73
66de775f 74 var yes = new Element("input", {"type": "submit", "value": "Connect"});
f065bc69 75 td.appendChild(yes);
f065bc69 76 yes.addEvent("click", function(e) {
5fc104ff 77 parentElement.removeChild(outerbox);
66de775f
CP
78 callback({"nickname": initialNickname, "autojoin": initialChannels});
79 });
f065bc69 80
6ce70043 81 if(qwebirc.auth.enabled() && qwebirc.auth.quakeNetAuth() && !qwebirc.auth.loggedin()) {
f065bc69
CP
82 var auth = new Element("input", {"type": "submit", "value": "Log in"});
83 td.appendChild(auth);
fb661c98 84 auth.addEvent("click", qwebirc.ui.AuthLogin);
f065bc69 85 }
9a1c691c 86
b1a46dae 87 if(window == window.top)
9a1c691c 88 yes.focus();
66de775f
CP
89}
90
2cad083e 91qwebirc.ui.LoginBox = function(parentElement, callback, initialNickname, initialChannels, networkName) {
d3ab254a
CP
92 var outerbox = new Element("table");
93 outerbox.addClass("qwebirc-centrebox");
94 parentElement.appendChild(outerbox);
95 var tbody = new Element("tbody");
96 outerbox.appendChild(tbody);
97 var tr = new Element("tr");
98 tbody.appendChild(tr);
99 var td = new Element("td");
100 tr.appendChild(td);
101
90b89aee 102 var box = new Element("table");
e1a91a8a 103 box.addClass("qwebirc-loginbox");
d3ab254a 104 td.appendChild(box);
90b89aee 105
95ce57b3
CP
106 var tbody = new Element("tbody");
107 box.appendChild(tbody);
108
90b89aee 109 var tr = new Element("tr");
95ce57b3 110 tbody.appendChild(tr);
90b89aee 111 tr.addClass("tr1");
66de775f 112
90b89aee
CP
113 var td = new Element("td");
114 tr.appendChild(td);
2cad083e 115 td.set("html", "<h1>Connect to " + networkName + " IRC</h1>");
95ce57b3 116
90b89aee 117 var tr = new Element("tr");
95ce57b3 118 tbody.appendChild(tr);
90b89aee
CP
119 tr.addClass("tr2");
120
90b89aee
CP
121 var td = new Element("td");
122 tr.appendChild(td);
95ce57b3 123
66de775f 124 var form = new Element("form");
90b89aee 125 td.appendChild(form);
66de775f
CP
126
127 var boxtable = new Element("table");
128 form.appendChild(boxtable);
129
130 var tbody = new Element("tbody");
131 boxtable.appendChild(tbody); /* stupid IE */
132
2f74dea9 133 function createRow(label, e2, style) {
66de775f
CP
134 var r = new Element("tr");
135 tbody.appendChild(r);
136
137 var d1 = new Element("td");
138 if(label)
139 d1.set("text", label);
140 r.appendChild(d1);
141
142 var d2 = new Element("td");
143 r.appendChild(d2);
2f74dea9
CP
144
145 if($defined(e2))
146 d2.appendChild(e2);
147 if($defined(style)) {
148 r.setStyles(style);
149 return [r, d2];
150 }
151
fb661c98 152 return d2;
66de775f
CP
153 }
154
155 var nick = new Element("input");
156 createRow("Nickname:", nick);
6ce70043
CP
157
158 var chanStyle = null;
159 if(qwebirc.auth.enabled() && qwebirc.auth.bouncerAuth())
160 chanStyle = {display: "none"};
161
66de775f 162 var chan = new Element("input");
6ce70043 163 createRow("Channels:", chan, chanStyle);
66de775f 164
6ce70043
CP
165 if(qwebirc.auth.enabled()) {
166 if(qwebirc.auth.passAuth()) {
167 var authRow = createRow("Auth to services:");
168 var authCheckBox = qwebirc.util.createInput("checkbox", authRow, "connect_auth_to_services", false);
2f74dea9 169
6ce70043
CP
170 var usernameBox = new Element("input");
171 var usernameRow = createRow("Username:", usernameBox, {display: "none"})[0];
2f74dea9 172
6ce70043
CP
173 var passwordRow = createRow("Password:", null, {display: "none"});
174 var passwordBox = qwebirc.util.createInput("password", passwordRow[1], "connect_auth_password");
2f74dea9 175
6ce70043
CP
176 authCheckBox.addEvent("click", function(e) { qwebirc.ui.authShowHide(authCheckBox, authRow, usernameBox, usernameRow, passwordRow[0]) });
177 } else if(qwebirc.auth.bouncerAuth()) {
178 var passwordRow = createRow("Password:");
179 var passwordBox = qwebirc.util.createInput("password", passwordRow, "connect_auth_password");
180 }
2f74dea9
CP
181 }
182
66de775f
CP
183 var connbutton = new Element("input", {"type": "submit"});
184 connbutton.set("value", "Connect");
2f74dea9
CP
185 var r = createRow(undefined, connbutton);
186
187 if(qwebirc.auth.enabled() && qwebirc.auth.quakeNetAuth() && !qwebirc.auth.loggedin()) {
fb661c98
CP
188 var auth = new Element("input", {"type": "submit", "value": "Log in"});
189 r.appendChild(auth);
190 auth.addEvent("click", qwebirc.ui.AuthLogin);
191 }
66de775f
CP
192
193 form.addEvent("submit", function(e) {
194 new Event(e).stop();
195 var nickname = nick.value;
196 var chans = chan.value;
197 if(chans == "#") /* sorry channel "#" :P */
198 chans = "";
199
200 if(!nickname) {
201 alert("You must supply a nickname.");
202 nick.focus();
203 return;
204 }
cc608160
CP
205 var stripped = qwebirc.global.nicknameValidator.validate(nickname);
206 if(stripped != nickname) {
207 nick.value = stripped;
208 alert("Your nickname was invalid and has been corrected; please check your altered nickname and press Connect again.");
209 nick.focus();
210 return;
211 }
212
2f74dea9 213 var data = {"nickname": nickname, "autojoin": chans};
6f848bbb
CP
214 if(qwebirc.auth.enabled()) {
215 if(qwebirc.auth.passAuth() && authCheckBox.checked) {
216 if(!usernameBox.value || !passwordBox.value) {
217 alert("You must supply your username and password in auth mode.");
218 if(!usernameBox.value) {
219 usernameBox.focus();
220 } else {
221 passwordBox.focus();
222 }
223 return;
6ce70043 224 }
6f848bbb
CP
225
226 data["serverPassword"] = usernameBox.value + " " + passwordBox.value;
227 } else if(qwebirc.auth.bouncerAuth()) {
228 if(!passwordBox.value) {
229 alert("You must supply a password.");
230 passwordBox.focus();
6ce70043
CP
231 return;
232 }
233
6f848bbb 234 data["serverPassword"] = passwordBox.value;
6ce70043 235 }
6ce70043 236 }
6ce70043
CP
237 parentElement.removeChild(outerbox);
238
2f74dea9 239 callback(data);
66de775f 240 }.bind(this));
6ce70043 241
66de775f
CP
242 nick.set("value", initialNickname);
243 chan.set("value", initialChannels);
244
b1a46dae 245 if(window == window.top)
9a1c691c 246 nick.focus();
cad18909 247}
2f74dea9
CP
248
249qwebirc.ui.authShowHide = function(checkbox, authRow, usernameBox, usernameRow, passwordRow) {
250 var visible = checkbox.checked;
251 var display = visible?null:"none";
252 usernameRow.setStyle("display", display);
253 passwordRow.setStyle("display", display);
254
255 if(visible) {
256// authRow.parentNode.setStyle("display", "none");
257 usernameBox.focus();
258 }
259}