blob: d19d639f755f24f83e1847f41fbcc91452dc4436 [file] [log] [blame]
Ferran Lópeza514bea2020-10-03 23:02:10 +02001
2var current_section = "section-1";
3
4function toggleVisibility(id) {
5 var x = document.getElementById(id);
6 if (x.style.display == "none") {
7 x.style.display = "block";
8 } else {
9 x.style.display = "none";
10 }
11}
12
13function switchSection(s) {
14 setTimeout(function(){
15 toggleVisibility(current_section);
16 toggleVisibility(s);
17 current_section = s;
18 }, 75);
19}
20
21const idsFormulari = {
22 room: "1063142948",
23 day: "2115504093",
24 begins: "1749141911",
25 ends: "1827359679",
26 rows: {
27 A: "208184485",
28 B: "1077148310",
29 C: "642851281",
30 D: "1686039024",
31 E: "697835787",
32 F: "1511799646",
33 G: "809853432",
34 H: "182597499",
35 I: "1890539481",
36 J: "529159478",
37 K: "1615241874",
38 L: "1334263875"
39 },
40 notes: "1600275159"
41};
42const formBaseUrl = "https://docs.google.com/forms/d/e/1FAIpQLSfT9o287VqLyhwR8LPdloAQWhuqCgA3NfdhgP5vb9_sVQHL-g/viewform";
43
44function sendForm() {
45 // Add subject to user
46 fetch(api_url + "addUserSubject", {
47 "method": "POST",
48 "body": JSON.stringify({
49 subject: final_JSON.class.subject_id
50 }),
51 "mode": "cors",
52 "credentials": "include"
53 })
54 .then(res => res.json())
55 .then(json => {
56 console.log("Subject added to user: ", json);
57
58 var begins = new Date(parseInt(final_JSON.class.begins)*1000);
59 var ends = new Date(parseInt(final_JSON.class.ends)*1000);
60
61 var params = new URLSearchParams();
62 params.append("entry." + idsFormulari.room, final_JSON.class.room); // class, number, letter
63 params.append("entry." + idsFormulari.day, begins.getFullYear().toString() + '-' + (begins.getMonth() + 1).toString().padStart(2, "0") + '-' + begins.getDate().toString().padStart(2, "0"));
64 params.append("entry." + idsFormulari.begins, formatDate(begins));
65 params.append("entry." + idsFormulari.ends, formatDate(ends));
66 params.append("entry." + idsFormulari.rows[final_JSON.letter], 'Columna ' + final_JSON.number);
67 // params.append("entry." + idsFormulari.notes, '[Autogenerat per delefme/covid-tracability -- Assignatura seleccionada: ' + (final_JSON.class.friendly_name || final_JSON.class.calendar_name) + ']');
68
69 var formulari_link = formBaseUrl + '?' + params.toString() + '#i1';
70 window.location.href = formulari_link;
71 });
72 }
73
74 document.getElementById("send-button").addEventListener('click', function (el) {
75 document.getElementById('send-button').classList.add('is-loading');
76
77 sendForm();
78 });
79