]>
Commit | Line | Data |
---|---|---|
1 | qwebirc.ui.GenericLoginBox = function(parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick) { | |
2 | if(autoConnect) { | |
3 | qwebirc.ui.ConfirmBox(parentElement, callback, initialNickname, initialChannels, autoNick); | |
4 | } else { | |
5 | qwebirc.ui.LoginBox(parentElement, callback, initialNickname, initialChannels); | |
6 | } | |
7 | } | |
8 | ||
9 | qwebirc.ui.ConfirmBox = function(parentElement, callback, initialNickname, initialChannels, autoNick) { | |
10 | var box = new Element("table"); | |
11 | box.addClass("confirmbox"); | |
12 | parentElement.appendChild(box); | |
13 | ||
14 | var tbody = new Element("tbody"); | |
15 | box.appendChild(tbody); | |
16 | ||
17 | var tr = new Element("tr"); | |
18 | tbody.appendChild(tr); | |
19 | tr.addClass("tr1"); | |
20 | ||
21 | var text = new Element("td"); | |
22 | tr.appendChild(text); | |
23 | ||
24 | var nick = new Element("b"); | |
25 | nick.set("text", initialNickname); | |
26 | ||
27 | var c = initialChannels.split(" ")[0].split(","); | |
28 | ||
29 | text.appendChild(document.createTextNode("To connect to IRC and join channel" + ((c.length>1)?"s":"") + " ")); | |
30 | ||
31 | for(var i=0;i<c.length;i++) { | |
32 | if((c.length > 1) && (i == c.length - 1)) { | |
33 | text.appendChild(document.createTextNode(" and ")); | |
34 | } else if(i > 0) { | |
35 | text.appendChild(document.createTextNode(", ")); | |
36 | } | |
37 | text.appendChild(new Element("b").set("text", c[i])); | |
38 | ||
39 | } | |
40 | ||
41 | if(!autoNick) { | |
42 | text.appendChild(document.createTextNode(" as ")); | |
43 | text.appendChild(nick); | |
44 | } | |
45 | text.appendChild(document.createTextNode(" click 'Connect'.")); | |
46 | ||
47 | var tr = new Element("tr"); | |
48 | tbody.appendChild(tr); | |
49 | tr.addClass("tr2"); | |
50 | ||
51 | var td = new Element("td"); | |
52 | tr.appendChild(td); | |
53 | ||
54 | var yes = new Element("input", {"type": "submit", "value": "Connect"}); | |
55 | td.appendChild(yes); | |
56 | yes.focus(); | |
57 | yes.addEvent("click", function(e) { | |
58 | parentElement.removeChild(box); | |
59 | callback({"nickname": initialNickname, "autojoin": initialChannels}); | |
60 | }); | |
61 | ||
62 | var user = Cookie.read("user") | |
63 | if(!$defined(user)) { | |
64 | var auth = new Element("input", {"type": "submit", "value": "Log in"}); | |
65 | td.appendChild(auth); | |
66 | auth.addEvent("click", function(e) { | |
67 | var cookie = Cookie.write("redirect", document.location); | |
68 | document.location = "./auth/"; | |
69 | }); | |
70 | } | |
71 | } | |
72 | ||
73 | qwebirc.ui.LoginBox = function(parentElement, callback, initialNickname, initialChannels) { | |
74 | var box = new Element("table"); | |
75 | parentElement.appendChild(box); | |
76 | box.addClass("loginbox"); | |
77 | ||
78 | var tbody = new Element("tbody"); | |
79 | box.appendChild(tbody); | |
80 | ||
81 | var tr = new Element("tr"); | |
82 | tbody.appendChild(tr); | |
83 | tr.addClass("tr1"); | |
84 | ||
85 | var td = new Element("td"); | |
86 | tr.appendChild(td); | |
87 | td.set("html", "<h1>Connect to IRC</h1>"); | |
88 | ||
89 | var tr = new Element("tr"); | |
90 | tbody.appendChild(tr); | |
91 | tr.addClass("tr2"); | |
92 | ||
93 | var td = new Element("td"); | |
94 | tr.appendChild(td); | |
95 | ||
96 | var form = new Element("form"); | |
97 | td.appendChild(form); | |
98 | ||
99 | var boxtable = new Element("table"); | |
100 | form.appendChild(boxtable); | |
101 | ||
102 | var tbody = new Element("tbody"); | |
103 | boxtable.appendChild(tbody); /* stupid IE */ | |
104 | ||
105 | function createRow(label, e2) { | |
106 | var r = new Element("tr"); | |
107 | tbody.appendChild(r); | |
108 | ||
109 | var d1 = new Element("td"); | |
110 | if(label) | |
111 | d1.set("text", label); | |
112 | r.appendChild(d1); | |
113 | ||
114 | var d2 = new Element("td"); | |
115 | r.appendChild(d2); | |
116 | d2.appendChild(e2); | |
117 | return d1; | |
118 | } | |
119 | ||
120 | var nick = new Element("input"); | |
121 | createRow("Nickname:", nick); | |
122 | var chan = new Element("input"); | |
123 | createRow("Channels:", chan); | |
124 | ||
125 | var connbutton = new Element("input", {"type": "submit"}); | |
126 | connbutton.set("value", "Connect"); | |
127 | createRow(undefined, connbutton) | |
128 | ||
129 | form.addEvent("submit", function(e) { | |
130 | new Event(e).stop(); | |
131 | var nickname = nick.value; | |
132 | var chans = chan.value; | |
133 | if(chans == "#") /* sorry channel "#" :P */ | |
134 | chans = ""; | |
135 | ||
136 | if(!nickname) { | |
137 | alert("You must supply a nickname."); | |
138 | nick.focus(); | |
139 | return; | |
140 | } | |
141 | ||
142 | parentElement.removeChild(box); | |
143 | ||
144 | callback({"nickname": nickname, "autojoin": chans}); | |
145 | }.bind(this)); | |
146 | ||
147 | nick.set("value", initialNickname); | |
148 | chan.set("value", initialChannels); | |
149 | ||
150 | nick.focus(); | |
151 | } |