]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/connect.js
Attempt #2 at not focusing while iframed.
[irc/quakenet/qwebirc.git] / js / ui / panes / connect.js
1 qwebirc.ui.GenericLoginBox = function(parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick, networkName) {
2 if(autoConnect) {
3 qwebirc.ui.ConfirmBox(parentElement, callback, initialNickname, initialChannels, autoNick, networkName);
4 } else {
5 qwebirc.ui.LoginBox(parentElement, callback, initialNickname, initialChannels, networkName);
6 }
7 }
8
9 qwebirc.ui.AuthLogin = function(e) {
10 var cookie = Cookie.write("redirect", document.location);
11 document.location = qwebirc.global.dynamicBaseURL + "auth/";
12 new Event(e).stop();
13 }
14
15 qwebirc.ui.ConfirmBox = function(parentElement, callback, initialNickname, initialChannels, autoNick, networkName) {
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
26 var box = new Element("table");
27 box.addClass("qwebirc-confirmbox");
28 td.appendChild(box);
29
30 var tbody = new Element("tbody");
31 box.appendChild(tbody);
32
33 var tr = new Element("tr");
34 tbody.appendChild(tr);
35 tr.addClass("tr1");
36
37 var text = new Element("td");
38 tr.appendChild(text);
39
40 var nick = new Element("b");
41 nick.set("text", initialNickname);
42
43 var c = initialChannels.split(" ")[0].split(",");
44
45 text.appendChild(document.createTextNode("To connect to " + networkName + " IRC and join channel" + ((c.length>1)?"s":"") + " "));
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
55 }
56
57 if(!autoNick) {
58 text.appendChild(document.createTextNode(" as "));
59 text.appendChild(nick);
60 }
61
62 text.appendChild(document.createTextNode(" click 'Connect'."));
63 text.appendChild(new Element("br"));
64 if(qwebirc.auth.enabled() && qwebirc.auth.quakeNetAuth() && !qwebirc.auth.loggedin())
65 text.appendChild(document.createTextNode("If you'd like to connect using your Q auth click 'Log in'."));
66
67 var tr = new Element("tr");
68 tbody.appendChild(tr);
69 tr.addClass("tr2");
70
71 var td = new Element("td");
72 tr.appendChild(td);
73
74 var yes = new Element("input", {"type": "submit", "value": "Connect"});
75 td.appendChild(yes);
76 yes.addEvent("click", function(e) {
77 parentElement.removeChild(outerbox);
78 callback({"nickname": initialNickname, "autojoin": initialChannels});
79 });
80
81 if(qwebirc.auth.enabled() && qwebirc.auth.quakeNetAuth() && !qwebirc.auth.loggedin()) {
82 var auth = new Element("input", {"type": "submit", "value": "Log in"});
83 td.appendChild(auth);
84 auth.addEvent("click", qwebirc.ui.AuthLogin);
85 }
86
87 if(window == window.top)
88 yes.focus();
89 }
90
91 qwebirc.ui.LoginBox = function(parentElement, callback, initialNickname, initialChannels, networkName) {
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
102 var box = new Element("table");
103 box.addClass("qwebirc-loginbox");
104 td.appendChild(box);
105
106 var tbody = new Element("tbody");
107 box.appendChild(tbody);
108
109 var tr = new Element("tr");
110 tbody.appendChild(tr);
111 tr.addClass("tr1");
112
113 var td = new Element("td");
114 tr.appendChild(td);
115 td.set("html", "<h1>Connect to " + networkName + " IRC</h1>");
116
117 var tr = new Element("tr");
118 tbody.appendChild(tr);
119 tr.addClass("tr2");
120
121 var td = new Element("td");
122 tr.appendChild(td);
123
124 var form = new Element("form");
125 td.appendChild(form);
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
133 function createRow(label, e2, style) {
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);
144
145 if($defined(e2))
146 d2.appendChild(e2);
147 if($defined(style)) {
148 r.setStyles(style);
149 return [r, d2];
150 }
151
152 return d2;
153 }
154
155 var nick = new Element("input");
156 createRow("Nickname:", nick);
157
158 var chanStyle = null;
159 if(qwebirc.auth.enabled() && qwebirc.auth.bouncerAuth())
160 chanStyle = {display: "none"};
161
162 var chan = new Element("input");
163 createRow("Channels:", chan, chanStyle);
164
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);
169
170 var usernameBox = new Element("input");
171 var usernameRow = createRow("Username:", usernameBox, {display: "none"})[0];
172
173 var passwordRow = createRow("Password:", null, {display: "none"});
174 var passwordBox = qwebirc.util.createInput("password", passwordRow[1], "connect_auth_password");
175
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 }
181 }
182
183 var connbutton = new Element("input", {"type": "submit"});
184 connbutton.set("value", "Connect");
185 var r = createRow(undefined, connbutton);
186
187 if(qwebirc.auth.enabled() && qwebirc.auth.quakeNetAuth() && !qwebirc.auth.loggedin()) {
188 var auth = new Element("input", {"type": "submit", "value": "Log in"});
189 r.appendChild(auth);
190 auth.addEvent("click", qwebirc.ui.AuthLogin);
191 }
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 }
205
206 var data = {"nickname": nickname, "autojoin": chans};
207 if(qwebirc.auth.enabled()) {
208 if(qwebirc.auth.passAuth() && authCheckBox.checked) {
209 if(!usernameBox.value || !passwordBox.value) {
210 alert("You must supply your username and password in auth mode.");
211 if(!usernameBox.value) {
212 usernameBox.focus();
213 } else {
214 passwordBox.focus();
215 }
216 return;
217 }
218
219 data["serverPassword"] = usernameBox.value + " " + passwordBox.value;
220 } else if(qwebirc.auth.bouncerAuth()) {
221 if(!passwordBox.value) {
222 alert("You must supply a password.");
223 passwordBox.focus();
224 return;
225 }
226
227 data["serverPassword"] = passwordBox.value;
228 }
229 }
230 parentElement.removeChild(outerbox);
231
232 callback(data);
233 }.bind(this));
234
235 nick.set("value", initialNickname);
236 chan.set("value", initialChannels);
237
238 if(window == window.top)
239 nick.focus();
240 }
241
242 qwebirc.ui.authShowHide = function(checkbox, authRow, usernameBox, usernameRow, passwordRow) {
243 var visible = checkbox.checked;
244 var display = visible?null:"none";
245 usernameRow.setStyle("display", display);
246 passwordRow.setStyle("display", display);
247
248 if(visible) {
249 // authRow.parentNode.setStyle("display", "none");
250 usernameBox.focus();
251 }
252 }