/
pp-script.js
276 lines (221 loc) · 7.72 KB
/
pp-script.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//deal with mobile form entry and tab order for g form
if(document.querySelectorAll('.reg-practice input')){
let regularFields = document.querySelectorAll('.reg-practice input, .reg-practice textarea');
regularFields.forEach((field, index) => {
field.tabIndex = 1;
});
let altFields = document.querySelectorAll('.alt-practice input, .alt-practice textarea');
altFields.forEach((field, index) => {
field.tabIndex = 2;
});
}
//chart builder
document.addEventListener("DOMContentLoaded", function(){
let entries = document.querySelectorAll('.accordion-item')
var chartData = [
['Date', 'Translation' , 'Other'],
];
entries.forEach((entry) => {
//console.log(entry.dataset.pdate)
let theDate = entry.dataset.pdate;
let entryPractice = Math.round(entry.dataset.practice);
let altPractice = Math.round(entry.dataset.alt);
let eventData = [theDate, entryPractice, altPractice];
chartData.push(eventData);
//console.log(chartData);
});
if(document.getElementById('chart')){
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(chartData);
var options = {
chart: {
title: 'Practice Log',
//subtitle: 'Keep on track',
},
isStacked: true,
series: {
0:{color:'#022543'},
1:{color:'#a7a7a7'},
},
titlePosition: 'in',
axisTitlesPosition: 'in',
hAxis: {
textPosition: 'out',
title: 'Dates',
slantedText: true,
slantedTextAngle: 45,
},
vAxis: {
textPosition: 'in'
},
};
var chart = new google.charts.Bar(document.getElementById('chart'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}
}
//fill form for editing
const editButtons = document.querySelectorAll('.edit-entry');
editButtons.forEach((button) => {
button.addEventListener('click', function (event) {
//get data from previous submission
// Extract info from data-bs-* attributes
let type = button.dataset.type;
let practice = button.dataset.practice;
let altpractice = button.dataset.altpractice;
let emotion = button.dataset.satisfaction;
let altEmotion = button.dataset.altsatisfaction;
let parallel = button.dataset.parallel;
let consecFocus = button.dataset.consecutive;
let simalFocus = button.dataset.simal;
let listening = button.dataset.listening;//*
let deverb = button.dataset.deverb;//
let notes = button.dataset.notes;//
let reexpress = button.dataset.reexpress;//*
let delivery = button.dataset.delivery;//*
let other = button.dataset.other;//
let evs = button.dataset.evs;//*
let multitask = button.dataset.multitask;//*
let share = button.dataset.share;
let detail = button.dataset.detail;
// let reflectLearn = button.dataset.strat;
// let reflectBoxes = button.dataset.reflectselection;
let entryid = button.dataset.entryid;
//modal selection
let formPractice = document.querySelector('#input_1_1');
let formAltPractice = document.querySelector('#input_1_7');
pp_radio_check('#input_1_22', type);
pp_radio_check('#input_1_23', emotion);
pp_radio_check('#input_1_24', altEmotion);
pp_radio_check('#input_1_32', parallel);
pp_hide_show(type);
pp_checkbox_check('#field_1_17', consecFocus);
pp_checkbox_check('#field_1_25', simalFocus);
pp_checkbox_check('#field_1_34', share);
//get the form fields
let formListening = document.querySelector('#input_1_18');
let formDeverb = document.querySelector('#input_1_21');
let formNotes = document.querySelector('#input_1_26');
let formReexpress = document.querySelector('#input_1_27');
let formDelivery = document.querySelector('#input_1_28');
let formOther = document.querySelector('#input_1_30');
let formEvs = document.querySelector('#input_1_29');
let formMultitask = document.querySelector('#input_1_19');
let formDetail = document.querySelector('#input_1_35');
let formEntryId = document.querySelector('#input_1_15');
//set the form field values
formPractice.value = practice;
formAltPractice.value = altpractice;
pp_optional_reflect(listening, formListening);
pp_optional_reflect(deverb, formDeverb);
pp_optional_reflect(notes, formNotes);
pp_optional_reflect(reexpress, formReexpress);
pp_optional_reflect(delivery, formDelivery);
pp_optional_reflect(other, formOther);
pp_optional_reflect(evs, formEvs);
pp_optional_reflect(multitask, formMultitask);
pp_optional_reflect(detail, formDetail);
formEntryId.value = entryid;
})
})
});
function modalStudentComments(btnSrc){
const destination = document.querySelector('#student-input');
console.log(btnSrc);
let allComments = [];
let listening = btnSrc.dataset.listening;//*
let deverb = btnSrc.dataset.deverb;//
let notes = btnSrc.dataset.notes;//
let reexpress = btnSrc.dataset.reexpress;//*
let delivery = btnSrc.dataset.delivery;//*
let other = btnSrc.dataset.other;//
let evs = btnSrc.dataset.evs;//*
let multitask = btnSrc.dataset.multitask;//*
let share = btnSrc.dataset.share;
let detail = btnSrc.dataset.detail;
allComments.push(listening,deverb,notes,reexpress,delivery,other,evs,multitask,share,detail);
let comments = condenseStuComments(allComments)
destination.innerHTML = destination.innerHTML + comments;
}
function condenseStuComments(allComments){
let html = '';
allComments.forEach((element) => {
if(element != ''){
html = html + `<p>${element}</p>`
}
});
return html;
}
//optional reflections
function pp_optional_reflect(value, element){
if(value){
element.value = value;
element.disabled = false;
element.parentNode.parentNode.style.display = 'block'
}
}
//radio buttons
function pp_radio_check(fieldId, selectedValue){
const formEmotion = document.querySelector(fieldId);
const options = formEmotion.querySelectorAll('input');
options.forEach((option) => {
if(option.value == selectedValue){
//console.log(emotion)
option.checked = true
}
});
}
function pp_checkbox_check(fieldId, selectedChoices){
const selectedArray = selectedChoices.split(', ');
const field = document.querySelector(fieldId);
const options = field.querySelectorAll('input');
options.forEach((option) => {
if(selectedArray.includes(option.value)){
//console.log(emotion)
option.checked = true
}
});
}
//manual hide show based on type
function pp_hide_show(type){
if(type == 'Consecutive Interpretation'){
let field = document.querySelector('#field_1_17');
field.style.display = 'block';
pp_undisable(field);
}
if(type == 'Simultaneous Interpretation'){
let field = document.querySelector('#field_1_25');
field.style.display = 'block';
pp_undisable(field);
}
}
//undisable
function pp_undisable(field){
let disabled = field.querySelectorAll(':disabled')
disabled.forEach(function(item){
item.disabled = false
})
}
jQuery('#logData').on('hidden.bs.modal', function () {
location.reload();
})
const editButtons = document.querySelectorAll('.comment-entry');
editButtons.forEach((button) => {
button.addEventListener('click', function (event) {
let entryid = button.dataset.entryid;
let comment = button.dataset.comment;
let buttonSrc = document.querySelector('#btn-'+entryid);
let formEntryId = document.querySelector('#input_4_2');
let formComment = document.querySelector('#input_4_1');
formEntryId.value = entryid;
formComment.value = comment;
modalStudentComments(buttonSrc);
})
})
jQuery('#comment').on('hidden.bs.modal', function () {
location.reload();
})
jQuery('#profile').on('hidden.bs.modal', function () {
location.reload();
})