]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/optionspane.js
f85133205bd76ecd8635d2b963c58501541063c9
1 qwebirc
.config
.CHECK_BOX
= 1;
2 qwebirc
.config
.TEXT_BOX
= 2;
3 qwebirc
.config
.RADIO_BUTTONS
= 3;
5 qwebirc
.config
.DEFAULT_OPTIONS
= [
6 [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, {
7 render: function(input
) {
8 if(!$defined(Browser
.Plugins
.Flash
) || Browser
.Plugins
.Flash
.version
< 8) {
10 input
.checked
= false;
13 get: function(value
, ui
) {
14 if(ui
.setBeepOnMention
)
15 ui
.setBeepOnMention(value
);
18 [2, "DEDICATED_MSG_WINDOW", "Use dedicated messages window", false],
19 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames", true]
22 qwebirc
.config
.DefaultOptions
= null;
24 qwebirc
.config
.Input
= new Class({
25 initialize: function(parent
, option
, position
, parentObject
) {
27 this.value
= option
.value
;
28 this.position
= position
;
29 this.parentElement
= parent
;
30 this.parentObject
= parentObject
;
34 createInput: function(type
, parent
, name
, selected
) {
36 parent
= this.parentElement
;
38 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
40 FE: function(element
, parent
) {
41 var n
= new Element(element
);
43 parent
= this.parentElement
;
45 parent
.appendChild(n
);
49 this.mainElement
.focus();
52 this.event("render", this.mainElement
);
54 get: function(value
) {
55 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
58 event: function(name
, x
) {
59 if(!$defined(this.option
.extras
))
61 var t
= this.option
.extras
[name
];
69 qwebirc
.config
.TextInput
= new Class({
70 Extends: qwebirc
.config
.Input
,
72 var i
= this.createInput("text");
80 return this.parent(this.mainElement
.value
);
84 qwebirc
.config
.CheckInput
= new Class({
85 Extends: qwebirc
.config
.Input
,
87 var i
= this.createInput("checkbox");
90 i
.checked
= this.value
;
95 return this.parent(this.mainElement
.checked
);
99 qwebirc
.config
.RadioInput
= new Class({
100 Extends: qwebirc
.config
.Input
,
102 var value
= this.option
.options
;
106 for(var i
=0;i
<value
.length
;i
++) {
107 var d
= this.FE("div", this.parentObject
);
108 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
109 this.elements
.push(e
);
112 this.mainElement
= e
;
114 d
.appendChild(document
.createTextNode(value
[i
][0]));
119 for(var i
=0;i
<this.elements
.length
;i
++) {
120 var x
= this.elements
[i
];
122 this.option
.position
= i
;
123 return this.parent(this.option
.options
[i
][1]);
129 qwebirc
.config
.Option
= new Class({
130 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
131 this.prefix
= prefix
;
133 this.default_
= default_
;
134 this.optionId
= optionId
;
135 this.extras
= extras
;
137 setSavedValue: function(x
) {
142 qwebirc
.config
.RadioOption
= new Class({
143 Extends: qwebirc
.config
.Option
,
144 Element: qwebirc
.config
.RadioInput
,
145 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
146 this.options
= options
.map(function(x
) {
147 if(typeof(x
) == "string")
151 this.defaultposition
= default_
;
153 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
155 setSavedValue: function(x
) {
156 for(var i
=0;i
<this.options
.length
;i
++) {
157 var y
= this.options
[i
][1];
164 this.position
= this.defaultposition
;
165 this.value
= this.default_
;
169 qwebirc
.config
.TextOption
= new Class({
170 Extends: qwebirc
.config
.Option
,
171 Element: qwebirc
.config
.TextInput
174 qwebirc
.config
.CheckOption
= new Class({
175 Extends: qwebirc
.config
.Option
,
176 Element: qwebirc
.config
.CheckInput
179 qwebirc
.ui
.Options
= new Class({
180 initialize: function(ui
) {
181 if(!$defined(qwebirc
.config
.DefaultOptions
))
182 this.__configureDefaults();
184 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
189 this.optionList
.forEach(function(x
) {
190 x
.setSavedValue(this._get(x
));
191 this.optionHash
[x
.prefix
] = x
;
192 this[x
.prefix
] = x
.value
;
195 __configureDefaults: function() {
196 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
201 var moreextras
= x
[4];
204 var stype
= typeof(default_
);
205 if(stype
== "number") {
206 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
209 if(stype
== "boolean") {
210 type
= qwebirc
.config
.CheckOption
;
212 type
= qwebirc
.config
.TextOption
;
214 return new type(optionId
, prefix
, label
, default_
, moreextras
);
218 setValue: function(option
, value
) {
219 this.optionHash
[option
.prefix
].value
= value
;
220 this[option
.prefix
] = value
;
222 getOptionList: function() {
223 return this.optionList
;
234 qwebirc
.ui
.OptionsPane
= new Class({
235 Implements: [Events
],
236 initialize: function(parentElement
, optionObject
) {
237 this.parentElement
= parentElement
;
238 this.optionObject
= optionObject
;
240 this.createElements();
242 createElements: function() {
243 var FE = function(element
, parent
) {
244 var n
= new Element(element
);
245 parent
.appendChild(n
);
249 var t
= FE("table", this.parentElement
);
250 var tb
= FE("tbody", t
);
254 var optList
= this.optionObject
.getOptionList();
255 for(var i
=0;i
<optList
.length
;i
++) {
258 var row
= FE("tr", tb
);
259 var cella
= FE("td", row
);
260 cella
.set("text", x
.label
+ ":");
262 var cellb
= FE("td", row
);
263 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
267 var r
= FE("tr", tb
);
268 var cella
= FE("td", r
);
269 var cellb
= FE("td", r
);
270 var save
= qwebirc
.util
.createInput("submit", cellb
);
273 save
.addEvent("click", function() {
275 this.fireEvent("close");
278 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
279 cancel
.value
= "Cancel";
280 cancel
.addEvent("click", function() {
281 this.fireEvent("close");
285 this.boxList
.forEach(function(x
) {
288 this.optionObject
.setValue(option
, box
.get());
290 this.optionObject
.flush();
294 qwebirc
.ui
.CookieOptions
= new Class({
295 Extends: qwebirc
.ui
.Options
,
297 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
300 var v
= this.__cookie
.get(x
.optionId
);
307 this.__cookie
.erase();
310 this.getOptionList().forEach(function(x
) {
311 this.__cookie
.set(x
.optionId
, x
.value
);
313 this.__cookie
.save();
317 qwebirc
.ui
.DefaultOptionsClass
= new Class({
318 Extends: qwebirc
.ui
.CookieOptions