]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseui.js
Fix errors in swmui, no argument commands and window closing.
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
1 var WINDOW_STATUS = 1;
2 var WINDOW_QUERY = 2;
3 var WINDOW_CHANNEL = 3;
4
5 var UIWindow = new Class({
6 Implements: [Events],
7 initialize: function(parentObject, client, type, name, identifier) {
8 this.parentObject = parentObject;
9 this.type = type;
10 this.name = name;
11 this.active = false;
12 this.client = client;
13 this.identifier = identifier;
14 },
15 updateNickList: function(nicks) {
16 },
17 updateTopic: function(topic) {
18 },
19 close: function() {
20 this.parentObject.__closed(this);
21 this.fireEvent("close", this);
22 },
23 select: function() {
24 this.active = true;
25 this.parentObject.__setActiveWindow(this);
26 },
27 deselect: function() {
28 this.active = false;
29 },
30 addLine: function(type, line, colour) {
31 },
32 errorMessage: function(message) {
33 this.addLine("", message, "red");
34 }
35 });
36
37 var UI = new Class({
38 initialize: function(parentElement, windowClass, uiName) {
39 this.windows = {};
40 this.windowArray = [];
41 this.windowClass = windowClass;
42 this.parentElement = parentElement;
43 this.parentElement.addClass("qwebirc");
44 this.parentElement.addClass("qwebirc-" + uiName);
45 },
46 newClient: function(client) {
47 this.windows[client] = {}
48 var w = this.newWindow(client, WINDOW_STATUS, "Status");
49 this.selectWindow(w);
50
51 return w;
52 },
53 newWindow: function(client, type, name) {
54 var identifier = name;
55 if(type == WINDOW_STATUS)
56 identifier = "";
57
58 var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);
59 this.windowArray.push(w);
60
61 return w;
62 },
63 getActiveWindow: function() {
64 return this.active;
65 },
66 __setActiveWindow: function(window) {
67 this.active = window;
68 },
69 selectWindow: function(window) {
70 if(this.active)
71 this.active.deselect();
72 window.select(); /* calls setActiveWindow */
73 },
74 __closed: function(window) {
75 if(window.active) {
76 this.active = undefined;
77 if(this.windowArray.length == 1) {
78 this.windowArray = [];
79 } else {
80 var index = this.windowArray.indexOf(window);
81 if(index == 0) {
82 this.selectWindow(this.windowArray[1]);
83 } else {
84 this.selectWindow(this.windowArray[index - 1]);
85 }
86
87 this.windowArray = this.windowArray.erase(window);
88 }
89 }
90
91 delete this.windows[window.client][window.identifier];
92 },
93 loginBox: function(callback) {
94 /*
95 this shouldn't be called by overriding classes!
96 some form of user input MUST be received before an
97 IRC connection is made, else users are going to get
98 tricked into getting themselves glined
99 */
100
101 var nick = prompt("Nickname:");
102 if(!nick) {
103 alert("Aborted.");
104 return;
105 }
106
107 var chans = prompt("Channels (seperate by comma):", "#quakenetX");
108 if(chans) {
109 callback(nick, chans);
110 } else {
111 callback(nick);
112 }
113 }
114 });