session.orig.js
2.18 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function Session(sInfo, sId, sUser)
{
this.eUser = $(sUser);
this.eId = $(sId);
this.canvas = $(sInfo + " canvas").get(0);
this.context = this.canvas.getContext("2d");
this.id = "none"
this.timeout = 0;
this.timeleft = 0;
this.user = null;
//this.draw();
}
Session.prototype.isAthenticated = function(data)
{
}
Session.prototype.authenticate = function(data)
{
this.username = data.username;
this.email = data.email;
this.firstname = data.firstname;
this.surname = data.surname;
name = "";
if ('' == this.username) {
name = "not logged in";
$("li.signup").removeClass("hide");
$("li.login").removeClass("hide");
$("li.logout").addClass("hide");
} else {
if ('' == this.firstname || '' == this.surname) {
name += this.username;
} else {
name += this.firstname + " " + this.surname;
}
$("li.signup").addClass("hide");
$("li.login").addClass("hide");
$("li.logout").removeClass("hide");
}
this.eUser.empty().append(name);
}
Session.prototype.loadJSON = function(data)
{
// this.stop();
this.id = ("0" == data.id)? "none" : data.id;
this.timeout = data.timeout * 10;
this.timeleft = data.timeleft * 10;
this.eId.empty().append(this.id);
this.draw();
if (0 < this.timeleft)
this.start();
}
Session.prototype.draw = function()
{
this.context.fillStyle = "rgb(255, 0, 0)";
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.context.fillStyle = "rgb(0, 255, 0)";
this.context.fillRect(0, 0,
this.canvas.width / this.timeout * this.timeleft,
this.canvas.height);
}
Session.prototype.start = function()
{
if (null === this.interval) {
this.interval = setInterval($.proxy(this.process, this), 1000);
}
}
Session.prototype.process = function()
{
if (0 >= this.timeleft) {
this.stop();
}
else {
this.timeleft -= 10;
this.draw();
}
}
Session.prototype.stop = function()
{
clearInterval(this.interval);
this.interval = null;
this.id = "none";
this.timeout = 0;
this.timeleft = 0;
this.username = "";
this.email = "";
this.firstname = "";
this.surname = "";
this.eId.empty().append("");
this.eUser.empty().append("not logged in");
this.draw();
}
// vim: set ts=4 sw=4: