Mercurial > hg > rlgwebd
annotate options.js @ 185:bbfda4a4eb7f
Finish moving DglSession methods into the prototype.
author | John "Elwin" Edwards |
---|---|
date | Tue, 20 Jan 2015 10:17:05 -0500 |
parents | 99fbc7c55b81 |
children |
rev | line source |
---|---|
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
1 function setup() { |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
2 if (!("lcred" in sessionStorage)) { |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
3 setstatus("You are not logged in."); |
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
4 return; |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
5 } |
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
6 var url = "/uinfo/email?key=" + sessionStorage.getItem("lcred"); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
7 var req = new XMLHttpRequest(); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
8 req.onreadystatechange = function () { |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
9 if (req.readyState != 4 || req.status != 200) |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
10 return; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
11 var reply = JSON.parse(req.responseText); |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
12 if (!("email" in reply)) { |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
13 setstatus("You are not logged in."); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
14 } |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
15 else { |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
16 setstatus("You are logged in as " + reply.u + "."); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
17 document.getElementById("input_email").value = reply["email"]; |
133
99fbc7c55b81
Options-related UI improvements.
John "Elwin" Edwards <elwin@sdf.org>
parents:
130
diff
changeset
|
18 //document.getElementById("switch").style.display = "block"; |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
19 } |
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
20 } |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
21 req.open('GET', url, true); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
22 req.send(); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
23 } |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
24 |
130
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
25 function setstatus(stattext) { |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
26 var statnode = document.createTextNode(stattext); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
27 var statdiv = document.getElementById("ostat"); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
28 statdiv.replaceChild(statnode, statdiv.firstChild); |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
29 } |
a2e071a95055
Options page: handle not being logged in.
John "Elwin" Edwards <elwin@sdf.org>
parents:
129
diff
changeset
|
30 |
129
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
31 function postemail() { |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
32 if (!("lcred" in sessionStorage)) |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
33 return; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
34 var posturl = "/uinfo/email?key=" + sessionStorage.getItem("lcred"); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
35 var msg = {"v": document.getElementById("input_email").value}; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
36 var req = new XMLHttpRequest(); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
37 req.open('POST', posturl, true); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
38 req.send(JSON.stringify(msg)); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
39 } |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
40 |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
41 function postpw() { |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
42 if (!("lcred" in sessionStorage)) |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
43 return; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
44 var posturl = "/uinfo/pw?key=" + sessionStorage.getItem("lcred"); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
45 var msg = {"v": document.getElementById("input_pw").value}; |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
46 var req = new XMLHttpRequest(); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
47 req.open('POST', posturl, true); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
48 req.send(JSON.stringify(msg)); |
46822bd329da
Make the options page functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
128
diff
changeset
|
49 } |