]>
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 [7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true],
19 [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
20 [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
21 [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in nicklist", true],
22 [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true],
23 [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true]
26 qwebirc
.config
.DefaultOptions
= null;
28 qwebirc
.config
.Input
= new Class({
29 initialize: function(parent
, option
, position
, parentObject
) {
31 this.value
= option
.value
;
32 this.position
= position
;
33 this.parentElement
= parent
;
34 this.parentObject
= parentObject
;
38 createInput: function(type
, parent
, name
, selected
) {
40 parent
= this.parentElement
;
42 return qwebirc
.util
.createInput(type
, parent
, name
, selected
);
44 FE: function(element
, parent
) {
45 var n
= new Element(element
);
47 parent
= this.parentElement
;
49 parent
.appendChild(n
);
53 this.mainElement
.focus();
56 this.event("render", this.mainElement
);
58 get: function(value
) {
59 this.event("get", [value
, this.parentObject
.optionObject
.ui
]);
62 event: function(name
, x
) {
63 if(!$defined(this.option
.extras
))
65 var t
= this.option
.extras
[name
];
73 qwebirc
.config
.TextInput
= new Class({
74 Extends: qwebirc
.config
.Input
,
76 var i
= this.createInput("text");
84 return this.parent(this.mainElement
.value
);
88 qwebirc
.config
.CheckInput
= new Class({
89 Extends: qwebirc
.config
.Input
,
91 var i
= this.createInput("checkbox");
94 i
.checked
= this.value
;
99 return this.parent(this.mainElement
.checked
);
103 qwebirc
.config
.RadioInput
= new Class({
104 Extends: qwebirc
.config
.Input
,
106 var value
= this.option
.options
;
110 for(var i
=0;i
<value
.length
;i
++) {
111 var d
= this.FE("div", this.parentObject
);
112 var e
= this.createInput("radio", d
, "options_radio" + this.position
, i
== this.option
.position
);
113 this.elements
.push(e
);
116 this.mainElement
= e
;
118 d
.appendChild(document
.createTextNode(value
[i
][0]));
123 for(var i
=0;i
<this.elements
.length
;i
++) {
124 var x
= this.elements
[i
];
126 this.option
.position
= i
;
127 return this.parent(this.option
.options
[i
][1]);
133 qwebirc
.config
.Option
= new Class({
134 initialize: function(optionId
, prefix
, label
, default_
, extras
) {
135 this.prefix
= prefix
;
137 this.default_
= default_
;
138 this.optionId
= optionId
;
139 this.extras
= extras
;
141 setSavedValue: function(x
) {
146 qwebirc
.config
.RadioOption
= new Class({
147 Extends: qwebirc
.config
.Option
,
148 Element: qwebirc
.config
.RadioInput
,
149 initialize: function(optionId
, prefix
, label
, default_
, extras
, options
) {
150 this.options
= options
.map(function(x
) {
151 if(typeof(x
) == "string")
155 this.defaultposition
= default_
;
157 this.parent(optionId
, prefix
, label
, this.options
[default_
][1], extras
);
159 setSavedValue: function(x
) {
160 for(var i
=0;i
<this.options
.length
;i
++) {
161 var y
= this.options
[i
][1];
168 this.position
= this.defaultposition
;
169 this.value
= this.default_
;
173 qwebirc
.config
.TextOption
= new Class({
174 Extends: qwebirc
.config
.Option
,
175 Element: qwebirc
.config
.TextInput
178 qwebirc
.config
.CheckOption
= new Class({
179 Extends: qwebirc
.config
.Option
,
180 Element: qwebirc
.config
.CheckInput
183 qwebirc
.ui
.Options
= new Class({
184 initialize: function(ui
) {
185 if(!$defined(qwebirc
.config
.DefaultOptions
))
186 this.__configureDefaults();
188 this.optionList
= qwebirc
.config
.DefaultOptions
.slice();
193 this.optionList
.forEach(function(x
) {
194 x
.setSavedValue(this._get(x
));
195 this.optionHash
[x
.prefix
] = x
;
196 this[x
.prefix
] = x
.value
;
199 __configureDefaults: function() {
200 qwebirc
.config
.DefaultOptions
= qwebirc
.config
.DEFAULT_OPTIONS
.map(function(x
) {
205 var moreextras
= x
[4];
208 var stype
= typeof(default_
);
209 if(stype
== "number") {
210 return new qwebirc
.config
.RadioOption(optionId
, prefix
, label
, default_
, moreextras
, extra
);
213 if(stype
== "boolean") {
214 type
= qwebirc
.config
.CheckOption
;
216 type
= qwebirc
.config
.TextOption
;
218 return new type(optionId
, prefix
, label
, default_
, moreextras
);
222 setValue: function(option
, value
) {
223 this.optionHash
[option
.prefix
].value
= value
;
224 this[option
.prefix
] = value
;
226 getOptionList: function() {
227 return this.optionList
;
238 qwebirc
.ui
.OptionsPane
= new Class({
239 Implements: [Events
],
240 initialize: function(parentElement
, optionObject
) {
241 this.parentElement
= parentElement
;
242 this.optionObject
= optionObject
;
244 this.createElements();
246 createElements: function() {
247 var FE = function(element
, parent
) {
248 var n
= new Element(element
);
249 parent
.appendChild(n
);
253 var t
= FE("table", this.parentElement
);
254 var tb
= FE("tbody", t
);
258 var optList
= this.optionObject
.getOptionList();
259 for(var i
=0;i
<optList
.length
;i
++) {
262 var row
= FE("tr", tb
);
263 var cella
= FE("td", row
);
264 cella
.set("text", x
.label
+ ":");
266 var cellb
= FE("td", row
);
267 this.boxList
.push([x
, new x
.Element(cellb
, x
, i
, this)]);
271 var r
= FE("tr", tb
);
272 var cella
= FE("td", r
);
273 var cellb
= FE("td", r
);
274 var save
= qwebirc
.util
.createInput("submit", cellb
);
277 save
.addEvent("click", function() {
279 this.fireEvent("close");
282 var cancel
= qwebirc
.util
.createInput("submit", cellb
);
283 cancel
.value
= "Cancel";
284 cancel
.addEvent("click", function() {
285 this.fireEvent("close");
289 this.boxList
.forEach(function(x
) {
292 this.optionObject
.setValue(option
, box
.get());
294 this.optionObject
.flush();
298 qwebirc
.ui
.CookieOptions
= new Class({
299 Extends: qwebirc
.ui
.Options
,
301 this.__cookie
= new Hash
.Cookie("opt1", {duration: 3650, autoSave: false});
304 var v
= this.__cookie
.get(x
.optionId
);
311 this.__cookie
.erase();
314 this.getOptionList().forEach(function(x
) {
315 this.__cookie
.set(x
.optionId
, x
.value
);
317 this.__cookie
.save();
321 qwebirc
.ui
.DefaultOptionsClass
= new Class({
322 Extends: qwebirc
.ui
.CookieOptions