~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/settings/settings.js

  • Committer: mattgiuca
  • Date: 2008-02-25 05:52:08 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:577
settings: Now populates all fields on the fly with the info from the DB,
    generating the necessary DOM nodes.
    (YHNIHTTW, etc, etc).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
function onload()
24
24
{
25
 
    populate();
 
25
    revert_settings();
26
26
}
27
27
 
28
 
/* Populate the page with this user's account details */
29
 
function populate()
 
28
/* Fetch the user's details from the server, and populate the page */
 
29
function revert_settings()
30
30
{
31
31
    var callback = function(xhr)
32
32
        {
33
33
            user = JSON.parse(xhr.responseText);
 
34
            populate(user);
34
35
        }
35
36
    /* Just get details for the logged in user */
36
37
    ajax_call(callback, "userservice", "get_user", {}, "GET");
37
38
}
 
39
 
 
40
/* Populate the page with the given user's account details */
 
41
function populate(user)
 
42
{
 
43
    /* Plain text elements (non-editable) */
 
44
    var login = document.getElementById("login");
 
45
    var role = document.getElementById("role");
 
46
    var changepassword = document.getElementById("changepassword");
 
47
    var notices = document.getElementById("notices");
 
48
    /* Textbox (input) elements */
 
49
    var nick = document.getElementById("nick");
 
50
    var email = document.getElementById("email");
 
51
 
 
52
    var text;
 
53
    var p;
 
54
    var b;
 
55
    var table;
 
56
    var tbody;
 
57
    var tr;
 
58
    var td;
 
59
    var inputbox;
 
60
 
 
61
    /* Clear things */
 
62
    dom_removechildren(login);
 
63
    dom_removechildren(role);
 
64
    dom_removechildren(notices);
 
65
 
 
66
    /* Construct the page */
 
67
 
 
68
    /* "login" : Full Name (<b>login</b> / studentid) */
 
69
    text = user.fullname + " (";
 
70
    login.appendChild(document.createTextNode(text));
 
71
    text = user.login
 
72
    b = document.createElement("b");
 
73
    b.appendChild(document.createTextNode(text));
 
74
    login.appendChild(b);
 
75
    if (user.studentid != null)
 
76
        text = " / " + user.studentid + ")"
 
77
    else
 
78
        text = ")"
 
79
    login.appendChild(document.createTextNode(text));
 
80
 
 
81
    /* "role" : <p>Your privilege level is <b>rolenm</b>.</p>
 
82
     * Unless rolenm is "student"
 
83
     */
 
84
    if (user.rolenm != "student")
 
85
    {
 
86
        text = "Your privilege level is ";
 
87
        role.appendChild(document.createTextNode(text));
 
88
        b = document.createElement("b");
 
89
        text = user.rolenm;
 
90
        b.appendChild(document.createTextNode(text));
 
91
        role.appendChild(b);
 
92
        text = ".";
 
93
        role.appendChild(document.createTextNode(text));
 
94
    }
 
95
 
 
96
    /* "nick" and "email" boxes */
 
97
    nick.value = user.nick;
 
98
    email.value = user.email;
 
99
 
 
100
    /* Password change box */
 
101
    /* (Only if this user has a local password) */
 
102
    if (user.local_password)
 
103
    {
 
104
        p = document.createElement("h3");
 
105
        p.appendChild(document.createTextNode("Change password"))
 
106
        changepassword.appendChild(p);
 
107
        table = document.createElement("table");
 
108
        tbody = document.createElement("tbody");
 
109
 
 
110
        tr = document.createElement("tr");
 
111
        td = document.createElement("td");
 
112
        td.appendChild(document.createTextNode("New password:"))
 
113
        tr.appendChild(td);
 
114
        td = document.createElement("td");
 
115
        inputbox = document.createElement("input");
 
116
        inputbox.setAttribute("type", "password");
 
117
        inputbox.setAttribute("name", "newpass");
 
118
        inputbox.setAttribute("id", "newpass");
 
119
        inputbox.setAttribute("size", "40");
 
120
        td.appendChild(inputbox)
 
121
        tr.appendChild(td);
 
122
        tbody.appendChild(tr);
 
123
 
 
124
        tr = document.createElement("tr");
 
125
        td = document.createElement("td");
 
126
        td.appendChild(document.createTextNode("Retype password:"))
 
127
        tr.appendChild(td);
 
128
        td = document.createElement("td");
 
129
        inputbox = document.createElement("input");
 
130
        inputbox.setAttribute("type", "password");
 
131
        inputbox.setAttribute("name", "repeatpass");
 
132
        inputbox.setAttribute("id", "repeatpass");
 
133
        inputbox.setAttribute("size", "40");
 
134
        td.appendChild(inputbox)
 
135
        tr.appendChild(td);
 
136
        tbody.appendChild(tr);
 
137
 
 
138
        table.appendChild(tbody);
 
139
        changepassword.appendChild(table);
 
140
 
 
141
        p = document.createElement("p");
 
142
        p.appendChild(document.createTextNode("Please type your new password "
 
143
            + "twice, to make sure you remember it."))
 
144
        changepassword.appendChild(p);
 
145
    }
 
146
 
 
147
    if (user.pass_exp != null || user.acct_exp != null)
 
148
    {
 
149
        p = document.createElement("h3");
 
150
        text = "Notices";
 
151
        p.appendChild(document.createTextNode(text));
 
152
        notices.appendChild(p);
 
153
        if (user.pass_exp != null)
 
154
        {
 
155
            p = document.createElement("p");
 
156
            /* TODO: Nice passexp */
 
157
            var pass_exp = user.pass_exp.toString()
 
158
            text = "Your password will expire on " + pass_exp
 
159
                + ". You should change it before then to avoid having your "
 
160
                + "account disabled.";
 
161
            p.appendChild(document.createTextNode(text));
 
162
            notices.appendChild(p);
 
163
        }
 
164
        if (user.acct_exp != null)
 
165
        {
 
166
            p = document.createElement("p");
 
167
            /* TODO: Nice acct_exp */
 
168
            var acct_exp = user.acct_exp.toString()
 
169
            text = "Your IVLE account will expire on " + acct_exp + ".";
 
170
            p.appendChild(document.createTextNode(text));
 
171
            notices.appendChild(p);
 
172
        }
 
173
    }
 
174
}