-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.js
71 lines (60 loc) · 1.67 KB
/
application.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
69
70
71
// Requires jQuery template
var current_uuid;
function renderStudyList(url, template, target) {
next_url = null;
$.getJSON(url,
function(data) {
$.each(data.studies, function(i,item){
$.tmpl(template, item)
.appendTo(target)
.bind('click', function() {current_uuid = item.uuid; });
});
if(data.actions.next != data.actions.last) {
next_url = data.actions.next;
}
}).complete(function(data){
$(target).listview('refresh');
if(next_url) {
renderStudyList(next_url, template, target)
}
});
}
function renderOrderList(url, target) {
next_url = null;
$.getJSON(url,
function(data) {
$.each(data.submissions, function(i,item){
$('<li><a href="/api/1/' + item.uuid + '"> '+item.created_at+'</a></li>').appendTo(target);
});
if(data.actions.next != data.actions.last) {
next_url = data.actions.next;
}
}).complete(function(data){
$(target).listview('refresh');
if(next_url) {
renderOrderList(next_url, template, target)
}
});
}
function fetchStudyDetails(url, template, target) {
$.getJSON(url,
function(data) {
$.tmpl(template, data.study).appendTo(target);
});
}
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
function init() {
$( '#statusPage' ).live( 'pageinit',function(event){
fetchStudyDetails("/api/1/" + current_uuid, "studyTemplate", "#study");
});
$( '#indexPage').live( 'pageinit',function(event){
renderStudyList("/api/1/studies", "studyListTemplate", "#list");
});
$( '#ordersPage').live( 'pageinit',function(event){
renderOrderList("/api/1/" + current_uuid + "/submissions", "#orderList");
});
};