]> jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/baseui.js
connectwizard -> embedwizard
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
1 var WINDOW_STATUS = 1;
2 var WINDOW_QUERY = 2;
3 var WINDOW_CHANNEL = 3;
4 var WINDOW_CUSTOM = 4;
5 var WINDOW_CONNECT = 5;
6 var CUSTOM_CLIENT = "custom";
7
8 var BaseUI = new Class({
9 Implements: [Events, Options],
10 options: {
11 appTitle: "QuakeNet Web IRC",
12 singleWindow: true
13 },
14 initialize: function(parentElement, windowClass, uiName, options) {
15 this.setOptions(options);
16
17 this.windows = {};
18 this.windows[CUSTOM_CLIENT] = {};
19 this.windowArray = [];
20 this.windowClass = windowClass;
21 this.parentElement = parentElement;
22 this.parentElement.addClass("qwebirc");
23 this.parentElement.addClass("qwebirc-" + uiName);
24 this.firstClient = false;
25 this.commandhistory = new CommandHistory();
26 },
27 newClient: function(client) {
28 this.windows[client] = {}
29 var w = this.newWindow(client, WINDOW_STATUS, "Status");
30 this.selectWindow(w);
31 if(!this.firstClient) {
32 this.firstClient = true;
33 w.addLine("", "qwebirc v" + QWEBIRC_VERSION);
34 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
35 w.addLine("", "http://webchat.quakenet.org/");
36 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
37 }
38 return w;
39 },
40 newWindow: function(client, type, name) {
41 var identifier = name;
42 if(type == WINDOW_STATUS)
43 identifier = "";
44
45 var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier);
46 this.windowArray.push(w);
47
48 return w;
49 },
50 getActiveWindow: function() {
51 return this.active;
52 },
53 __setActiveWindow: function(window) {
54 this.active = window;
55 },
56 selectWindow: function(window) {
57 if(this.active)
58 this.active.deselect();
59 window.select(); /* calls setActiveWindow */
60 document.title = window.name + " - " + this.options.appTitle;
61 },
62 __closed: function(window) {
63 if(window.active) {
64 this.active = undefined;
65 if(this.windowArray.length == 1) {
66 this.windowArray = [];
67 } else {
68 var index = this.windowArray.indexOf(window);
69 if(index == 0) {
70 this.selectWindow(this.windowArray[1]);
71 } else {
72 this.selectWindow(this.windowArray[index - 1]);
73 }
74
75 this.windowArray = this.windowArray.erase(window);
76 }
77 }
78
79 delete this.windows[window.client][window.identifier];
80 },
81 /*
82 this shouldn't be called by overriding classes!
83 they should implement their own!
84 some form of user input MUST be received before an
85 IRC connection is made, else users are going to get
86 tricked into getting themselves glined
87 */
88 loginBox: function(callback, initialNickname, initialChannels, autoConnect, autoNick) {
89 GenericLoginBox(this.parentElement, callback, initialNickname, initialChannels, autoConnect, autoNick);
90 /*if(autoConnect) {
91 var c = initialChannels.split(",");
92 var ctext;
93
94 if(c.length > 1) {
95 var last = c.pop();
96 ctext = c.join(", ") + " and " + last;
97 } else {
98 ctext = c[0];
99 }
100
101 var nicktext;
102 if(autoNick) {
103 nicktext = "";
104 } else {
105 nicktext = " (as '" + initialNickname + "')"
106 }
107 if(confirm("Connect to IRC and join channels " + ctext + nicktext + "?"))
108 callback({"nickname": initialNickname, "autojoin": initialChannels});
109 return;
110 }
111
112 var nick = prompt("Nickname:", initialNickname);
113 if(!nick) {
114 alert("Aborted.");
115 return;
116 }
117
118 var chans = prompt("Channels (seperate by comma):", initialChannels);
119 callback({"nickname": nick, "autojoin": chans});
120 */
121 }
122 });
123
124 var UI = new Class({
125 Extends: BaseUI,
126 initialize: function(parentElement, windowClass, uiName, options) {
127 this.parent(parentElement, windowClass, uiName, options);
128 window.addEvent("keydown", function(x) {
129 if(!x.alt)
130 return;
131
132 if(x.key == "a" || x.key == "A") {
133 new Event(x).stop();
134 for(var i=0;i<this.windowArray.length;i++) {
135 if(this.windowArray[i].hilighted) {
136 this.selectWindow(this.windowArray[i]);
137 break;
138 }
139 }
140 } else if(x.key >= '0' && x.key <= '9') {
141 new Event(x).stop();
142
143 number = x.key - '0';
144 if(number == 0)
145 number = 10
146
147 number = number - 1;
148
149 if(number >= this.windowArray.length)
150 return;
151
152 this.selectWindow(this.windowArray[number]);
153 }
154 }.bind(this));
155 },
156 newCustomWindow: function(name, select, type) {
157 if(!type)
158 type = WINDOW_CUSTOM;
159
160 var w = this.newWindow(CUSTOM_CLIENT, type, name);
161 w.addEvent("close", function(w) {
162 delete this.windows[name];
163 }.bind(this));
164
165 if(select)
166 this.selectWindow(w);
167
168 return w;
169 },
170 embeddedWindow: function() {
171 if(this.embedded) {
172 this.selectWindow(this.embedded)
173 return;
174 }
175
176 this.embedded = this.newCustomWindow("Embedded wizard", true);
177 this.embedded.addEvent("close", function() {
178 this.embedded = null;
179 }.bind(this));
180
181 var ew = new WebmasterGuide({parent: this.embedded.lines});
182 ew.addEvent("close", function() {
183 this.embedded.close();
184 }.bind(this));
185 },
186 urlDispatcher: function(name) {
187 if(name == "embedded")
188 return this.embeddedWindow.bind(this);
189
190 return null;
191 }
192 });