]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/optionspane.js
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 (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, "OPEN_QUERIES", "Open new queries automatically", false]
21 qwebirc
.config
.DefaultOptions
= null;
23 qwebirc
.config
.Input
= new Class({
24 initialize: function(parent
, option
, position
, parentObject
) {
26 this.value
= option
.value
;
27 this.position
= position
;
28 this.parentElement
= parent
;
29 this.parentObject
= parentObject
;
33 FE: function(element
, parent
) {
34 var n
= new Element(element
);
36 parent
= this.parentElement
;
38 parent
.appendChild(n
);
42 this.mainElement
.focus();
45 this.event("render", this.mainElement
);
47 get: function(value
) {
48 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
51 event: function(name
, x
) {
52 if(!$defined(this.option
.extras
))
54 var t
= this.option
.extras
[name
];
62 qwebirc
.config
.TextInput
= new Class({
63 Extends: qwebirc
.config
.Input
,
65 var i
= this.FE("input");
74 return this.parent(this.mainElement
.value
);
78 qwebirc
.config
.CheckInput
= new Class({
79 Extends: qwebirc
.config
.Input
,
81 var i
= this.FE("input");
85 i
.checked
= this.value
;
90 return this.parent(this.mainElement
.checked
);
94 qwebirc
.config
.RadioInput
= new Class({
95 Extends: qwebirc
.config
.Input
,
97 var value
= this.option
.options
;
101 for(var i
=0;i
<value
.length
;i
++) {
102 var d
= this.FE("div", this.parentObject
);
103 var e
= this.FE("input", d
);
104 this.elements
.push(e
);
107 e
.name
= "options_radio" + this.position
;
108 if(i
== this.option
.position
)
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
= FE("input", r
);
271 save
.type
= "button";
274 save
.addEvent("click", function() {
276 this.fireEvent("close");
279 var cancel
= FE("input", r
);
280 cancel
.type
= "button";
281 cancel
.value
= "Cancel";
282 cancel
.addEvent("click", function() {
283 this.fireEvent("close");
287 this.boxList
.forEach(function(x
) {
290 this.optionObject
.setValue(option
, box
.get());
292 this.optionObject
.flush();
296 qwebirc
.ui
.CookieOptions
= new Class({
297 Extends: qwebirc
.ui
.Options
,
299 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
302 var v
= this.__cookie
.get(x
.optionId
);
309 this.__cookie
.erase();
312 this.getOptionList().forEach(function(x
) {
313 this.__cookie
.set(x
.optionId
, x
.value
);
315 this.__cookie
.save();
319 qwebirc
.ui
.DefaultOptionsClass
= new Class({
320 Extends: qwebirc
.ui
.CookieOptions