]>
Commit | Line | Data |
---|---|---|
65152b01 CP |
1 | var WINDOW_STATUS = 1; |
2 | var WINDOW_QUERY = 2; | |
3 | var WINDOW_CHANNEL = 3; | |
9e769c12 | 4 | |
9e769c12 CP |
5 | var UI = new Class({ |
6 | initialize: function(parentElement, windowClass, uiName) { | |
7 | this.windows = {}; | |
8 | this.windowArray = []; | |
9 | this.windowClass = windowClass; | |
10 | this.parentElement = parentElement; | |
11 | this.parentElement.addClass("qwebirc"); | |
12 | this.parentElement.addClass("qwebirc-" + uiName); | |
e8db8558 | 13 | this.firstClient = false; |
9e769c12 CP |
14 | }, |
15 | newClient: function(client) { | |
16 | this.windows[client] = {} | |
17 | var w = this.newWindow(client, WINDOW_STATUS, "Status"); | |
18 | this.selectWindow(w); | |
e8db8558 CP |
19 | if(!this.firstClient) { |
20 | this.firstClient = true; | |
4094890f CP |
21 | w.addLine("", "qwebirc v" + QWEBIRC_VERSION); |
22 | w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved."); | |
e8db8558 | 23 | w.addLine("", "http://webchat.quakenet.org/"); |
4094890f | 24 | w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org"); |
e8db8558 | 25 | } |
9e769c12 CP |
26 | return w; |
27 | }, | |
28 | newWindow: function(client, type, name) { | |
29 | var identifier = name; | |
30 | if(type == WINDOW_STATUS) | |
31 | identifier = ""; | |
32 | ||
33 | var w = this.windows[client][identifier] = new this.windowClass(this, client, type, name, identifier); | |
34 | this.windowArray.push(w); | |
35 | ||
36 | return w; | |
37 | }, | |
38 | getActiveWindow: function() { | |
39 | return this.active; | |
40 | }, | |
41 | __setActiveWindow: function(window) { | |
42 | this.active = window; | |
43 | }, | |
44 | selectWindow: function(window) { | |
45 | if(this.active) | |
46 | this.active.deselect(); | |
47 | window.select(); /* calls setActiveWindow */ | |
48 | }, | |
49 | __closed: function(window) { | |
50 | if(window.active) { | |
51 | this.active = undefined; | |
52 | if(this.windowArray.length == 1) { | |
53 | this.windowArray = []; | |
54 | } else { | |
55 | var index = this.windowArray.indexOf(window); | |
56 | if(index == 0) { | |
57 | this.selectWindow(this.windowArray[1]); | |
58 | } else { | |
59 | this.selectWindow(this.windowArray[index - 1]); | |
60 | } | |
61 | ||
62 | this.windowArray = this.windowArray.erase(window); | |
63 | } | |
64 | } | |
65 | ||
66 | delete this.windows[window.client][window.identifier]; | |
eb9b087b | 67 | }, |
d65fe45f | 68 | loginBox: function(callback, initialNickname, initialChannels) { |
eb9b087b CP |
69 | /* |
70 | this shouldn't be called by overriding classes! | |
71 | some form of user input MUST be received before an | |
72 | IRC connection is made, else users are going to get | |
73 | tricked into getting themselves glined | |
74 | */ | |
75 | ||
d65fe45f | 76 | var nick = prompt("Nickname:", initialNickname); |
eb9b087b CP |
77 | if(!nick) { |
78 | alert("Aborted."); | |
79 | return; | |
80 | } | |
81 | ||
d65fe45f | 82 | var chans = prompt("Channels (seperate by comma):", initialChannels); |
4656ff82 | 83 | callback({"nickname": nick, "autojoin": chans}); |
9e769c12 CP |
84 | } |
85 | }); |