user.js
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function User(userSelector, menu)
{
this.userElement = $(userSelector);
this.menu = menu;
this.update();
}
User.prototype.update = function() {
$.getJSON("/currentuser/", $.proxy(this._setData, this));
}
User.prototype.clear = function() {
this.username = "";
this.email = "";
this.firstname = "";
this.surname = "";
this._displayUser();
}
User.prototype.isEmpty = function() {
if ("" == this.username) {
return true;
}
return false;
}
User.prototype._setData = function(data) {
this.username = data.username;
this.email = data.email;
this.firstname = data.firstname;
this.surname = data.surname;
this._displayUser();
this.menu.update();
}
User.prototype._displayUser = function() {
if (this.isEmpty()) {
this.userElement.empty().append("not logged in");
} else {
if ("" == this.firstname || "" == this.surname) {
this.userElement.empty().append(this.username);
} else {
this.userElement.empty()
.append(this.firstname + " " + this.surname);
}
}
}
// vim: set ts=4 sw=4: