]>
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 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", "Send privmsgs to dedicated messages window", false],
19 [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
20 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames", true]
23 qwebirc
.config
.DefaultOptions
= null;
25 qwebirc
.config
.Input
= new Class({
26 initialize: function(parent
, option
, position
, parentObject
) {
28 this.value
= option
.value
;
29 this.position
= position
;
30 this.parentElement
= parent
;
31 this.parentObject
= parentObject
;
35 createInput: function(type
, parent
, name
, selected
) {
37 parent
= this.parentElement
;
39 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
41 FE: function(element
, parent
) {
42 var n
= new Element(element
);
44 parent
= this.parentElement
;
46 parent
.appendChild(n
);
50 this.mainElement
.focus();
53 this.event("render", this.mainElement
);
55 get: function(value
) {
56 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
59 event: function(name
, x
) {
60 if(!$defined(this.option
.extras
))
62 var t
= this.option
.extras
[name
];
70 qwebirc
.config
.TextInput
= new Class({
71 Extends: qwebirc
.config
.Input
,
73 var i
= this.createInput("text");
81 return this.parent(this.mainElement
.value
);
85 qwebirc
.config
.CheckInput
= new Class({
86 Extends: qwebirc
.config
.Input
,
88 var i
= this.createInput("checkbox");
91 i
.checked
= this.value
;
96 return this.parent(this.mainElement
.checked
);
100 qwebirc
.config
.RadioInput
= new Class({
101 Extends: qwebirc
.config
.Input
,
103 var value
= this.option
.options
;
107 for(var i
=0;i
<value
.length
;i
++) {
108 var d
= this.FE("div", this.parentObject
);
109 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
110 this.elements
.push(e
);
113 this.mainElement
= e
;
115 d
.appendChild(document
.createTextNode(value
[i
][0]));
120 for(var i
=0;i
<this.elements
.length
;i
++) {
121 var x
= this.elements
[i
];
123 this.option
.position
= i
;
124 return this.parent(this.option
.options
[i
][1]);
130 qwebirc
.config
.Option
= new Class({
131 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
132 this.prefix
= prefix
;
134 this.default_
= default_
;
135 this.optionId
= optionId
;
136 this.extras
= extras
;
138 setSavedValue: function(x
) {
143 qwebirc
.config
.RadioOption
= new Class({
144 Extends: qwebirc
.config
.Option
,
145 Element: qwebirc
.config
.RadioInput
,
146 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
147 this.options
= options
.map(function(x
) {
148 if(typeof(x
) == "string")
152 this.defaultposition
= default_
;
154 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
156 setSavedValue: function(x
) {
157 for(var i
=0;i
<this.options
.length
;i
++) {
158 var y
= this.options
[i
][1];
165 this.position
= this.defaultposition
;
166 this.value
= this.default_
;
170 qwebirc
.config
.TextOption
= new Class({
171 Extends: qwebirc
.config
.Option
,
172 Element: qwebirc
.config
.TextInput
175 qwebirc
.config
.CheckOption
= new Class({
176 Extends: qwebirc
.config
.Option
,
177 Element: qwebirc
.config
.CheckInput
180 qwebirc
.ui
.Options
= new Class({
181 initialize: function(ui
) {
182 if(!$defined(qwebirc
.config
.DefaultOptions
))
183 this.__configureDefaults();
185 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
190 this.optionList
.forEach(function(x
) {
191 x
.setSavedValue(this._get(x
));
192 this.optionHash
[x
.prefix
] = x
;
193 this[x
.prefix
] = x
.value
;
196 __configureDefaults: function() {
197 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
202 var moreextras
= x
[4];
205 var stype
= typeof(default_
);
206 if(stype
== "number") {
207 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
210 if(stype
== "boolean") {
211 type
= qwebirc
.config
.CheckOption
;
213 type
= qwebirc
.config
.TextOption
;
215 return new type(optionId
, prefix
, label
, default_
, moreextras
);
219 setValue: function(option
, value
) {
220 this.optionHash
[option
.prefix
].value
= value
;
221 this[option
.prefix
] = value
;
223 getOptionList: function() {
224 return this.optionList
;
235 qwebirc
.ui
.OptionsPane
= new Class({
236 Implements: [Events
],
237 initialize: function(parentElement
, optionObject
) {
238 this.parentElement
= parentElement
;
239 this.optionObject
= optionObject
;
241 this.createElements();
243 createElements: function() {
244 var FE = function(element
, parent
) {
245 var n
= new Element(element
);
246 parent
.appendChild(n
);
250 var t
= FE("table", this.parentElement
);
251 var tb
= FE("tbody", t
);
255 var optList
= this.optionObject
.getOptionList();
256 for(var i
=0;i
<optList
.length
;i
++) {
259 var row
= FE("tr", tb
);
260 var cella
= FE("td", row
);
261 cella
.set("text", x
.label
+ ":");
263 var cellb
= FE("td", row
);
264 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
268 var r
= FE("tr", tb
);
269 var cella
= FE("td", r
);
270 var cellb
= FE("td", r
);
271 var save
= qwebirc
.util
.createInput("submit", cellb
);
274 save
.addEvent("click", function() {
276 this.fireEvent("close");
279 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
280 cancel
.value
= "Cancel";
281 cancel
.addEvent("click", function() {
282 this.fireEvent("close");
286 this.boxList
.forEach(function(x
) {
289 this.optionObject
.setValue(option
, box
.get());
291 this.optionObject
.flush();
295 qwebirc
.ui
.CookieOptions
= new Class({
296 Extends: qwebirc
.ui
.Options
,
298 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
301 var v
= this.__cookie
.get(x
.optionId
);
308 this.__cookie
.erase();
311 this.getOptionList().forEach(function(x
) {
312 this.__cookie
.set(x
.optionId
, x
.value
);
314 this.__cookie
.save();
318 qwebirc
.ui
.DefaultOptionsClass
= new Class({
319 Extends: qwebirc
.ui
.CookieOptions