]> jfr.im git - irc/quakenet/qwebirc.git/blame - js/ui/baseui.js
connectwizard -> embedwizard
[irc/quakenet/qwebirc.git] / js / ui / baseui.js
CommitLineData
65152b01
CP
1var WINDOW_STATUS = 1;
2var WINDOW_QUERY = 2;
3var WINDOW_CHANNEL = 3;
8af49135
CP
4var WINDOW_CUSTOM = 4;
5var WINDOW_CONNECT = 5;
6var CUSTOM_CLIENT = "custom";
9e769c12 7
381fddfd 8var BaseUI = new Class({
a59dc700
CP
9 Implements: [Events, Options],
10 options: {
7c633700
CP
11 appTitle: "QuakeNet Web IRC",
12 singleWindow: true
a59dc700
CP
13 },
14 initialize: function(parentElement, windowClass, uiName, options) {
15 this.setOptions(options);
16
9e769c12 17 this.windows = {};
8af49135 18 this.windows[CUSTOM_CLIENT] = {};
9e769c12
CP
19 this.windowArray = [];
20 this.windowClass = windowClass;
21 this.parentElement = parentElement;
22 this.parentElement.addClass("qwebirc");
23 this.parentElement.addClass("qwebirc-" + uiName);
e8db8558 24 this.firstClient = false;
9b63b053 25 this.commandhistory = new CommandHistory();
9e769c12
CP
26 },
27 newClient: function(client) {
28 this.windows[client] = {}
29 var w = this.newWindow(client, WINDOW_STATUS, "Status");
30 this.selectWindow(w);
e8db8558
CP
31 if(!this.firstClient) {
32 this.firstClient = true;
4094890f
CP
33 w.addLine("", "qwebirc v" + QWEBIRC_VERSION);
34 w.addLine("", "Copyright (C) 2008 Chris Porter. All rights reserved.");
e8db8558 35 w.addLine("", "http://webchat.quakenet.org/");
4094890f 36 w.addLine("", "This is BETA quality software, please report bugs to slug@quakenet.org");
e8db8558 37 }
9e769c12
CP
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 */
a59dc700 60 document.title = window.name + " - " + this.options.appTitle;
9e769c12
CP
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];
eb9b087b 80 },
eb9b087b
CP
81 /*
82 this shouldn't be called by overriding classes!
66de775f 83 they should implement their own!
eb9b087b
CP
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 */
66de775f
CP
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 }
eb9b087b 111
d65fe45f 112 var nick = prompt("Nickname:", initialNickname);
eb9b087b
CP
113 if(!nick) {
114 alert("Aborted.");
115 return;
116 }
117
d65fe45f 118 var chans = prompt("Channels (seperate by comma):", initialChannels);
4656ff82 119 callback({"nickname": nick, "autojoin": chans});
66de775f 120 */
9e769c12
CP
121 }
122});
381fddfd
CP
123
124var UI = new Class({
125 Extends: BaseUI,
126 initialize: function(parentElement, windowClass, uiName, options) {
127 this.parent(parentElement, windowClass, uiName, options);
381fddfd
CP
128 window.addEvent("keydown", function(x) {
129 if(!x.alt)
130 return;
131
132 if(x.key == "a" || x.key == "A") {
424608ac 133 new Event(x).stop();
381fddfd
CP
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') {
424608ac
CP
141 new Event(x).stop();
142
381fddfd
CP
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));
841a451d 155 },
8af49135
CP
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;
841a451d 174 }
8af49135
CP
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));
841a451d 185 },
8af49135
CP
186 urlDispatcher: function(name) {
187 if(name == "embedded")
188 return this.embeddedWindow.bind(this);
189
190 return null;
191 }
381fddfd 192});