blob: e5799857c58cec2ac140194d2d9310126ccf389b [file] [log] [blame]
avm999634f7c03c2020-09-29 00:08:12 +02001<!DOCTYPE html>
2
3<html lang="ca">
4 <head>
delefmeefcc0302020-09-30 09:26:12 +02005 <meta charset="UTF-8">
6 <title>Seients DAFME</title>
7
8 <meta name="viewport" content="width=device-width, initial-scale=1">
9 <link rel="manifest" href="manifest.json">
10
11 <!-- Apple web app -->
12 <link rel="apple-touch-icon" href="./images/icon-64.png">
13 <meta name="apple-mobile-web-app-title" content="Seients DAFME">
14 <meta name="apple-mobile-web-app-capable" content="yes">
15 <meta name="apple-mobile-web-app-status-bar-style" content="white">
16
avm999634f7c03c2020-09-29 00:08:12 +020017 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
18 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css">
Andreu Huguet898768a2020-09-29 00:30:23 +020019 <link rel="stylesheet" href="./css/bulma-adjustments.css">
avm999634f7c03c2020-09-29 00:08:12 +020020 </head>
21 <body>
avm999634f7c03c2020-09-29 00:08:12 +020022 <script>
23 var elements = document.getElementsByClassName("button");
24 Array.from(elements).forEach(function(element) {
25 element.addEventListener('click', clickButton);
26 element.parent = element.parentNode.id;
27 });
28 var elements = document.getElementsByClassName("complex-button");
29 Array.from(elements).forEach(function(element) {
30 element.addEventListener('click', clickButton);
31 element.parent = element.parentNode.id;
32 });
33
34 var final_JSON = {
35 "class": null,
36 "number": "",
37 "letter": ""
38 };
39
40 function fillInSummary() {
41 var begins = new Date(parseInt(final_JSON.class.begins)*1000);
42 var ends = new Date(parseInt(final_JSON.class.ends)*1000);
43
avm99963c041bae2020-09-30 10:57:33 +020044 document.getElementById('subject-final').textContent = final_JSON.class.friendly_name || final_JSON.class.calendar_name;
avm999634f7c03c2020-09-29 00:08:12 +020045 document.getElementById('classroom-final').textContent = final_JSON.class.room;
46 document.getElementById('date-final').textContent = begins.toLocaleDateString();
47 document.getElementById('time-final').textContent = formatDate(begins) + ' - ' + formatDate(ends);
48 document.getElementById('letter-final').textContent = final_JSON.letter;
49 document.getElementById('number-final').textContent = final_JSON.number;
50 }
51
52 function clickButton(element) {
53 var btn = element.currentTarget;
54 var parent = btn.parent;
55
56 if (parent == "subject-container") {
57 // Canvi de background del button
58 var selectedClass = JSON.parse(btn.getAttribute('data-class'));
59 $("#subject-container .complex-button").removeClass("is-link")
60 btn.classList.add("is-link");
61 // Canvi JSON
62 final_JSON["class"] = selectedClass;
63 // Anchor següent pregunta
64 switchSection("section-2");
65 } else if (parent == "number-container") {
66 // Canvi de background del button
67 $("#number-container .button").removeClass("is-link is-light is-active")
68 btn.classList.add("is-link", "is-light", "is-active");
69 // Canvi JSON
70 final_JSON["number"] = btn.getAttribute('data-number');
71 // Introducció de totes les dades al resum final
72 fillInSummary();
73 // Anchor següent pregunta
74 switchSection("section-send");
75 } else if (parent == "letter-container") {
76 // Canvi de background del button
77 $("#letter-container .button").removeClass("is-link is-light is-active")
78 btn.classList.add("is-link", "is-light", "is-active");
79 // Canvi JSON
80 final_JSON["letter"] = btn.getAttribute('data-letter');
81 // Anchor següent pregunta
82 switchSection("section-3");
83 }
84 }
85
86 function formatDate(d) {
87 var str = "";
avm999634f7c03c2020-09-29 00:08:12 +020088 str += d.getHours();
89 str += ":";
90 if (d.getMinutes() < 10) str += "0";
91 str += d.getMinutes();
92 return str;
93 }
94
95 var api_url;
96
97 window.addEventListener('load', _ => {
98 // Check if user is signed in
99 if (localStorage.getItem('devMode') == 'true') {
100 var banner = document.getElementById('dev-mode');
101 banner.addEventListener('click', _ => {
102 localStorage.devMode = 'false';
103 location.reload();
104 });
105 banner.classList.remove('hidden');
106 api_url = localStorage.getItem('apiUrl') || 'https://covid-tracability-backend-dev.sandbox.avm99963.com/api/v1/'
107 } else {
108 api_url = "https://covid-tracability-backend-prod.sandbox.avm99963.com/api/v1/";
109 }
110 fetch(api_url + "isSignedIn", {
111 "mode": "cors",
112 "credentials": "include"
113 })
114 .then(response => response.json())
115 .then(data => {
116 if (!data.payload.signedIn) {
117 console.log("Not signed in!");
118 fetch(api_url + "getAuthUrl", {
119 "mode": "cors",
120 "credentials": "include"
121 })
122 .then(response => response.json())
123 .then(data => {
124 // TODO: redirect here
125 // location.href = data.payload.url;
126 console.warn('Log in here: ', data.payload.url);
127 });
128 }
129 });
130
131 fetch(api_url + "getCurrentClasses", {
132 "mode": "cors",
133 "credentials": "include"
134 })
135 .then(response => response.json())
136 .then(data => {
137 for (var classe of data.payload.classes) {
138 console.log(classe);
139
140 var hora_inici = formatDate(new Date(parseInt(classe.begins)*1000));
141 var hora_final = formatDate(new Date(parseInt(classe.ends)*1000));
142
143 var classeDiv = document.createElement('div');
144 classeDiv.classList.add('message', 'complex-button');
145 classeDiv.id = 'subject-' + classe.subject_id + '-' + classe.room;
146 classeDiv.setAttribute('data-class', JSON.stringify(classe));
147
148 var header = document.createElement('div');
149 header.classList.add('message-header');
avm99963c041bae2020-09-30 10:57:33 +0200150 header.textContent = classe.friendly_name || classe.calendar_name;
avm999634f7c03c2020-09-29 00:08:12 +0200151
152 var body = document.createElement('div');
153 body.classList.add('message-body');
154
155 var div1 = document.createElement('div');
156 var span = document.createElement('span');
157 span.textContent = classe.room;
158
159 div1.textContent = 'Aula ';
160 div1.appendChild(span);
161
162 var div2 = document.createElement('div');
163 div2.textContent = hora_inici + ' - ' + hora_final;
164
165 body.appendChild(div1);
166 body.appendChild(div2);
167
168 classeDiv.appendChild(header);
169 classeDiv.appendChild(body);
170
171 document.getElementById("subject-container").appendChild(classeDiv);
172 }
173
174 var elements = document.getElementsByClassName("button");
175 Array.from(elements).forEach(function(element) {
176 element.addEventListener('click', clickButton);
177 element.parent = element.parentNode.id;
178 });
179 var elements = document.getElementsByClassName("complex-button");
180 Array.from(elements).forEach(function(element) {
181 element.addEventListener('click', clickButton);
182 element.parent = element.parentNode.id;
183 });
184 });
185 });
186 </script>
187
188 <span id="dev-mode" class="hidden">Dev mode</span>
189
190 <nav class="navbar is-link">
191 <div class="navbar-brand">
192 <div class="navbar-item has-text-weight-bold">Traçabilitat DAFME</div>
193 </div>
194 </nav>
195
196 <section id="section-1" class="section">
197 <!--
198 <div class="field has-addons">
199 <p class="control">
200 <button class="button">&lt;</button>
201 </p>
202 <p class="control">
203 <input type="date" class="button">
204 </p>
205 <p class="control">
206 <button class="button">&gt;</button>
207 </p>
208 </div>
209 <div class="field has-addons">
210 <p class="control">
211 <button class="button">&lt;</button>
212 </p>
213 <p class="control">
214 <input type="button" class="button" value="08:00 - 08:30">
215 </p>
216 <p class="control">
217 <button class="button">&gt;</button>
218 </p>
219 </div><br>
220 -->
221 <div id="subject-container" class="grid buttons"></div><br>
222
223 </section>
224
225 <section id="section-2" class="section" style="display: none;">
226 <button class="button is-link is-light" onclick="switchSection('section-1')">Torna enrere (Classe)</button>
227
228 <div id="letter-container" class="buttons grid">
229 <button class="button" id="letter-A" data-letter="A">A</button>
230 <button class="button" id="letter-B" data-letter="B">B</button>
231 <button class="button" id="letter-C" data-letter="C">C</button>
232 <button class="button" id="letter-D" data-letter="D">D</button>
233 <button class="button" id="letter-E" data-letter="E">E</button>
234 <button class="button" id="letter-F" data-letter="F">F</button>
235 <button class="button" id="letter-G" data-letter="G">G</button>
236 <button class="button" id="letter-H" data-letter="H">H</button>
237 <button class="button" id="letter-I" data-letter="I">I</button>
238 <button class="button" id="letter-J" data-letter="J">J</button>
239 <button class="button" id="letter-K" data-letter="K">K</button>
240 <button class="button" id="letter-L" data-letter="L">L</button>
241 </div>
242 </section>
243
244 <section id="section-3" class="section" style="display: none;">
245 <button class="button is-link is-light" onclick="switchSection('section-2')">Torna enrere (Lletra)</button>
246
247 <div id="number-container" class="buttons grid">
248 <button class="button" id="number-1" data-number="1">1</button>
249 <button class="button" id="number-2" data-number="2">2</button>
250 <button class="button" id="number-3" data-number="3">3</button>
251 <button class="button" id="number-4" data-number="4">4</button>
252 <button class="button" id="number-5" data-number="5">5</button>
253 <button class="button" id="number-6" data-number="6">6</button>
254 <button class="button" id="number-7" data-number="7">7</button>
255 <button class="button" id="number-8" data-number="8">8</button>
256 <button class="button" id="number-9" data-number="9">9</button>
257 <button class="button" id="number-10" data-number="10">10</button>
258 </div>
259 </section>
260 <section id="section-send" class="section" style="display: none;">
261 <button class="button is-link is-light" onclick="switchSection('section-3')">Torna enrere (Número)</button>
262 <br/><br/>
263 <span class="has-text-weight-bold">Assignatura:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200264 <span id="subject-final">ASSIGNATURA ESCOLLIDA</span><br>
avm999634f7c03c2020-09-29 00:08:12 +0200265 <span class="has-text-weight-bold">Aula:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200266 <span id="classroom-final">AULA ESCOLLIDA</span><br>
avm999634f7c03c2020-09-29 00:08:12 +0200267 <span class="has-text-weight-bold">Data:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200268 <span id="date-final">DD/MM/YYYY</span><br>
avm999634f7c03c2020-09-29 00:08:12 +0200269 <span class="has-text-weight-bold">Hora:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200270 <span id="time-final">HH:MM - HH:MM</span><br>
avm999634f7c03c2020-09-29 00:08:12 +0200271 <span class="has-text-weight-bold">Posició:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200272 <span id="letter-final">A</span><span id="number-final">1</span><br><br>
avm999634f7c03c2020-09-29 00:08:12 +0200273
274 <button id="send-button" class="button is-link is-large">Omple el formulari</button><br><br>
275
276 Hi ha errors? <br /><a class="button is-link is-light" href="https://docs.google.com/forms/d/e/1FAIpQLSfT9o287VqLyhwR8LPdloAQWhuqCgA3NfdhgP5vb9_sVQHL-g/viewform">Completa el formulari manualment</a>
flopgui53b67b42020-09-30 11:48:34 +0200277
flopgui0a80b592020-09-30 11:52:12 +0200278 <br><br><article class="message is-warning">
flopgui53b67b42020-09-30 11:48:34 +0200279 <div class="message-body">
280 Aquest primers dies estem de prova! Mireu bé la informació, si hi ha res malament expliqueu-ho a l'Andreu: <a href="telf:+34681236024">+34 681 236 024</a>.
281 </div>
282 </article>
Ferran López6759ecf2020-09-30 11:32:44 +0200283 </section>
avm999634f7c03c2020-09-29 00:08:12 +0200284 <script>
285 var current_section = "section-1";
286
287 function toggleVisibility(id) {
288 var x = document.getElementById(id);
289 if (x.style.display === "none") {
290 x.style.display = "block";
291 } else {
292 x.style.display = "none";
293 }
294 }
295
296 function switchSection(s) {
297 setTimeout(function(){
298 toggleVisibility(current_section);
299 toggleVisibility(s);
300 current_section = s;
301 }, 75);
302 }
303
304 const idsFormulari = {
305 room: "1063142948",
306 day: "2115504093",
307 begins: "1749141911",
308 ends: "1827359679",
309 rows: {
310 A: "208184485",
311 B: "1077148310",
312 C: "642851281",
313 D: "1686039024",
314 E: "697835787",
315 F: "1511799646",
316 G: "809853432",
317 H: "182597499",
318 I: "1890539481",
319 J: "529159478",
320 K: "1615241874",
321 L: "1334263875"
322 },
323 notes: "1600275159"
324 };
325 const formBaseUrl = "https://docs.google.com/forms/d/e/1FAIpQLSfT9o287VqLyhwR8LPdloAQWhuqCgA3NfdhgP5vb9_sVQHL-g/viewform";
326
327 function sendForm() {
328 // Add subject to user
329 fetch(api_url + "addUserSubject", {
330 "method": "POST",
331 "body": JSON.stringify({
332 subject: final_JSON.class.subject_id
333 }),
334 "mode": "cors",
335 "credentials": "include"
336 })
337 .then(res => res.json())
338 .then(json => {
339 console.log("Subject added to user: ", json);
340
341 var begins = new Date(parseInt(final_JSON.class.begins)*1000);
342 var ends = new Date(parseInt(final_JSON.class.ends)*1000);
343
344 var params = new URLSearchParams();
345 params.append("entry." + idsFormulari.room, final_JSON.class.room); // class, number, letter
346 params.append("entry." + idsFormulari.day, begins.getFullYear().toString() + '-' + (begins.getMonth() + 1).toString().padStart(2, "0") + '-' + begins.getDate().toString().padStart(2, "0"));
347 params.append("entry." + idsFormulari.begins, formatDate(begins));
348 params.append("entry." + idsFormulari.ends, formatDate(ends));
349 params.append("entry." + idsFormulari.rows[final_JSON.letter], 'Columna ' + final_JSON.number);
avm99963c041bae2020-09-30 10:57:33 +0200350 // params.append("entry." + idsFormulari.notes, '[Autogenerat per delefme/covid-tracability -- Assignatura seleccionada: ' + (final_JSON.class.friendly_name || final_JSON.class.calendar_name) + ']');
avm999634f7c03c2020-09-29 00:08:12 +0200351
avm99963dbdc9652020-09-29 01:09:25 +0200352 var formulari_link = formBaseUrl + '?' + params.toString() + '#i1';
avm999634f7c03c2020-09-29 00:08:12 +0200353 window.location.href = formulari_link;
354 });
355 }
356
357 document.getElementById("send-button").addEventListener('click', function (el) {
358 document.getElementById('send-button').classList.add('is-loading');
359
360 sendForm();
361 });
362 </script>
363 </body>
364</html>