changeset 129:46822bd329da

Make the options page functional. The options page now uses the /uinfo interface to change e-mail and password values.
author John "Elwin" Edwards <elwin@sdf.org>
date Tue, 28 Aug 2012 17:38:25 -0700
parents bea4e7e703a2
children a2e071a95055
files options.html options.js
diffstat 2 files changed, 39 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/options.html	Mon Aug 27 21:28:10 2012 -0700
+++ b/options.html	Tue Aug 28 17:38:25 2012 -0700
@@ -5,7 +5,7 @@
 <script type="text/javascript" src="options.js"></script>
 <link rel="stylesheet" type="text/css" href="style-rlg.css">
 </head>
-<body onload="setup()" onkeydown="sendkey(event)">
+<body onload="setup()">
 <h1>RLG-Web Options</h1>
 <div id="switch">
   <span class="ibutton">E-mail</span>
@@ -13,11 +13,11 @@
 </div>
 <div class="formtable" id="o_email">
   <div><div>E-mail:</div><div><input type="text" name="email" id="input_email"></div></div>
-  <div><div><span class="ibutton">Save</span></div><div><span class="ibutton">Cancel</span></div></div>
+  <div><div><span class="ibutton" onclick="postemail()">Save</span></div><div><span class="ibutton">Cancel</span></div></div>
 </div>
 <div class="formtable" id="o_pw">
   <div><div>Password:</div><div><input type="password" name="pw" id="input_pw"></div></div>
-  <div><div><span class="ibutton">Save</span></div><div><span class="ibutton">Cancel</span></div></div>
+  <div><div><span class="ibutton" onclick="postpw()">Save</span></div><div><span class="ibutton">Cancel</span></div></div>
 </div>
 </body>
 </html>
--- a/options.js	Mon Aug 27 21:28:10 2012 -0700
+++ b/options.js	Tue Aug 28 17:38:25 2012 -0700
@@ -1,1 +1,36 @@
-/* Nothing here yet. */
+function setup() {
+  if (!("lcred" in sessionStorage))
+    return;
+  var url = "/uinfo/email?key=" + sessionStorage.getItem("lcred");
+  var req = new XMLHttpRequest();
+  req.onreadystatechange = function () {
+    if (req.readyState != 4 || req.status != 200) 
+      return;
+    var reply = JSON.parse(req.responseText);
+    if (!("email" in reply))
+      return;
+    document.getElementById("input_email").value = reply["email"];
+  }
+  req.open('GET', url, true);
+  req.send();
+}
+
+function postemail() {
+  if (!("lcred" in sessionStorage))
+    return;
+  var posturl = "/uinfo/email?key=" + sessionStorage.getItem("lcred");
+  var msg = {"v": document.getElementById("input_email").value};
+  var req = new XMLHttpRequest();
+  req.open('POST', posturl, true);
+  req.send(JSON.stringify(msg));
+}
+
+function postpw() {
+  if (!("lcred" in sessionStorage))
+    return;
+  var posturl = "/uinfo/pw?key=" + sessionStorage.getItem("lcred");
+  var msg = {"v": document.getElementById("input_pw").value};
+  var req = new XMLHttpRequest();
+  req.open('POST', posturl, true);
+  req.send(JSON.stringify(msg));
+}