]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/baseui.js
Whoops.
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
index 60b1b1269e200101fc117204e9b80de571510940..838c21fd86d013a8bdf10562a06d7e4cd089fcfe 100644 (file)
@@ -1,16 +1,21 @@
 var WINDOW_STATUS = 1;
 var WINDOW_QUERY = 2;
 var WINDOW_CHANNEL = 3;
+var WINDOW_CUSTOM = 4;
+var WINDOW_CONNECT = 5;
+var CUSTOM_CLIENT = "custom";
 
 var BaseUI = new Class({
   Implements: [Events, Options],
   options: {
-    appTitle: "QuakeNet Web IRC"
+    appTitle: "QuakeNet Web IRC",
+    singleWindow: true
   },
   initialize: function(parentElement, windowClass, uiName, options) {
     this.setOptions(options);
     
     this.windows = {};
+    this.windows[CUSTOM_CLIENT] = {};
     this.windowArray = [];
     this.windowClass = windowClass;
     this.parentElement = parentElement;
@@ -61,7 +66,9 @@ var BaseUI = new Class({
         this.windowArray = [];
       } else {
         var index = this.windowArray.indexOf(window);
-        if(index == 0) {
+        if(index == -1) {
+          return;
+        } else if(index == 0) {
           this.selectWindow(this.windowArray[1]);
         } else {
           this.selectWindow(this.windowArray[index - 1]);
@@ -73,13 +80,36 @@ var BaseUI = new Class({
     
     delete this.windows[window.client][window.identifier];
   },
-  loginBox: function(callback, initialNickname, initialChannels) {
     /*
       this shouldn't be called by overriding classes!
+      they should implement their own!
       some form of user input MUST be received before an
       IRC connection is made, else users are going to get
       tricked into getting themselves glined
     */
+  loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
+    GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
+    /*if(autoConnect) {
+      var c = initialChannels.split(",");
+      var ctext;
+      
+      if(c.length > 1) {
+        var last = c.pop();
+        ctext = c.join(", ") + " and " + last;
+      } else {
+        ctext = c[0];
+      }
+      
+      var nicktext;
+      if(autoNick) {
+        nicktext = "";
+      } else {
+        nicktext = " (as '" + initialNickname + "')"
+      }
+      if(confirm("Connect to IRC and join channels " + ctext + nicktext + "?"))
+        callback({"nickname": initialNickname, "autojoin": initialChannels});
+      return;
+    }
 
     var nick = prompt("Nickname:", initialNickname);
     if(!nick) {
@@ -89,6 +119,7 @@ var BaseUI = new Class({
 
     var chans = prompt("Channels (seperate by comma):", initialChannels);
     callback({"nickname": nick, "autojoin": chans});
+    */
   }
 });
 
@@ -101,6 +132,7 @@ var UI = new Class({
         return;
         
       if(x.key == "a" || x.key == "A") {
+        new Event(x).stop();
         for(var i=0;i<this.windowArray.length;i++) {
           if(this.windowArray[i].hilighted) {
             this.selectWindow(this.windowArray[i]);
@@ -108,6 +140,8 @@ var UI = new Class({
           }
         }
       } else if(x.key >= '0' && x.key <= '9') {
+        new Event(x).stop();
+        
         number = x.key - '0';
         if(number == 0)
           number = 10
@@ -120,5 +154,55 @@ var UI = new Class({
         this.selectWindow(this.windowArray[number]);
       }
     }.bind(this));
+  },
+  newCustomWindow: function(name, select, type) {
+    if(!type)
+      type = WINDOW_CUSTOM;
+      
+    var w = this.newWindow(CUSTOM_CLIENT, type, name);
+    w.addEvent("close", function(w) {
+      delete this.windows[name];
+    }.bind(this));
+    
+    if(select)
+      this.selectWindow(w);  
+      
+    return w;
+  },
+  embeddedWindow: function() {
+    if(this.embedded) {
+      this.selectWindow(this.embedded)
+      return;
+    }
+    
+    this.embedded = this.newCustomWindow("Embedded wizard", true);
+    this.embedded.addEvent("close", function() {
+      this.embedded = null;
+    }.bind(this));
+        
+    var ew = new WebmasterGuide({parent: this.embedded.lines});
+    ew.addEvent("close", function() {
+      this.embedded.close();
+    }.bind(this));
+  },
+  urlDispatcher: function(name) {
+    if(name == "embedded")
+      return this.embeddedWindow.bind(this);
+
+    return null;
+  }
+});
+
+var NewLoginUI = new Class({
+  Extends: UI,
+  loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) {
+    this.postInitialize();
+    var w = this.newCustomWindow("Connect", true, WINDOW_CONNECT);
+    var callback = function(args) {
+      w.close();
+      callbackfn(args);
+    };
+    
+    GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick);
   }
 });