]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/panes/options.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],
21 [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true],
22 [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true]
25 qwebirc
.config
.DefaultOptions
= null;
27 qwebirc
.config
.Input
= new Class({
28 initialize: function(parent
, option
, position
, parentObject
) {
30 this.value
= option
.value
;
31 this.position
= position
;
32 this.parentElement
= parent
;
33 this.parentObject
= parentObject
;
37 createInput: function(type
, parent
, name
, selected
) {
39 parent
= this.parentElement
;
41 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
43 FE: function(element
, parent
) {
44 var n
= new Element(element
);
46 parent
= this.parentElement
;
48 parent
.appendChild(n
);
52 this.mainElement
.focus();
55 this.event("render", this.mainElement
);
57 get: function(value
) {
58 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
61 event: function(name
, x
) {
62 if(!$defined(this.option
.extras
))
64 var t
= this.option
.extras
[name
];
72 qwebirc
.config
.TextInput
= new Class({
73 Extends: qwebirc
.config
.Input
,
75 var i
= this.createInput("text");
83 return this.parent(this.mainElement
.value
);
87 qwebirc
.config
.CheckInput
= new Class({
88 Extends: qwebirc
.config
.Input
,
90 var i
= this.createInput("checkbox");
93 i
.checked
= this.value
;
98 return this.parent(this.mainElement
.checked
);
102 qwebirc
.config
.RadioInput
= new Class({
103 Extends: qwebirc
.config
.Input
,
105 var value
= this.option
.options
;
109 for(var i
=0;i
<value
.length
;i
++) {
110 var d
= this.FE("div", this.parentObject
);
111 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
112 this.elements
.push(e
);
115 this.mainElement
= e
;
117 d
.appendChild(document
.createTextNode(value
[i
][0]));
122 for(var i
=0;i
<this.elements
.length
;i
++) {
123 var x
= this.elements
[i
];
125 this.option
.position
= i
;
126 return this.parent(this.option
.options
[i
][1]);
132 qwebirc
.config
.Option
= new Class({
133 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
134 this.prefix
= prefix
;
136 this.default_
= default_
;
137 this.optionId
= optionId
;
138 this.extras
= extras
;
140 setSavedValue: function(x
) {
145 qwebirc
.config
.RadioOption
= new Class({
146 Extends: qwebirc
.config
.Option
,
147 Element: qwebirc
.config
.RadioInput
,
148 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
149 this.options
= options
.map(function(x
) {
150 if(typeof(x
) == "string")
154 this.defaultposition
= default_
;
156 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
158 setSavedValue: function(x
) {
159 for(var i
=0;i
<this.options
.length
;i
++) {
160 var y
= this.options
[i
][1];
167 this.position
= this.defaultposition
;
168 this.value
= this.default_
;
172 qwebirc
.config
.TextOption
= new Class({
173 Extends: qwebirc
.config
.Option
,
174 Element: qwebirc
.config
.TextInput
177 qwebirc
.config
.CheckOption
= new Class({
178 Extends: qwebirc
.config
.Option
,
179 Element: qwebirc
.config
.CheckInput
182 qwebirc
.ui
.Options
= new Class({
183 initialize: function(ui
) {
184 if(!$defined(qwebirc
.config
.DefaultOptions
))
185 this.__configureDefaults();
187 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
192 this.optionList
.forEach(function(x
) {
193 x
.setSavedValue(this._get(x
));
194 this.optionHash
[x
.prefix
] = x
;
195 this[x
.prefix
] = x
.value
;
198 __configureDefaults: function() {
199 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
204 var moreextras
= x
[4];
207 var stype
= typeof(default_
);
208 if(stype
== "number") {
209 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
212 if(stype
== "boolean") {
213 type
= qwebirc
.config
.CheckOption
;
215 type
= qwebirc
.config
.TextOption
;
217 return new type(optionId
, prefix
, label
, default_
, moreextras
);
221 setValue: function(option
, value
) {
222 this.optionHash
[option
.prefix
].value
= value
;
223 this[option
.prefix
] = value
;
225 getOptionList: function() {
226 return this.optionList
;
237 qwebirc
.ui
.OptionsPane
= new Class({
238 Implements: [Events
],
239 initialize: function(parentElement
, optionObject
) {
240 this.parentElement
= parentElement
;
241 this.optionObject
= optionObject
;
243 this.createElements();
245 createElements: function() {
246 var FE = function(element
, parent
) {
247 var n
= new Element(element
);
248 parent
.appendChild(n
);
252 var t
= FE("table", this.parentElement
);
253 var tb
= FE("tbody", t
);
257 var optList
= this.optionObject
.getOptionList();
258 for(var i
=0;i
<optList
.length
;i
++) {
261 var row
= FE("tr", tb
);
262 var cella
= FE("td", row
);
263 cella
.set("text", x
.label
+ ":");
265 var cellb
= FE("td", row
);
266 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
270 var r
= FE("tr", tb
);
271 var cella
= FE("td", r
);
272 var cellb
= FE("td", r
);
273 var save
= qwebirc
.util
.createInput("submit", cellb
);
276 save
.addEvent("click", function() {
278 this.fireEvent("close");
281 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
282 cancel
.value
= "Cancel";
283 cancel
.addEvent("click", function() {
284 this.fireEvent("close");
288 this.boxList
.forEach(function(x
) {
291 this.optionObject
.setValue(option
, box
.get());
293 this.optionObject
.flush();
297 qwebirc
.ui
.CookieOptions
= new Class({
298 Extends: qwebirc
.ui
.Options
,
300 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
303 var v
= this.__cookie
.get(x
.optionId
);
310 this.__cookie
.erase();
313 this.getOptionList().forEach(function(x
) {
314 this.__cookie
.set(x
.optionId
, x
.value
);
316 this.__cookie
.save();
320 qwebirc
.ui
.DefaultOptionsClass
= new Class({
321 Extends: qwebirc
.ui
.CookieOptions