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