-qwebirc.ui.LoginBox = function(parentElement, callback, initialNickname, initialChannels, networkName) {
- var outerbox = new Element("table");
- outerbox.addClass("qwebirc-centrebox");
- parentElement.appendChild(outerbox);
- var tbody = new Element("tbody");
- outerbox.appendChild(tbody);
- var tr = new Element("tr");
- tbody.appendChild(tr);
- var td = new Element("td");
- tr.appendChild(td);
-
- var box = new Element("table");
- box.addClass("qwebirc-loginbox");
- td.appendChild(box);
-
- var tbody = new Element("tbody");
- box.appendChild(tbody);
-
- var tr = new Element("tr");
- tbody.appendChild(tr);
- tr.addClass("tr1");
-
- var td = new Element("td");
- tr.appendChild(td);
- td.set("html", "<h1>Connect to " + networkName + " IRC</h1>");
-
- var tr = new Element("tr");
- tbody.appendChild(tr);
- tr.addClass("tr2");
-
- var td = new Element("td");
- tr.appendChild(td);
-
- var form = new Element("form");
- td.appendChild(form);
+ 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;
+ }
+
+ if(qwebirc.auth.loggedin()) {
+ exec("[name=authname]", util.setText(qwebirc.auth.loggedin()));
+ exec("[name=connectbutton]", util.makeVisible);
+ exec("[name=loginstatus]", util.makeVisible);
+ } else {
+ if(qwebirc.ui.isAuthRequired()) {
+ exec("[name=loginconnectbutton]", util.makeVisible);
+ if(focus == "connect")
+ focus = "loginconnect";
+ } else {
+ exec("[name=connectbutton]", util.makeVisible);
+ exec("[name=loginbutton]", util.makeVisible);
+ }
+ }
+
+ if(window == window.top) /* don't focus when we're iframe'd */
+ exec("[name=" + focus + "]", util.focus);
+ exec("[name=connect]", util.attachClick(this.__connect.bind(this)));
+ exec("[name=loginconnect]", util.attachClick(this.__loginConnect.bind(this)));
+
+ exec("[name=login]", util.attachClick(this.__login.bind(this)));
+
+ if(qwebirc.ui.isHideAuth())
+ exec("[name=login]", util.setVisible(false));
+ }.bind(this)});
+ r.get();
+ },
+ util: {
+ makeVisible: function(x) { x.setStyle("display", ""); },
+ setVisible: function(y) { return function(x) { x.setStyle("display", y ? "" : "none"); }; },
+ 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;
+
+ this.__cancelLogin();
+ this.fireEvent("close");
+ this.options.callback(data);
+ },
+ __cancelLogin: function(noUIModifications) {
+ if(this.__cancelLoginCallback)
+ this.__cancelLoginCallback(noUIModifications);
+ },
+ __loginConnect: function(e) {
+ new Event(e).stop();
+ if(this.validate() === false)
+ return;
+
+ this.__performLogin(function() {
+ var data = this.validate();
+ if(data === false) {
+ /* we're logged in -- show the normal join button */
+ this.util.exec("[name=connectbutton]", this.util.setVisible(true));
+ return;
+ }
+
+ this.fireEvent("close");
+ this.options.callback(data);
+ }.bind(this), "loginconnectbutton");
+ },
+ __login: function(e) {
+ new Event(e).stop();
+
+ this.__cancelLogin(true);
+
+ this.__performLogin(function() {
+ var focus = "connect";
+ if(!this.options.autoConnect) {
+ var nick = this.rootElement.getElement("input[name=nickname]").value, chan = this.rootElement.getElement("input[name=channels]").value;
+ if(!nick) {
+ focus = "nickname";
+ } else if(!chan) {
+ focus = "channels";
+ }
+ }
+ this.util.exec("[name=" + focus + "]", this.util.focus);
+ }.bind(this), "login");
+ },
+ __performLogin: function(callback, calleename) {
+ Cookie.write("jslogin", "1");
+
+ var handle = window.open("/auth", this.__windowName, "status=0,toolbar=0,location=1,menubar=0,directories=0,resizable=0,scrollbars=1,height=280,width=550");
+
+ if(handle === null || handle === undefined) {
+ Cookie.dispose("jslogin");
+// Cookie.write("redirect", document.location);
+// window.location = "auth?";
+ return;
+ }