]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/ui/panes/options.js
use home-made string hashset/map instead of js default
[irc/quakenet/qwebirc.git] / js / ui / panes / options.js
index 402213ab0763ed1f02f2b3d025f3d28360cb7c09..879dc2b79d81d8a75830d80259b6dd927ee73312 100644 (file)
@@ -20,7 +20,7 @@ qwebirc.config.DEFAULT_OPTIONS = [
         return [false, false]; /* [disabled, default_value] */
       return [true];
     },
-    get: function(value, ui) {
+    applyChanges: function(value, ui) {
       if(ui.setBeepOnMention)
         ui.setBeepOnMention(value);
     }
@@ -45,10 +45,13 @@ qwebirc.config.DEFAULT_OPTIONS = [
   [11, "STYLE_HUE", "Adjust user interface hue", function() {
     return {class_: qwebirc.config.HueOption, default_: 210};
   }, {
-    get: function(value, ui) {
-      ui.setModifiableStylesheetValues(value, 0, 0);
+    applyChanges: function(value, ui) {
+      ui.setModifiableStylesheetValues({hue: value});
     }
-  }]
+  }],
+  [12, "QUERY_ON_NICK_CLICK", "Query on nickname click in channel", false],
+  [13, "SHOW_NICKLIST", "Show nickname list in channels", true],
+  [14, "SHOW_TIMESTAMPS", "Show timestamps", true] /* we rely on the hue update */
 ];
 
 qwebirc.config.DefaultOptions = null;
@@ -64,11 +67,11 @@ qwebirc.config.Input = new Class({
     
     this.render();
   },
-  createInput: function(type, parent, name, selected) {
+  createInput: function(type, parent, name, selected, id) {
     if(!$defined(parent))
       parent = this.parentElement;
 
-    return qwebirc.util.createInput(type, parent, name, selected);
+    return qwebirc.util.createInput(type, parent, name, selected, this.option.id);
   },
   FE: function(element, parent) {
     var n = new Element(element);
@@ -84,9 +87,8 @@ qwebirc.config.Input = new Class({
   render: function() {
     this.event("render", this.mainElement);
   },
-  get: function(value) {
-    this.event("get", [value, this.parentObject.optionObject.ui]);
-    return value;
+  applyChanges: function() {
+    this.event("applyChanges", [this.get(), this.parentObject.optionObject.ui]);
   },
   event: function(name, x) {
     if(!$defined(this.option.extras))
@@ -113,7 +115,7 @@ qwebirc.config.TextInput = new Class({
     this.parent();
   },
   get: function() {
-    return this.parent(this.mainElement.value);
+    return this.mainElement.value;
   }
 });
 
@@ -140,7 +142,7 @@ qwebirc.config.HueInput = new Class({
     
     slider.addEvent("change", function(step) {
       this.value = step;
-      this.get();
+      this.applyChanges();
     }.bind(this));
     this.mainElement = i;
     
@@ -150,18 +152,18 @@ qwebirc.config.HueInput = new Class({
     this.parent();
   },
   get: function() {
-    return this.parent(this.value);
+    return this.value;
   },
   cancel: function() {
     this.value = this.startValue;
-    this.get();
+    this.applyChanges();
   }
 });
 
 qwebirc.config.CheckInput = new Class({
   Extends: qwebirc.config.Input,
   render: function() {
-    var i = this.createInput("checkbox");
+    var i = this.createInput("checkbox", null, null, null, this.id);
     this.mainElement = i;
     
     i.checked = this.value;
@@ -170,7 +172,7 @@ qwebirc.config.CheckInput = new Class({
     this.parent();
   },
   get: function() {
-    return this.parent(this.mainElement.checked);
+    return this.mainElement.checked;
   }
 });
 
@@ -199,7 +201,7 @@ qwebirc.config.RadioInput = new Class({
       var x = this.elements[i];
       if(x.checked) {
         this.option.position = i;
-        return this.parent(this.option.options[i][1]);
+        return this.option.options[i][1];
       }
     }
   }
@@ -362,7 +364,11 @@ qwebirc.ui.OptionsPane = new Class({
       
       var row = FE("tr", tb);
       var cella = FE("td", row);
-      cella.set("text", x.label + ":");
+      
+      x.id = qwebirc.util.generateID();
+      var label = new Element("label", {"for": x.id});
+      cella.appendChild(label);
+      label.set("text", x.label + ":");
 
       var cellb = FE("td", row);
       this.boxList.push([x, new x.Element(cellb, x, i, this)]);
@@ -393,6 +399,9 @@ qwebirc.ui.OptionsPane = new Class({
       var box = x[1];
       this.optionObject.setValue(option, box.get());
     }.bind(this));
+    this.boxList.forEach(function(x) {
+      x[1].applyChanges();
+    }.bind(this));
     this.optionObject.flush();
   },
   cancel: function() {
@@ -428,14 +437,18 @@ qwebirc.ui.CookieOptions = new Class({
 qwebirc.ui.SuppliedArgOptions = new Class({
   Extends: qwebirc.ui.CookieOptions,
   initialize: function(ui, arg) {
-    var p = {};
+    var p = new QHash();
     
     if($defined(arg) && arg != "" && arg.length > 2) {
       var checksum = arg.substr(arg.length - 2, 2);
       var decoded = qwebirc.util.b64Decode(arg.substr(0, arg.length - 2));
       
-      if(decoded && (new qwebirc.util.crypto.MD5().digest(decoded).slice(0, 2) == checksum))
-        p = qwebirc.util.parseURI("?" + decoded);
+      if(decoded && (new qwebirc.util.crypto.MD5().digest(decoded).slice(0, 2) == checksum)) {
+        var p2 = qwebirc.util.parseURI("?" + decoded);
+        p2.each(function(k, v) {
+          p.put(k, JSON.decode(v, true));
+        });
+      }
     }
     
     this.parsedOptions = p;
@@ -445,7 +458,7 @@ qwebirc.ui.SuppliedArgOptions = new Class({
     if(x.settableByURL !== true)
       return this.parent(x);
 
-    var opt = this.parsedOptions[x.optionId];
+    var opt = this.parsedOptions.get(String(x.optionId));
     if(!$defined(opt))
       return this.parent(x);
       
@@ -455,7 +468,7 @@ qwebirc.ui.SuppliedArgOptions = new Class({
     var result = [];
     this.getOptionList().forEach(function(x) {
       if(x.settableByURL && x.default_ != x.value)
-        result.push(x.optionId + "=" + x.value);
+        result.push(x.optionId + "=" + JSON.encode(x.value));
     }.bind(this));
     
     var raw = result.join("&");