]>
Commit | Line | Data |
---|---|---|
e89c812f CP |
1 | qwebirc.ui.ConnectPane = new Class({ |
2 | Implements: [Events], | |
3 | initialize: function(parent, options) { | |
4 | var callback = options.callback, initialNickname = options.initialNickname, initialChannels = options.initialChannels, networkName = options.networkName, autoConnect = options.autoConnect, autoNick = options.autoNick; | |
5 | this.options = options; | |
6 | ||
7 | var delayfn = function() { parent.set("html", "<div class=\"loading\">Loading. . .</div>"); }; | |
8 | var cb = delayfn.delay(500); | |
9 | ||
10 | var r = qwebirc.ui.RequestTransformHTML({url: qwebirc.global.staticBaseURL + "panes/connect.html", update: parent, onSuccess: function() { | |
11 | $clear(cb); | |
12 | ||
13 | var box = (autoConnect ? "confirm" : "login"); | |
14 | var rootElement = parent.getElement("[name=" + box + "box]"); | |
15 | this.rootElement = rootElement; | |
16 | ||
17 | this.util.exec = function(n, x) { rootElement.getElements(n).each(x); }; | |
18 | var util = this.util; | |
19 | var exec = util.exec; | |
20 | util.makeVisible(rootElement); | |
21 | ||
22 | exec("[name=nickname]", util.setText(initialNickname)); | |
23 | exec("[name=channels]", util.setText(initialChannels)); | |
24 | exec("[name=prettychannels]", function(node) { this.__buildPrettyChannels(node, initialChannels); }.bind(this)); | |
25 | exec("[name=networkname]", util.setText(networkName)); | |
26 | ||
27 | var focus = "connect"; | |
28 | if(autoConnect) { | |
29 | if(!autoNick) | |
30 | exec("[name=nickselected]", util.makeVisible); | |
31 | ||
32 | this.__validate = this.__validateConfirmData; | |
33 | } else { | |
34 | if(!initialNickname) { | |
35 | focus = "nickname"; | |
36 | } else if(initialNickname && !initialChannels) { | |
37 | focus = "channels"; | |
38 | } | |
39 | ||
40 | this.__validate = this.__validateLoginData; | |
41 | } | |
42 | ||
43 | exec("[name=" + focus + "]", util.focus); | |
44 | exec("[name=connect]", util.attachClick(this.__connect.bind(this))); | |
45 | }.bind(this)}); | |
46 | r.get(); | |
47 | }, | |
48 | util: { | |
49 | makeVisible: function(x) { x.setStyle("display", ""); }, | |
50 | focus: function(x) { x.focus(); }, | |
51 | attachClick: function(fn) { return function(x) { x.addListener("click", fn); } }, | |
52 | setText: function(x) { return function(y) { | |
53 | if(typeof y.value === "undefined") { | |
54 | y.set("text", x); | |
55 | } else { | |
56 | y.value = x === null ? "" : x; | |
57 | } | |
58 | } } | |
59 | }, | |
60 | validate: function() { | |
61 | return this.__validate(); | |
62 | }, | |
63 | __connect: function(e) { | |
64 | new Event(e).stop(); | |
65 | var data = this.validate(); | |
66 | if(data === false) | |
67 | return; | |
66de775f | 68 | |
e89c812f CP |
69 | this.fireEvent("close"); |
70 | this.options.callback(data); | |
71 | }, | |
72 | __validateConfirmData: function() { | |
73 | return {nickname: this.options.initialNickname, autojoin: this.options.initialChannels}; | |
74 | }, | |
75 | __validateLoginData: function() { | |
76 | var nick = this.rootElement.getElement("input[name=nickname]"), chan = this.rootElement.getElement("input[name=channels]"); | |
66de775f | 77 | |
e89c812f CP |
78 | var nickname = nick.value; |
79 | var chans = chan.value; | |
80 | if(chans == "#") /* sorry channel "#" :P */ | |
81 | chans = ""; | |
66de775f | 82 | |
e89c812f CP |
83 | if(!nickname) { |
84 | alert("You must supply a nickname."); | |
85 | nick.focus(); | |
86 | return false; | |
87 | } | |
66de775f | 88 | |
e89c812f CP |
89 | var data = {nickname: nickname, autojoin: chans}; |
90 | return data; | |
91 | }, | |
92 | __buildPrettyChannels: function(node, channels) { | |
93 | var c = channels.split(" ")[0].split(","); | |
94 | node.appendChild(document.createTextNode("channel" + ((c.length>1)?"s":"") + " ")); | |
95 | for(var i=0;i<c.length;i++) { | |
96 | if((c.length > 1) && (i == c.length - 1)) { | |
97 | node.appendChild(document.createTextNode(" and ")); | |
98 | } else if(i > 0) { | |
99 | node.appendChild(document.createTextNode(", ")); | |
100 | } | |
101 | node.appendChild(new Element("b").set("text", c[i])); | |
2f74dea9 | 102 | } |
66de775f | 103 | } |
e89c812f | 104 | }); |
66de775f | 105 | |
e89c812f CP |
106 | qwebirc.ui.LoginBox2 = function(parentElement, callback, initialNickname, initialChannels, networkName) { |
107 | /* | |
6ce70043 CP |
108 | if(qwebirc.auth.enabled()) { |
109 | if(qwebirc.auth.passAuth()) { | |
110 | var authRow = createRow("Auth to services:"); | |
111 | var authCheckBox = qwebirc.util.createInput("checkbox", authRow, "connect_auth_to_services", false); | |
2f74dea9 | 112 | |
6ce70043 CP |
113 | var usernameBox = new Element("input"); |
114 | var usernameRow = createRow("Username:", usernameBox, {display: "none"})[0]; | |
2f74dea9 | 115 | |
6ce70043 CP |
116 | var passwordRow = createRow("Password:", null, {display: "none"}); |
117 | var passwordBox = qwebirc.util.createInput("password", passwordRow[1], "connect_auth_password"); | |
2f74dea9 | 118 | |
6ce70043 CP |
119 | authCheckBox.addEvent("click", function(e) { qwebirc.ui.authShowHide(authCheckBox, authRow, usernameBox, usernameRow, passwordRow[0]) }); |
120 | } else if(qwebirc.auth.bouncerAuth()) { | |
121 | var passwordRow = createRow("Password:"); | |
122 | var passwordBox = qwebirc.util.createInput("password", passwordRow, "connect_auth_password"); | |
123 | } | |
2f74dea9 | 124 | } |
e89c812f CP |
125 | */ |
126 | ||
66de775f CP |
127 | var connbutton = new Element("input", {"type": "submit"}); |
128 | connbutton.set("value", "Connect"); | |
2f74dea9 CP |
129 | var r = createRow(undefined, connbutton); |
130 | ||
66de775f CP |
131 | form.addEvent("submit", function(e) { |
132 | new Event(e).stop(); | |
66de775f | 133 | |
2f74dea9 | 134 | var data = {"nickname": nickname, "autojoin": chans}; |
6f848bbb CP |
135 | if(qwebirc.auth.enabled()) { |
136 | if(qwebirc.auth.passAuth() && authCheckBox.checked) { | |
137 | if(!usernameBox.value || !passwordBox.value) { | |
138 | alert("You must supply your username and password in auth mode."); | |
139 | if(!usernameBox.value) { | |
140 | usernameBox.focus(); | |
141 | } else { | |
142 | passwordBox.focus(); | |
143 | } | |
144 | return; | |
6ce70043 | 145 | } |
6f848bbb CP |
146 | |
147 | data["serverPassword"] = usernameBox.value + " " + passwordBox.value; | |
148 | } else if(qwebirc.auth.bouncerAuth()) { | |
149 | if(!passwordBox.value) { | |
150 | alert("You must supply a password."); | |
151 | passwordBox.focus(); | |
6ce70043 CP |
152 | return; |
153 | } | |
154 | ||
6f848bbb | 155 | data["serverPassword"] = passwordBox.value; |
6ce70043 | 156 | } |
6ce70043 | 157 | } |
6ce70043 CP |
158 | parentElement.removeChild(outerbox); |
159 | ||
2f74dea9 | 160 | callback(data); |
66de775f | 161 | }.bind(this)); |
6ce70043 | 162 | |
66de775f CP |
163 | nick.set("value", initialNickname); |
164 | chan.set("value", initialChannels); | |
165 | ||
b1a46dae | 166 | if(window == window.top) |
9a1c691c | 167 | nick.focus(); |
cad18909 | 168 | } |
2f74dea9 CP |
169 | |
170 | qwebirc.ui.authShowHide = function(checkbox, authRow, usernameBox, usernameRow, passwordRow) { | |
171 | var visible = checkbox.checked; | |
172 | var display = visible?null:"none"; | |
173 | usernameRow.setStyle("display", display); | |
174 | passwordRow.setStyle("display", display); | |
175 | ||
176 | if(visible) { | |
177 | // authRow.parentNode.setStyle("display", "none"); | |
178 | usernameBox.focus(); | |
179 | } | |
180 | } |