]>
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", true],
7 [2, "OPEN_QUERIES", "Open new queries automatically", false]
10 qwebirc
.config
.DefaultOptions
= null;
12 qwebirc
.config
.Input
= new Class({
13 initialize: function(parent
, option
, position
) {
15 this.value
= option
.value
;
16 this.position
= position
;
17 this.parentObject
= parent
;
21 FE: function(element
, parent
) {
22 var n
= new Element(element
);
24 parent
= this.parentObject
;
26 parent
.appendChild(n
);
30 this.mainElement
.focus();
34 qwebirc
.config
.TextInput
= new Class({
35 Extends: qwebirc
.config
.Input
,
37 var i
= this.FE("input");
44 return this.mainElement
.value
;
48 qwebirc
.config
.CheckInput
= new Class({
49 Extends: qwebirc
.config
.Input
,
51 var i
= this.FE("input");
55 i
.checked
= this.value
;
58 return this.mainElement
.checked
;
62 qwebirc
.config
.RadioInput
= new Class({
63 Extends: qwebirc
.config
.Input
,
65 var value
= this.option
.options
;
69 for(var i
=0;i
<value
.length
;i
++) {
70 var d
= this.FE("div", this.parentObject
);
71 var e
= this.FE("input", d
);
72 this.elements
.push(e
);
75 e
.name
= "options_radio" + this.position
;
76 if(i
== this.option
.position
)
82 d
.appendChild(document
.createTextNode(value
[i
][0]));
86 for(var i
=0;i
<this.elements
.length
;i
++) {
87 var x
= this.elements
[i
];
89 this.option
.position
= i
;
90 return this.option
.options
[i
][1];
96 qwebirc
.config
.Option
= new Class({
97 initialize: function(optionId
, prefix
, label
, default_
) {
100 this.default_
= default_
;
101 this.optionId
= optionId
;
103 setSavedValue: function(x
) {
108 qwebirc
.config
.RadioOption
= new Class({
109 Extends: qwebirc
.config
.Option
,
110 Element: qwebirc
.config
.RadioInput
,
111 initialize: function(optionId
, prefix
, label
, default_
, options
) {
112 this.options
= options
.map(function(x
) {
113 if(typeof(x
) == "string")
117 this.defaultposition
= default_
;
119 this.parent(optionId
, prefix
, label
, this.options
[default_
][1]);
121 setSavedValue: function(x
) {
122 for(var i
=0;i
<this.options
.length
;i
++) {
123 var y
= this.options
[i
][1];
130 this.position
= this.defaultposition
;
131 this.value
= this.default_
;
135 qwebirc
.config
.TextOption
= new Class({
136 Extends: qwebirc
.config
.Option
,
137 Element: qwebirc
.config
.TextInput
140 qwebirc
.config
.CheckOption
= new Class({
141 Extends: qwebirc
.config
.Option
,
142 Element: qwebirc
.config
.CheckInput
145 qwebirc
.ui
.Options
= new Class({
146 initialize: function() {
147 if(!$defined(qwebirc
.config
.DefaultOptions
))
148 this.__configureDefaults();
150 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
154 this.optionList
.forEach(function(x
) {
155 x
.setSavedValue(this._get(x
));
156 this.optionHash
[x
.prefix
] = x
;
157 this[x
.prefix
] = x
.value
;
160 __configureDefaults: function() {
161 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
168 var stype
= typeof(default_
);
169 if(stype
== "number") {
170 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, extra
);
173 if(stype
== "boolean") {
174 type
= qwebirc
.config
.CheckOption
;
176 type
= qwebirc
.config
.TextOption
;
178 return new type(optionId
, prefix
, label
, default_
);
182 setValue: function(option
, value
) {
183 this.optionHash
[option
.prefix
].value
= value
;
184 this[option
.prefix
] = value
;
186 getOptionList: function() {
187 return this.optionList
;
198 qwebirc
.ui
.OptionsPane
= new Class({
199 Implements: [Events
],
200 initialize: function(parentElement
, optionObject
) {
201 this.parentElement
= parentElement
;
202 this.optionObject
= optionObject
;
204 this.createElements();
206 createElements: function() {
207 var FE = function(element
, parent
) {
208 var n
= new Element(element
);
209 parent
.appendChild(n
);
213 var t
= FE("table", this.parentElement
);
214 var tb
= FE("tbody", t
);
218 var optList
= this.optionObject
.getOptionList();
219 for(var i
=0;i
<optList
.length
;i
++) {
222 var row
= FE("tr", tb
);
223 var cella
= FE("td", row
);
224 cella
.set("text", x
.label
+ ":");
226 var cellb
= FE("td", row
);
228 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
)]);
231 var r
= FE("tr", tb
);
232 var cella
= FE("td", r
);
233 var cellb
= FE("td", r
);
234 var save
= FE("input", r
);
235 save
.type
= "button";
238 save
.addEvent("click", function() {
240 this.fireEvent("close");
243 var cancel
= FE("input", r
);
244 cancel
.type
= "button";
245 cancel
.value
= "Cancel";
246 cancel
.addEvent("click", function() {
247 this.fireEvent("close");
251 this.boxList
.forEach(function(x
) {
254 this.optionObject
.setValue(option
, box
.get());
256 this.optionObject
.flush();
260 qwebirc
.ui
.CookieOptions
= new Class({
261 Extends: qwebirc
.ui
.Options
,
263 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
266 var v
= this.__cookie
.get(x
.optionId
);
273 this.__cookie
.erase();
276 this.getOptionList().forEach(function(x
) {
277 this.__cookie
.set(x
.optionId
, x
.value
);
279 this.__cookie
.save();
283 qwebirc
.ui
.DefaultOptionsClass
= new Class({
284 Extends: qwebirc
.ui
.CookieOptions