application.js
1.36 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
function Application()
{
}
Application.prototype.init = function(menu) {
this.user = new User("#user", menu);
this.session = new Session("#sessid", "#sessinfo", this.user);
$(window).focus($.proxy(this.session.update, this.session));
$.getJSON("/version/", function(data) {
this.version = data.version;
$("#version").empty().append("version: " + this.version);
});
}
Application.prototype.logout = function() {
$.ajax({
dataType : "json",
url : "/authenticate/",
type : "DELETE",
success : $.proxy(this.user.update, this.user),
complete : $.proxy(this.session.update, this.session)
});
}
Application.prototype.login = function(ev) {
this._sendForm("#login", "/authenticate/", "POST", ev);
}
Application.prototype.signup = function(ev) {
this._sendForm("#signup", "/signup/", "POST", ev);
}
Application.prototype.userupdate = function(ev) {
this._sendForm("#myaccount", "/user/", "PUT", ev);
}
Application.prototype._sendForm = function(id, url, method, ev) {
ev.preventDefault();
$.ajax({
dataType : "json",
url : url,
type : method,
data : $(id + " form").serialize(),
success : $.proxy(this._formSuccess, this, id),
complete : $.proxy(this.session.update, this.session)
});
}
Application.prototype._formSuccess = function(id) {
this.user.update();
$(id + "-container").addClass("hide");
}
// vim: set ts=4 sw=4: