X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/9b63b053148bdd08d7b72085ed45efa12aa0705a..e20e5a6b73d37ddd1a4c6ded2dcc336e3299fecf:/js/ui/baseui.js diff --git a/js/ui/baseui.js b/js/ui/baseui.js index 60b1b12..9f8b970 100644 --- a/js/ui/baseui.js +++ b/js/ui/baseui.js @@ -1,31 +1,36 @@ -var WINDOW_STATUS = 1; -var WINDOW_QUERY = 2; -var WINDOW_CHANNEL = 3; +qwebirc.ui.WINDOW_STATUS = 1; +qwebirc.ui.WINDOW_QUERY = 2; +qwebirc.ui.WINDOW_CHANNEL = 3; +qwebirc.ui.WINDOW_CUSTOM = 4; +qwebirc.ui.WINDOW_CONNECT = 5; +qwebirc.ui.CUSTOM_CLIENT = "custom"; -var BaseUI = new Class({ +qwebirc.ui.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[qwebirc.ui.CUSTOM_CLIENT] = {}; this.windowArray = []; this.windowClass = windowClass; this.parentElement = parentElement; this.parentElement.addClass("qwebirc"); this.parentElement.addClass("qwebirc-" + uiName); this.firstClient = false; - this.commandhistory = new CommandHistory(); + this.commandhistory = new qwebirc.irc.CommandHistory(); }, newClient: function(client) { this.windows[client] = {} - var w = this.newWindow(client, WINDOW_STATUS, "Status"); + var w = this.newWindow(client, qwebirc.ui.WINDOW_STATUS, "Status"); this.selectWindow(w); if(!this.firstClient) { this.firstClient = true; - w.addLine("", "qwebirc v" + QWEBIRC_VERSION); + w.addLine("", "qwebirc v" + qwebirc.VERSION); w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved."); w.addLine("", "http://webchat.quakenet.org/"); w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org"); @@ -34,7 +39,7 @@ var BaseUI = new Class({ }, newWindow: function(client, type, name) { var identifier = name; - if(type == WINDOW_STATUS) + if(type == qwebirc.ui.WINDOW_STATUS) identifier = ""; var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier); @@ -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,27 +80,20 @@ 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 */ - - var nick = prompt("Nickname:", initialNickname); - if(!nick) { - alert("Aborted."); - return; - } - - var chans = prompt("Channels (seperate by comma):", initialChannels); - callback({"nickname": nick, "autojoin": chans}); + loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) { + qwebirc.ui.GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick); } }); -var UI = new Class({ - Extends: BaseUI, +qwebirc.ui.StandardUI = new Class({ + Extends: qwebirc.ui.BaseUI, initialize: function(parentElement, windowClass, uiName, options) { this.parent(parentElement, windowClass, uiName, options); window.addEvent("keydown", function(x) { @@ -101,6 +101,7 @@ var UI = new Class({ return; if(x.key == "a" || x.key == "A") { + new Event(x).stop(); for(var i=0;i= '0' && x.key <= '9') { + new Event(x).stop(); + number = x.key - '0'; if(number == 0) number = 10 @@ -120,5 +123,55 @@ var UI = new Class({ this.selectWindow(this.windowArray[number]); } }.bind(this)); + }, + newCustomWindow: function(name, select, type) { + if(!type) + type = qwebirc.ui.WINDOW_CUSTOM; + + var w = this.newWindow(qwebirc.ui.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("Embedding wizard", true); + this.embedded.addEvent("close", function() { + this.embedded = null; + }.bind(this)); + + var ew = new qwebirc.ui.EmbedWizard({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; + } +}); + +qwebirc.ui.NewLoginUI = new Class({ + Extends: qwebirc.ui.StandardUI, + loginBox: function(callbackfn, initialNickname, initialChannels, autoConnect, autoNick) { + this.postInitialize(); + var w = this.newCustomWindow("Connect", true, qwebirc.ui.WINDOW_CONNECT); + var callback = function(args) { + w.close(); + callbackfn(args); + }; + + qwebirc.ui.GenericLoginBox(w.lines, callback, initialNickname, initialChannels, autoConnect, autoNick); } });