avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | |
| 3 | <html lang="ca"> |
| 4 | <head> |
delefme | efcc030 | 2020-09-30 09:26:12 +0200 | [diff] [blame] | 5 | <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 | |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 17 | <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 Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 19 | <link rel="stylesheet" href="./css/bulma-adjustments.css"> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 20 | </head> |
| 21 | <body> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 22 | <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 | |
avm99963 | c041bae | 2020-09-30 10:57:33 +0200 | [diff] [blame^] | 44 | document.getElementById('subject-final').textContent = final_JSON.class.friendly_name || final_JSON.class.calendar_name; |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 45 | 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 = ""; |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 88 | 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'); |
avm99963 | c041bae | 2020-09-30 10:57:33 +0200 | [diff] [blame^] | 150 | header.textContent = classe.friendly_name || classe.calendar_name; |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 151 | |
| 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"><</button> |
| 201 | </p> |
| 202 | <p class="control"> |
| 203 | <input type="date" class="button"> |
| 204 | </p> |
| 205 | <p class="control"> |
| 206 | <button class="button">></button> |
| 207 | </p> |
| 208 | </div> |
| 209 | <div class="field has-addons"> |
| 210 | <p class="control"> |
| 211 | <button class="button"><</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">></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 Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 264 | <span id="subject-final">ASSIGNATURA ESCOLLIDA</span><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 265 | <span class="has-text-weight-bold">Aula:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 266 | <span id="classroom-final">AULA ESCOLLIDA</span><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 267 | <span class="has-text-weight-bold">Data:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 268 | <span id="date-final">DD/MM/YYYY</span><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 269 | <span class="has-text-weight-bold">Hora:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 270 | <span id="time-final">HH:MM - HH:MM</span><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 271 | <span class="has-text-weight-bold">Posició:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 272 | <span id="letter-final">A</span><span id="number-final">1</span><br><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 273 | |
| 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> |
delefme | 8b6c2e4 | 2020-09-30 09:49:06 +0200 | [diff] [blame] | 277 | <br /><br /> |
| 278 | <p><u>Nota:</u> 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>.</p> |
delefme | 31bd27f | 2020-09-30 09:43:00 +0200 | [diff] [blame] | 279 | </section> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 280 | |
| 281 | <script> |
| 282 | var current_section = "section-1"; |
| 283 | |
| 284 | function toggleVisibility(id) { |
| 285 | var x = document.getElementById(id); |
| 286 | if (x.style.display === "none") { |
| 287 | x.style.display = "block"; |
| 288 | } else { |
| 289 | x.style.display = "none"; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | function switchSection(s) { |
| 294 | setTimeout(function(){ |
| 295 | toggleVisibility(current_section); |
| 296 | toggleVisibility(s); |
| 297 | current_section = s; |
| 298 | }, 75); |
| 299 | } |
| 300 | |
| 301 | const idsFormulari = { |
| 302 | room: "1063142948", |
| 303 | day: "2115504093", |
| 304 | begins: "1749141911", |
| 305 | ends: "1827359679", |
| 306 | rows: { |
| 307 | A: "208184485", |
| 308 | B: "1077148310", |
| 309 | C: "642851281", |
| 310 | D: "1686039024", |
| 311 | E: "697835787", |
| 312 | F: "1511799646", |
| 313 | G: "809853432", |
| 314 | H: "182597499", |
| 315 | I: "1890539481", |
| 316 | J: "529159478", |
| 317 | K: "1615241874", |
| 318 | L: "1334263875" |
| 319 | }, |
| 320 | notes: "1600275159" |
| 321 | }; |
| 322 | const formBaseUrl = "https://docs.google.com/forms/d/e/1FAIpQLSfT9o287VqLyhwR8LPdloAQWhuqCgA3NfdhgP5vb9_sVQHL-g/viewform"; |
| 323 | |
| 324 | function sendForm() { |
| 325 | // Add subject to user |
| 326 | fetch(api_url + "addUserSubject", { |
| 327 | "method": "POST", |
| 328 | "body": JSON.stringify({ |
| 329 | subject: final_JSON.class.subject_id |
| 330 | }), |
| 331 | "mode": "cors", |
| 332 | "credentials": "include" |
| 333 | }) |
| 334 | .then(res => res.json()) |
| 335 | .then(json => { |
| 336 | console.log("Subject added to user: ", json); |
| 337 | |
| 338 | var begins = new Date(parseInt(final_JSON.class.begins)*1000); |
| 339 | var ends = new Date(parseInt(final_JSON.class.ends)*1000); |
| 340 | |
| 341 | var params = new URLSearchParams(); |
| 342 | params.append("entry." + idsFormulari.room, final_JSON.class.room); // class, number, letter |
| 343 | params.append("entry." + idsFormulari.day, begins.getFullYear().toString() + '-' + (begins.getMonth() + 1).toString().padStart(2, "0") + '-' + begins.getDate().toString().padStart(2, "0")); |
| 344 | params.append("entry." + idsFormulari.begins, formatDate(begins)); |
| 345 | params.append("entry." + idsFormulari.ends, formatDate(ends)); |
| 346 | params.append("entry." + idsFormulari.rows[final_JSON.letter], 'Columna ' + final_JSON.number); |
avm99963 | c041bae | 2020-09-30 10:57:33 +0200 | [diff] [blame^] | 347 | // params.append("entry." + idsFormulari.notes, '[Autogenerat per delefme/covid-tracability -- Assignatura seleccionada: ' + (final_JSON.class.friendly_name || final_JSON.class.calendar_name) + ']'); |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 348 | |
avm99963 | dbdc965 | 2020-09-29 01:09:25 +0200 | [diff] [blame] | 349 | var formulari_link = formBaseUrl + '?' + params.toString() + '#i1'; |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 350 | window.location.href = formulari_link; |
| 351 | }); |
| 352 | } |
| 353 | |
| 354 | document.getElementById("send-button").addEventListener('click', function (el) { |
| 355 | document.getElementById('send-button').classList.add('is-loading'); |
| 356 | |
| 357 | sendForm(); |
| 358 | }); |
| 359 | </script> |
| 360 | </body> |
| 361 | </html> |