-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscripts.js
111 lines (95 loc) · 3 KB
/
scripts.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
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
111
google.load('visualization', 1.0);
var timeout;
$( document ).ready(function() {
$("#title").html(eventName);
$("#sid").keyup(function (e) {
if (e.keyCode === 13) {
removeFromPage();
getStudent();
}
});
});
function getStudent(){
var id = $("#sid").val();
console.log(id);
if(typeof id == 'string') {
if(id.charAt(0) == 'P') id = id.substring(1);
}
var opts = {sendMethod: 'auto'};
var query = new google.visualization.Query(databaseInfo.link, opts);
query.setQuery('select * where ' + databaseInfo.column + ' =' + id);
query.send(handleQueryResponse);
console.log('sent');
var loading = {
sid: "1",
firstName: "Loading...",
lastName: "",
grade: "",
team: ""
}
addToPage(loading, 999999999);
$("#sid").val("");
$("img").remove();
}
function handleQueryResponse(response){
console.log("recieving response");
if(response.isError()){
console.log('Error: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
if(data.getNumberOfRows() > 1) {
alert("Please ask a teacher for help.");
removeFromPage();
$("#sid").val('');
return;
}else if(data.getNumberOfRows() < 1){
alert("Did you type your ID in correctly?");
removeFromPage();
$("#sid").val('');
return;
}
var student = {
sid: data.getValue(0,0),
firstName: data.getValue(0,1),
lastName: data.getValue(0,2),
grade: data.getValue(0,3),
team: data.getValue(0,4)
}
postToGoogle(student);
}
function postToGoogle(student) {
var form = document.createElement("form");
form.action = formInfo.link;
form.method = "POST";
form.id="ss-form";
form.target = "my_iframe";
var timeIn = new Date();
form.innerHTML = [
"<input id='entry_1826631571' name = '" + formInfo.timeIn + "'' value = '" + timeIn + "'/>",
"<input id='entry_846193839' name = '" + formInfo.sid + "' value = '" + student.sid + "'/>",
"<input id='entry_1810641923' name = '" + formInfo.firstName + "' value = '" + student.firstName + "'/>",
"<input id='entry_2112623826' name = '" + formInfo.lastName + "' value = '" + student.lastName + "'/>",
"<input id='entry_421600000' name = '" + formInfo.grade + "' value = '" + student.grade + "'/>",
"<input id='entry_1105692196' name = '" + formInfo.team + "' value = '" + student.team + "'/>"
].join("");
form.submit();
addToPage(student, 8000);
}
function addToPage(student, delay){
$("#student").attr("data-sid", student.sid);
$("#student #first-name").html(student.firstName);
$("#student #last-name").html(student.lastName);
$("#student #grade").html(student.grade);
$("#student #team").html(student.team);
clearTimeout(timeout);
timeout = setTimeout(removeFromPage, delay);
}
function removeFromPage(){
$("#student").attr("data-sid", 0);
$("#student #first-name").html("");
$("#student #last-name").html("");
$("#student #grade").html("");
$("#student #team").html("");
clearTimeout(timeout);
}