-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsent_form.html
153 lines (135 loc) · 5.69 KB
/
consent_form.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!doctype html>
<html>
<!--
11/30/2020: Updated batch session logging to create a single array per subject with a chronological list of each time
6/19/2410/23/23 (CELS): Multi-lang support using Honeycomb style language file
-->
<head>
<link rel="stylesheet" href="css/consent_form.css" />
<script type="text/javascript" src="jatos.js"></script>
<script src="js/jquery-3.1.1.min.js"></script>
<meta charset="UTF-8" />
<title>Consent Form</title>
</head>
<body>
<script type="text/javascript">
function getID() {
// Try to get a reasonable ID code for this person
// URL > studySession > workerID
var sid = jatos.urlQueryParameters.sid;
if (sid == undefined) {
sid = jatos.studySessionData['sid'];
}
if (typeof sid == 'undefined') {
if (typeof jatos.workerId !== 'undefined') { // At least try the workerID
sid = jatos.workerId;
}
else { sid = 1234; }
}
return sid
}
function waitFor(conditionFunction) {
const poll = resolve => {
if(conditionFunction()) resolve();
else setTimeout(_ => poll(resolve), 400);
}
return new Promise(poll)
}
jatos.onLoad(async function () {
var sid = getID();
console.log('In consent, sid= ' + sid);
let date = new Date();
let dcode = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate()) +
"-" + date.getHours() + "-" + date.getMinutes();
console.log(dcode);
if (!jatos.batchSession.defined("/" + sid)) { // Make sure to create this as an array
console.log('no record yet, adding one at ' + "/" + sid);
jatos.batchSession.add("/" + sid, ["ConsentLoad_" + dcode]);
}
else { // Append to array
console.log('have the record, appending to ' + "/" + sid)
jatos.batchSession.add("/" + sid + "/-", "ConsentLoad_" + dcode);
}
var lang='en';
if (typeof jatos.studySessionData['lang'] !== 'undefined') {
lang=jatos.studySessionData['lang'];
}
if (jatos.studyJsonInput && typeof jatos.studyJsonInput['lang'] !== 'undefined' ) {
lang=jatos.studyJsonInput['lang']
}
if (jatos.batchJsonInput && typeof jatos.batchJsonInput['lang'] !== 'undefined' ) {
lang=jatos.batchJsonInput['lang']
}
// load honeycomb version of lang file
console.log('loading json lang')
var langfile='lang/omst_'+lang+'.json';
var json_prompts=null;
$.getJSON(langfile,function( data ) {
json_prompts=data;
console.debug(langfile + ' loaded...ish');
});
await waitFor(_ => json_prompts !== null);
console.log(json_prompts['task']['name'])
let prompts=json_prompts['consent']; // Load in this phase's section
// Basic HTML for test
p=document.createElement("p");
p.innerHTML='<div id="consenttext"><h1>' + prompts['title'] + '</h1>' +
prompts['study']['uni'] +
prompts['study']['sis'] +
prompts['study']['num'] +
'<br>' + prompts['researcher']['title'] +
prompts['researcher']['name'] +
prompts['researcher']['dept'] +
prompts['researcher']['tele'] + prompts['researcher']['email'] +
'<ul>' + prompts['text'] + prompts['prompt'] + '</ul>' +
'</div><div id="buttons">' +
'<button id="agreeButton">' + prompts['buttons']['agree'] + '</button>' +
'<button id="cancelButton">' + prompts['buttons']['cancel'] + '</button></div>';
document.body.appendChild(p)
$("#buttons").show();
$('#agreeButton').click(function () {
var sid = getID();
let date = new Date();
let dcode = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate()) +
"-" + date.getHours() + "-" + date.getMinutes();
jatos.batchSession.add("/" + sid + "/-", "ConsentAgreed_" + dcode);
var expdata = "Consent given, ID=" + sid + " URL ID=" + jatos.urlQueryParameters.sid;
//if (typeof jatos.studySessionData["taskindex"] !== 'undefined') { jatos.studySessionData["taskindex"] += 1; }
//jatos.submitResultData(result, jatos.startNextComponent);
var order=jatos.studySessionData["order"];
jatos.studySessionData["taskindex"] += 1;
if (typeof order === 'undefined') {
// We don't have an 'order' setup, so assume it's 1-N (e.g., we didn't use the setup.html in this exp)
console.log('faking an order')
order=Array(jatos.componentList.length).fill().map((e,i)=>i+1);
jatos.studySessionData["taskindex"]=jatos.componentPos;
}
//jatos.submitResultData(result, jatos.startNextComponent);
if (typeof order === 'undefined' || order.length == jatos.studySessionData["taskindex"]) { // we're done?
// Check if this came from SONA - should have URL.sid and .sona
if (typeof jatos.urlQueryParameters.sid === 'undefined' || typeof jatos.urlQueryParameters.sona === 'undefined' ||
typeof jatos.studyJsonInput['experiment_id'] === 'undefined' || typeof jatos.studyJsonInput['credit_token'] === 'undefined') { // not SONA - just finish
jatos.submitResultData(expdata,jatos.endStudy);
}
else { // SONA - give credit
var redirect='https://uci.sona-systems.com/webstudy_credit.aspx?experiment_id='+jatos.studyJsonInput['experiment_id']+
'&credit_token='+jatos.studyJsonInput['credit_token']+'&survey_code='+jatos.urlQueryParameters.sid;
jatos.endStudyAndRedirect(redirect,expdata);
}
}
else { // submit data and start the next
jatos.submitResultData(expdata, () => { jatos.startComponentByPos(order[jatos.studySessionData["taskindex"]]) });
}
});
$('#cancelButton').click(function () {
var sid = getID();
let date = new Date();
let dcode = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + (date.getDate()) +
"-" + date.getHours() + "-" + date.getMinutes();
jatos.batchSession.add("/" + sid + "/-", "ConsentNOTAgreed_" + dcode);
jatos.abortStudy("Consent not given.");
});
});
</script>
</body>
</html>