]> jfr.im git - irc/quakenet/qwebirc.git/commitdiff
Add dynamic setting of UI options in URL.
authorChris Porter <redacted>
Sat, 24 Apr 2010 02:28:21 +0000 (03:28 +0100)
committerChris Porter <redacted>
Sat, 24 Apr 2010 02:28:21 +0000 (03:28 +0100)
js/qwebircinterface.js
js/ui/baseui.js
js/ui/panes/embed.js
js/ui/panes/options.js

index 381ecbd76a77b4f7e0af9721d42719f7b7be1c85..49897807b03481cf70ddcc0c3b5de273e3440908 100644 (file)
@@ -19,6 +19,7 @@ qwebirc.ui.Interface = new Class({
     theme: undefined,
     baseURL: null,
     hue: null,
+    uiOptionsArg: null,
     dynamicBaseURL: "/",
     staticBaseURL: "/"
   },
@@ -44,6 +45,10 @@ qwebirc.ui.Interface = new Class({
       if(this.options.searchURL) {
         var args = qwebirc.util.parseURI(String(document.location));
         this.options.hue = this.getHueArg(args);
+        
+        if($defined(args["uio"]))
+          this.options.uiOptionsArg = args["uio"];
+
         var url = args["url"];
         var chans, nick = args["nick"];
         
index 3da28abb8f59e43b5f21c6b2a81a3ce0edd6d869..524a8530944612116d6d6cb0b282395b22fee812 100644 (file)
@@ -190,7 +190,7 @@ qwebirc.ui.StandardUI = new Class({
     this.parent(parentElement, windowClass, uiName, options);
 
     this.tabCompleter = new qwebirc.ui.TabCompleterFactory(this);
-    this.uiOptions = new qwebirc.ui.DefaultOptionsClass(this);
+    this.uiOptions = new qwebirc.ui.DefaultOptionsClass(this, options.uiOptionsArg);
     this.customWindows = {};
     
     var ev;
@@ -293,7 +293,9 @@ qwebirc.ui.StandardUI = new Class({
     d.setSubWindow(ew);
   },
   embeddedWindow: function() {
-    this.addCustomWindow("Embedding wizard", qwebirc.ui.EmbedWizard, "embeddedwizard", {baseURL: this.options.baseURL});
+    this.addCustomWindow("Embedding wizard", qwebirc.ui.EmbedWizard, "embeddedwizard", {baseURL: this.options.baseURL, uiOptions: this.uiOptions, optionsCallback: function() {
+      this.optionsWindow();
+    }.bind(this)});
   },
   optionsWindow: function() {
     this.addCustomWindow("Options", qwebirc.ui.OptionsPane, "optionspane", this.uiOptions);
index 9d4867d0e834017eddb18d79e0e43f26e63b4175..7a3fd1ef712da57699bf517f0fea8e3fc9804fce 100644 (file)
@@ -32,11 +32,16 @@ qwebirc.ui.EmbedWizardStep = new Class({
 qwebirc.ui.EmbedWizard = new Class({
   Implements: [Options, Events],
   options: {
-    parent: null,
+    uiOptions: null,
+    optionsCallback: null,
     baseURL: "http://webchat.quakenet.org/"
   },
   initialize: function(parent, options) {
-    this.setOptions(options);
+    /* for some unknown reason setOptions doesn't work... */
+    this.options.uiOptions = options.uiOptions;
+    this.options.baseURL = options.baseURL;
+    this.options.optionsCallback = options.optionsCallback;
+    
     this.create(parent);
     this.addSteps();
   },
@@ -110,7 +115,7 @@ qwebirc.ui.EmbedWizard = new Class({
     };
   
     this.welcome = this.newStep({
-      "title": "Welcome!",
+      "title": "Add webchat to your website",
       "first": "This wizard will help you create an embedded client by asking you questions then giving you the code to add to your website.<br/><br/>You can use the <b>Next</b> and <b>Back</b> buttons to navigate through the wizard; click <b>Next</b> to continue."
     });
     
@@ -143,6 +148,17 @@ qwebirc.ui.EmbedWizard = new Class({
       middle: promptdiv,
       "hint": "You need to display the dialog if you want the user to be able to set their nickname before connecting."
     });
+
+    var changeOptions = new Element("input");
+    changeOptions.type = "submit";
+    changeOptions.value = "Alter current look and feel";
+    changeOptions.addEvent("click", this.options.optionsCallback);
+
+    this.lookandfeel = this.newStep({
+      "title": "Alter look and feel?",
+      "first": "The look and feel will be copied from the current settings.",
+      middle: changeOptions
+    });
     
     var autoconnect = this.newRadio(promptdiv, "Connect without displaying the dialog.", "prompt", true);
     this.connectdialogr = this.newRadio(promptdiv, "Show the connect dialog.", "prompt");
@@ -216,6 +232,7 @@ qwebirc.ui.EmbedWizard = new Class({
     if(this.chanBox.value != "" && !this.choosenick.checked)
       this.steps.push(this.connectdialog);
     
+    this.steps.push(this.lookandfeel);
     this.steps.push(this.finish);
   },
   showStep: function() {
@@ -278,6 +295,10 @@ qwebirc.ui.EmbedWizard = new Class({
     if(connectdialog)
       URL.push("prompt=1");
 
+    var uioptions = this.options.uiOptions.serialise();
+    if(uioptions != "")
+      URL.push("uio=" + uioptions);
+      
     return this.options.baseURL + (URL.length>0?"?":"") + URL.join("&");
   }
 });
index 251b01d60ef0a4c8eb395111755289717f9cfc3a..2422f75e221d6b4960852e1ab97a9216bc1b33fc 100644 (file)
@@ -9,6 +9,10 @@ qwebirc.ui.supportsFocus = function() {
   return [true];
 }
 
+/**
+ * Note that options are settable by the uioptions url arg by default unless you specifiy
+ * settableByURL...
+ */
 qwebirc.config.DEFAULT_OPTIONS = [
   [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity (requires Flash)", true, {
     enabled: function() {
@@ -27,8 +31,12 @@ qwebirc.config.DEFAULT_OPTIONS = [
   [2, "DEDICATED_MSG_WINDOW", "Send privmsgs to dedicated messages window", false],
   [4, "DEDICATED_NOTICE_WINDOW", "Send notices to dedicated message window", false],
   [3, "NICK_OV_STATUS", "Show status (@/+) before nicknames in channel lines", true],
-  [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true],
-  [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true],
+  [5, "ACCEPT_SERVICE_INVITES", "Automatically join channels when invited by Q", true, {
+    settableByURL: false
+  }],
+  [6, "USE_HIDDENHOST", "Hide your hostmask when authed to Q (+x)", true, {
+    settableByURL: false
+  }],
   [8, "LASTPOS_LINE", "Show a last position indicator for each window", true, {
     enabled: qwebirc.ui.supportsFocus
   }],
@@ -213,7 +221,13 @@ qwebirc.config.Option = new Class({
         this.default_ = enabledResult[1];
     } else {
       this.enabled = true;
-    }    
+    }
+    
+    if($defined(extras) && $defined(extras.settableByURL)) {
+      this.settableByURL = extras.settableByURL;
+    } else {
+      this.settableByURL = true;
+    }
   },
   setSavedValue: function(x) {
     if(this.enabled)
@@ -411,6 +425,41 @@ qwebirc.ui.CookieOptions = new Class({
   }
 });
 
+qwebirc.ui.SuppliedArgOptions = new Class({
+  Extends: qwebirc.ui.CookieOptions,
+  initialize: function(ui, arg) {
+    var p = {};
+    
+    if($defined(arg) && arg != "") {
+      var decoded = qwebirc.util.b64Decode(arg);
+      if(decoded)
+        p = qwebirc.util.parseURI("?" + decoded);
+    }
+    
+    this.parsedOptions = p;
+    this.parent(ui);
+  },
+  _get: function(x) {
+    if(x.settableByURL !== true)
+      return this.parent(x);
+
+    var opt = this.parsedOptions[x.optionId];
+    if(!$defined(opt))
+      return this.parent(x);
+      
+    return opt;
+  },
+  serialise: function() {
+    var result = [];
+    this.getOptionList().forEach(function(x) {
+      if(x.settableByURL && x.default_ != x.value)
+        result.push(x.optionId + "=" + x.value);
+    }.bind(this));
+    
+    return qwebirc.util.b64Encode(result.join("&")).replaceAll("=", "");
+  }
+});
+
 qwebirc.ui.DefaultOptionsClass = new Class({
-  Extends: qwebirc.ui.CookieOptions
+  Extends: qwebirc.ui.SuppliedArgOptions
 });