]>
Commit | Line | Data |
---|---|---|
2cad083e | 1 | qwebirc.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 |
9 | qwebirc.ui.AuthLogin = function(e) { |
10 | var cookie = Cookie.write("redirect", document.location); | |
11 | document.location = "./auth/"; | |
12 | new Event(e).stop(); | |
13 | } | |
14 | ||
2cad083e | 15 | qwebirc.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 CP |
63 | text.appendChild(new Element("br")); |
64 | if(!qwebirc.auth.loggedin()) | |
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); |
70638ce4 | 76 | yes.focus(); |
f065bc69 | 77 | yes.addEvent("click", function(e) { |
5fc104ff | 78 | parentElement.removeChild(outerbox); |
66de775f CP |
79 | callback({"nickname": initialNickname, "autojoin": initialChannels}); |
80 | }); | |
f065bc69 | 81 | |
4fb3b38c | 82 | if(!qwebirc.auth.loggedin()) { |
f065bc69 CP |
83 | var auth = new Element("input", {"type": "submit", "value": "Log in"}); |
84 | td.appendChild(auth); | |
fb661c98 | 85 | auth.addEvent("click", qwebirc.ui.AuthLogin); |
f065bc69 | 86 | } |
66de775f CP |
87 | } |
88 | ||
2cad083e | 89 | qwebirc.ui.LoginBox = function(parentElement, callback, initialNickname, initialChannels, networkName) { |
d3ab254a CP |
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 | ||
90b89aee | 100 | var box = new Element("table"); |
e1a91a8a | 101 | box.addClass("qwebirc-loginbox"); |
d3ab254a | 102 | td.appendChild(box); |
90b89aee | 103 | |
95ce57b3 CP |
104 | var tbody = new Element("tbody"); |
105 | box.appendChild(tbody); | |
106 | ||
90b89aee | 107 | var tr = new Element("tr"); |
95ce57b3 | 108 | tbody.appendChild(tr); |
90b89aee | 109 | tr.addClass("tr1"); |
66de775f | 110 | |
90b89aee CP |
111 | var td = new Element("td"); |
112 | tr.appendChild(td); | |
2cad083e | 113 | td.set("html", "<h1>Connect to " + networkName + " IRC</h1>"); |
95ce57b3 | 114 | |
90b89aee | 115 | var tr = new Element("tr"); |
95ce57b3 | 116 | tbody.appendChild(tr); |
90b89aee CP |
117 | tr.addClass("tr2"); |
118 | ||
90b89aee CP |
119 | var td = new Element("td"); |
120 | tr.appendChild(td); | |
95ce57b3 | 121 | |
66de775f | 122 | var form = new Element("form"); |
90b89aee | 123 | td.appendChild(form); |
66de775f CP |
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) { | |
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 | d2.appendChild(e2); | |
fb661c98 | 143 | return d2; |
66de775f CP |
144 | } |
145 | ||
146 | var nick = new Element("input"); | |
147 | createRow("Nickname:", nick); | |
148 | var chan = new Element("input"); | |
90b89aee | 149 | createRow("Channels:", chan); |
66de775f CP |
150 | |
151 | var connbutton = new Element("input", {"type": "submit"}); | |
152 | connbutton.set("value", "Connect"); | |
fb661c98 CP |
153 | var r = createRow(undefined, connbutton) |
154 | if(!qwebirc.auth.loggedin()) { | |
155 | var auth = new Element("input", {"type": "submit", "value": "Log in"}); | |
156 | r.appendChild(auth); | |
157 | auth.addEvent("click", qwebirc.ui.AuthLogin); | |
158 | } | |
66de775f CP |
159 | |
160 | form.addEvent("submit", function(e) { | |
161 | new Event(e).stop(); | |
162 | var nickname = nick.value; | |
163 | var chans = chan.value; | |
164 | if(chans == "#") /* sorry channel "#" :P */ | |
165 | chans = ""; | |
166 | ||
167 | if(!nickname) { | |
168 | alert("You must supply a nickname."); | |
169 | nick.focus(); | |
170 | return; | |
171 | } | |
172 | ||
5fc104ff | 173 | parentElement.removeChild(outerbox); |
66de775f CP |
174 | |
175 | callback({"nickname": nickname, "autojoin": chans}); | |
176 | }.bind(this)); | |
177 | ||
178 | nick.set("value", initialNickname); | |
179 | chan.set("value", initialChannels); | |
180 | ||
181 | nick.focus(); | |
cad18909 | 182 | } |