]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/connect.js
Don't steal focus if we're inside an iframe.
[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.focus();
77 yes.addEvent("click", function(e) {
78 parentElement.removeChild(outerbox);
79 callback({"nickname": initialNickname, "autojoin": initialChannels});
80 });
81
82 if(qwebirc.auth.enabled() && qwebirc.auth.quakeNetAuth() && !qwebirc.auth.loggedin()) {
83 var auth = new Element("input", {"type": "submit", "value": "Log in"});
84 td.appendChild(auth);
85 auth.addEvent("click", qwebirc.ui.AuthLogin);
86 }
87
88 if(!window != window.top)
89 yes.focus();
90 }
91
92 qwebirc.ui.LoginBox = function(parentElement, callback, initialNickname, initialChannels, networkName) {
93 var outerbox = new Element("table");
94 outerbox.addClass("qwebirc-centrebox");
95 parentElement.appendChild(outerbox);
96 var tbody = new Element("tbody");
97 outerbox.appendChild(tbody);
98 var tr = new Element("tr");
99 tbody.appendChild(tr);
100 var td = new Element("td");
101 tr.appendChild(td);
102
103 var box = new Element("table");
104 box.addClass("qwebirc-loginbox");
105 td.appendChild(box);
106
107 var tbody = new Element("tbody");
108 box.appendChild(tbody);
109
110 var tr = new Element("tr");
111 tbody.appendChild(tr);
112 tr.addClass("tr1");
113
114 var td = new Element("td");
115 tr.appendChild(td);
116 td.set("html", "<h1>Connect to " + networkName + " IRC</h1>");
117
118 var tr = new Element("tr");
119 tbody.appendChild(tr);
120 tr.addClass("tr2");
121
122 var td = new Element("td");
123 tr.appendChild(td);
124
125 var form = new Element("form");
126 td.appendChild(form);
127
128 var boxtable = new Element("table");
129 form.appendChild(boxtable);
130
131 var tbody = new Element("tbody");
132 boxtable.appendChild(tbody); /* stupid IE */
133
134 function createRow(label, e2, style) {
135 var r = new Element("tr");
136 tbody.appendChild(r);
137
138 var d1 = new Element("td");
139 if(label)
140 d1.set("text", label);
141 r.appendChild(d1);
142
143 var d2 = new Element("td");
144 r.appendChild(d2);
145
146 if($defined(e2))
147 d2.appendChild(e2);
148 if($defined(style)) {
149 r.setStyles(style);
150 return [r, d2];
151 }
152
153 return d2;
154 }
155
156 var nick = new Element("input");
157 createRow("Nickname:", nick);
158
159 var chanStyle = null;
160 if(qwebirc.auth.enabled() && qwebirc.auth.bouncerAuth())
161 chanStyle = {display: "none"};
162
163 var chan = new Element("input");
164 createRow("Channels:", chan, chanStyle);
165
166 if(qwebirc.auth.enabled()) {
167 if(qwebirc.auth.passAuth()) {
168 var authRow = createRow("Auth to services:");
169 var authCheckBox = qwebirc.util.createInput("checkbox", authRow, "connect_auth_to_services", false);
170
171 var usernameBox = new Element("input");
172 var usernameRow = createRow("Username:", usernameBox, {display: "none"})[0];
173
174 var passwordRow = createRow("Password:", null, {display: "none"});
175 var passwordBox = qwebirc.util.createInput("password", passwordRow[1], "connect_auth_password");
176
177 authCheckBox.addEvent("click", function(e) { qwebirc.ui.authShowHide(authCheckBox, authRow, usernameBox, usernameRow, passwordRow[0]) });
178 } else if(qwebirc.auth.bouncerAuth()) {
179 var passwordRow = createRow("Password:");
180 var passwordBox = qwebirc.util.createInput("password", passwordRow, "connect_auth_password");
181 }
182 }
183
184 var connbutton = new Element("input", {"type": "submit"});
185 connbutton.set("value", "Connect");
186 var r = createRow(undefined, connbutton);
187
188 if(qwebirc.auth.enabled() && qwebirc.auth.quakeNetAuth() && !qwebirc.auth.loggedin()) {
189 var auth = new Element("input", {"type": "submit", "value": "Log in"});
190 r.appendChild(auth);
191 auth.addEvent("click", qwebirc.ui.AuthLogin);
192 }
193
194 form.addEvent("submit", function(e) {
195 new Event(e).stop();
196 var nickname = nick.value;
197 var chans = chan.value;
198 if(chans == "#") /* sorry channel "#" :P */
199 chans = "";
200
201 if(!nickname) {
202 alert("You must supply a nickname.");
203 nick.focus();
204 return;
205 }
206
207 var data = {"nickname": nickname, "autojoin": chans};
208 if(qwebirc.auth.enabled()) {
209 if(qwebirc.auth.passAuth() && authCheckBox.checked) {
210 if(!usernameBox.value || !passwordBox.value) {
211 alert("You must supply your username and password in auth mode.");
212 if(!usernameBox.value) {
213 usernameBox.focus();
214 } else {
215 passwordBox.focus();
216 }
217 return;
218 }
219
220 data["serverPassword"] = usernameBox.value + " " + passwordBox.value;
221 } else if(qwebirc.auth.bouncerAuth()) {
222 if(!passwordBox.value) {
223 alert("You must supply a password.");
224 passwordBox.focus();
225 return;
226 }
227
228 data["serverPassword"] = passwordBox.value;
229 }
230 }
231 parentElement.removeChild(outerbox);
232
233 callback(data);
234 }.bind(this));
235
236 nick.set("value", initialNickname);
237 chan.set("value", initialChannels);
238
239 if(!window != window.top)
240 nick.focus();
241 }
242
243 qwebirc.ui.authShowHide = function(checkbox, authRow, usernameBox, usernameRow, passwordRow) {
244 var visible = checkbox.checked;
245 var display = visible?null:"none";
246 usernameRow.setStyle("display", display);
247 passwordRow.setStyle("display", display);
248
249 if(visible) {
250 // authRow.parentNode.setStyle("display", "none");
251 usernameBox.focus();
252 }
253 }