-qwebirc.ui.GenericLoginBox = function(parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick, networkName) {
- if(autoConnect) {
- qwebirc.ui.ConfirmBox(parentElement, callback, initialNickname, initialChannels, autoNick, networkName);
- } else {
- qwebirc.ui.LoginBox(parentElement, callback, initialNickname, initialChannels, networkName);
- }
-}
+qwebirc.ui.ConnectPane = new Class({
+ Implements: [Events],
+ initialize: function(parent, options) {
+ var callback = options.callback, initialNickname = options.initialNickname, initialChannels = options.initialChannels, networkName = options.networkName, autoConnect = options.autoConnect, autoNick = options.autoNick;
+ this.options = options;
+
+ var delayfn = function() { parent.set("html", "<div class=\"loading\">Loading. . .</div>"); };
+ var cb = delayfn.delay(500);
+
+ var r = qwebirc.ui.RequestTransformHTML({url: qwebirc.global.staticBaseURL + "panes/connect.html", update: parent, onSuccess: function() {
+ $clear(cb);
+
+ var box = (autoConnect ? "confirm" : "login");
+ var rootElement = parent.getElement("[name=" + box + "box]");
+ this.rootElement = rootElement;
+
+ this.util.exec = function(n, x) { rootElement.getElements(n).each(x); };
+ var util = this.util;
+ var exec = util.exec;
+ util.makeVisible(rootElement);
+
+ exec("[name=nickname]", util.setText(initialNickname));
+ exec("[name=channels]", util.setText(initialChannels));
+ exec("[name=prettychannels]", function(node) { this.__buildPrettyChannels(node, initialChannels); }.bind(this));
+ exec("[name=networkname]", util.setText(networkName));
+
+ var focus = "connect";
+ if(autoConnect) {
+ if(!autoNick)
+ exec("[name=nickselected]", util.makeVisible);
+
+ this.__validate = this.__validateConfirmData;
+ } else {
+ if(!initialNickname) {
+ focus = "nickname";
+ } else if(initialNickname && !initialChannels) {
+ focus = "channels";
+ }
+
+ this.__validate = this.__validateLoginData;
+ }
+
+ exec("[name=" + focus + "]", util.focus);
+ exec("[name=connect]", util.attachClick(this.__connect.bind(this)));
+ }.bind(this)});
+ r.get();
+ },
+ util: {
+ makeVisible: function(x) { x.setStyle("display", ""); },
+ focus: function(x) { x.focus(); },
+ attachClick: function(fn) { return function(x) { x.addListener("click", fn); } },
+ setText: function(x) { return function(y) {
+ if(typeof y.value === "undefined") {
+ y.set("text", x);
+ } else {
+ y.value = x === null ? "" : x;
+ }
+ } }
+ },
+ validate: function() {
+ return this.__validate();
+ },
+ __connect: function(e) {
+ new Event(e).stop();
+ var data = this.validate();
+ if(data === false)
+ return;