-
Notifications
You must be signed in to change notification settings - Fork 3
/
controller.js
69 lines (55 loc) · 1.62 KB
/
controller.js
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
var config = $.require("config");
var Imap = $.require("imap/client").Imap;
$.golf.imap = {};
$.golf.defaultRoute = "/login/";
$.golf.jssTimeout = 10;
$(document).bind("imap_state", function(event) {
if (imap.state == 0) {
$.golf.location("/connect/");
}
else if (imap.state == 1) {
$.golf.location("/login/");
}
else if (imap.state == 2) {
$.golf.location("/folder/"+requested_box+"/");
}
});
var imap = new Imap("/longpoll/");
window.imap = imap; // debugging
var mbox;
var requested_box = "INBOX";
$.golf.controller = [
{ route: "^/connect/$",
action: function(container, params) {
container.empty().append("<h3 style='color:red'>connecting...</h3>");
imap.connect(config.host, config.port);
}
},
{ route: "^/login/$",
action: function(container, params) {
if (!imap || imap.state == 0)
return $.golf.location("/connect/");
else if (imap.state == 2)
return $.golf.location("/folder/INBOX/");
else if (imap.state == 3)
return $.golf.location("/folder/"+imap.mailbox+"/");
container.empty().append(new Component.IMAP(imap));
}
},
{ route: "^/folder/(.*)/$",
action: function(container, params) {
if (!params[1])
return $.golf.location("/folder/INBOX/");
if (!imap || imap.state < 2) {
requested_box = params[1];
return $.golf.location("/login/");
}
if (!mbox)
mbox = new Component.Mailbox(imap);
if (! container.children().size() ||
mbox._dom !== container.children().eq(0))
container.empty().append(mbox);
imap.select(params[1]);
}
}
];