-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewlayout.html
More file actions
executable file
·1034 lines (940 loc) · 51.1 KB
/
Copy pathnewlayout.html
File metadata and controls
executable file
·1034 lines (940 loc) · 51.1 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="color-scheme" content="light">
<title>Student Satisfaction Survey</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"/>
<meta http-equiv="Content-Security-Policy"
content="frame-src 'self' https://app.powerbi.com https://*.powerbi.com; child-src 'self' https://app.powerbi.com https://*.powerbi.com">
<style>
/* Floating action buttons for kiosk mode */
.fab{
position:fixed; min-width:44px; height:44px; border-radius:9999px;
padding:0 14px; font-weight:600; font-size:12px; display:flex; align-items:center; justify-content:center;
box-shadow:0 2px 6px rgba(0,0,0,.18); z-index:60; cursor:pointer; user-select:none;
}
#kioskEnter{ right:12px; bottom:12px; background:#000; color:#fff; }
#kioskEnter:hover{ background:#111; }
.kiosk-mode #kioskEnter{ display:none !important; }
#kioskExit{ display:none; position:fixed; right:0; top:0; width:56px; height:56px; z-index:70; background:transparent; cursor:pointer; }
#kioskExit:focus{ outline:2px solid rgba(185,28,28,.6); outline-offset:2px; }
.kiosk-mode #kioskExit{ display:block; }
.kiosk-mode #adminControls,
.kiosk-mode #sidebar,
.kiosk-mode #sidebarOverlay,
.kiosk-mode #buildingSelectionPage,
.kiosk-mode #analyticsPage { display:none !important; }
/* Allow scrolling in kiosk mode */
.kiosk-mode html, .kiosk-mode body { height:auto; overflow:auto; }
.kiosk-mode body{ position:static; inset:auto; height:auto; width:auto; overscroll-behavior:contain; }
.kiosk-mode #mainWrapper{ height:auto; overflow:visible; }
.kiosk-mode * { -webkit-touch-callout:none; user-select:none; }
.kiosk-mode input, .kiosk-mode textarea { -webkit-touch-callout:auto; user-select:text; }
/* Make sure kiosk restrictions never block the supporter login modal */
.kiosk-mode #loginModal,
.kiosk-mode #loginModal *{
-webkit-touch-callout: auto !important;
user-select: auto !important;
pointer-events: auto !important;
}
/* ==== Student-flow layout (token/QR/kiosk) ==== */
/* Hide top bar and use a tall, centered survey area for students */
body.student-flow header { display: none !important; }
body.student-flow #surveyPage { padding: 0 !important; }
body.student-flow #buildingSelectionPage,
body.student-flow #analyticsPage { display: none !important; }
/* Default student-flow: flat (no card) for token/QR */
body.student-flow #surveyCard{
margin: 0;
border-radius: 0;
box-shadow: none;
min-height: 100vh; /* fallback */
display: flex;
flex-direction: column;
justify-content: center;
max-width: 44rem; /* keep reasonable width */
}
@supports (min-height: 100svh) {
body.student-flow #surveyCard { min-height: 100svh; }
}
/* === Kiosk only: bring the card back === */
body.kiosk-mode.student-flow #surveyPage { padding: 1rem !important; }
body.kiosk-mode.student-flow #surveyCard{
margin: 1rem auto;
border-radius: 0.75rem; /* rounded card */
box-shadow: 0 10px 25px rgba(17,24,39,.12);
max-width: 44rem;
min-height: auto; /* don’t stretch full height when card is back */
}
</style>
</head>
<body class="bg-gray-50 flex min-h-screen">
<!-- Sidebar -->
<div id="sidebar" class="fixed inset-y-0 left-0 z-50 w-64 bg-white shadow-lg transform -translate-x-full transition-transform duration-300 ease-in-out">
<div class="flex items-center justify-between h-16 px-4 border-b">
<h2 class="text-lg font-semibold text-gray-800">Menu</h2>
<button id="closeSidebar" class="text-gray-500 hover:text-gray-700" aria-label="Close menu">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<nav class="mt-8">
<a href="#" id="surveyTab" class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100 border-r-4 border-red-500 bg-gray-50">
<svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
</svg>
Survey
</a>
<a href="#" id="analyticsTab" class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100">
<svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path>
</svg>
Analytics
</a>
<a href="#" id="backSelectorTab" class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100">
<svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/>
</svg>
Back to selector
</a>
<a href="#" id="resetTab" class="flex items-center px-4 py-3 text-gray-700 hover:bg-gray-100">
<svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v6h6M20 20v-6h-6M4 10a8 8 0 0114-5.292M20 14a8 8 0 01-14 5.292"/>
</svg>
Reset / Logout
</a>
</nav>
</div>
<div id="sidebarOverlay" class="fixed inset-0 bg-black bg-opacity-50 z-40 hidden"></div>
<div class="flex-1 flex flex-col" id="mainWrapper">
<!-- TOP BAR (hidden in student-flow) -->
<header class="h-16 flex items-center px-4 border-b bg-white">
<button id="openSidebar" class="text-gray-600 hover:text-gray-800 mr-3" aria-label="Open menu">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
</svg>
</button>
<h1 class="text-lg font-semibold text-gray-800">DTU Python Support Survey</h1>
</header>
<!-- Building Selection -->
<div id="buildingSelectionPage" class="flex-1 flex items-center justify-center p-4">
<div class="w-full max-w-xl md:max-w-3xl mx-auto bg-white rounded-lg shadow-lg p-4 sm:p-6 md:p-8">
<div class="flex items-center justify-between mb-6">
<h2 class="text-2xl font-bold text-gray-700">Select Your Building</h2>
<div id="adminControls" class="flex items-center gap-3 sm:gap-4">
<label class="inline-flex items-center text-gray-700">
<input id="workshopDayToggle" type="checkbox" class="h-5 w-5 text-red-500 border-gray-300 rounded">
<span class="ml-2 whitespace-nowrap">Workshop</span>
</label>
<button id="btnGenerateLink" type="button" class="text-sm bg-red-500 text-white px-3 py-2 rounded hover:bg-red-600">
Discord link
</button>
<button id="btnGenerateQR" type="button" class="text-sm bg-white border border-red-500 text-red-600 px-3 py-2 rounded hover:bg-red-50">
QR
</button>
</div>
</div>
<div class="space-y-4">
<button onclick="selectBuilding(302)" class="w-full p-4 border-2 border-gray-200 rounded-lg hover:border-red-300 hover:bg-red-50 transition-colors text-left">
<div class="font-semibold text-gray-700">Building 302</div>
<div class="text-sm text-gray-500">Main Python Support Office</div>
</button>
<button onclick="selectBuilding(358)" class="w-full p-4 border-2 border-gray-200 rounded-lg hover:border-red-300 hover:bg-red-50 transition-colors text-left">
<div class="font-semibold text-gray-700">Building 358</div>
<div class="text-sm text-gray-500">Secondary Python Support Office</div>
</button>
<div class="border-2 border-gray-200 rounded-lg p-4">
<div class="font-semibold text-gray-700 mb-2">Other Building</div>
<div class="text-sm text-gray-500 mb-3">Enter building number</div>
<div class="flex gap-2">
<input
id="customBuilding"
type="number"
placeholder="e.g. 324"
min="100"
max="500"
class="flex-1 border border-gray-300 p-2 rounded focus:ring-2 focus:ring-red-500 focus:border-red-500"
onkeypress="handleEnterKey(event)"
/>
<button onclick="selectCustomBuilding()" class="bg-red-500 text-white px-4 py-2 rounded hover:bg-red-600 transition-colors">
Select
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Survey -->
<div id="surveyPage" class="flex-1 flex items-center justify-center p-4 hidden">
<div id="surveyCard" class="w-full max-w-xl md:max-w-3xl mx-auto bg-white rounded-lg shadow-lg p-4 sm:p-6 md:p-8">
<div class="flex items-center justify-center mb-6">
<h2 class="text-2xl font-bold text-gray-700">Student Satisfaction Survey</h2>
</div>
<form id="surveyForm" class="space-y-6">
<div id="roleWorkshopGroup" class="grid gap-3 sm:grid-cols-3 sm:gap-6 items-start">
<div class="flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-6 order-1 sm:order-1 sm:col-span-2">
<label class="inline-flex items-center text-gray-700">
<input type="radio" name="role" value="student" class="form-radio" checked />
<span class="ml-2">Student</span>
</label>
<label class="inline-flex items-center text-gray-700">
<input type="radio" name="role" value="employee" class="form-radio" />
<span class="ml-2">PhD / Employee</span>
</label>
</div>
<div class="order-3 sm:order-2">
<fieldset>
<legend class="block text-gray-700 mb-2 font-medium">Attended workshop?</legend>
<div class="flex items-center gap-4 sm:justify-end">
<label class="inline-flex items-center text-gray-700">
<input type="radio" id="workshop_yes" name="workshop" value="yes" class="form-radio h-5 w-5 text-red-500 border-gray-300" />
<span class="ml-2">Yes</span>
</label>
<label class="inline-flex items-center text-gray-700">
<input type="radio" id="workshop_no" name="workshop" value="no" class="form-radio h-5 w-5 text-red-500 border-gray-300" />
<span class="ml-2">No</span>
</label>
</div>
</fieldset>
</div>
<div id="studentWrapper" class="order-2 sm:order-3 sm:col-span-3">
<label class="block text-gray-700 mb-2 font-medium" for="student_number">Student Number:</label>
<div class="flex">
<span class="inline-flex items-center px-3 text-gray-700 bg-gray-200 border border-r-0 border-gray-300 rounded-l">s</span>
<input id="student_number" name="student_number" type="text" inputmode="numeric" pattern="[0-9]{6}" placeholder="e.g. 123456" title="Enter 6 digits only. Example: s123456 (type only the digits after ‘s’)" class="flex-1 border border-gray-300 p-2 sm:p-3 rounded-r focus:ring-2 focus:ring-red-500 focus:border-red-500" required/>
</div>
</div>
<div id="usernameWrapper" class="hidden order-2 sm:order-3 sm:col-span-3">
<label class="block text-gray-700 mb-2 font-medium" for="dtu_username">DTU Credentials:</label>
<input id="dtu_username" name="dtu_username" type="text" pattern="[A-Za-z]{3,20}" placeholder="e.g. manufer" class="w-full border border-gray-300 p-2 sm:p-3 rounded focus:ring-2 focus:ring-red-500 focus:border-red-500"/>
</div>
</div>
<div>
<span class="block text-gray-700 mb-3 font-medium">Satisfaction (1 to 5):</span>
<div class="grid grid-cols-5 gap-2 sm:gap-4 place-items-center">
<label class="flex flex-col items-center text-gray-600 cursor-pointer">
<input type="radio" name="satisfaction" value="1" class="form-radio mb-1 sm:mb-2" required />
<img src="face1.png" alt="Satisfaction level 1" class="w-9 h-9 sm:w-10 sm:h-10" />
</label>
<label class="flex flex-col items-center text-gray-600 cursor-pointer">
<input type="radio" name="satisfaction" value="2" class="form-radio mb-1 sm:mb-2" />
<img src="face2.png" alt="Satisfaction level 2" class="w-9 h-9 sm:w-10 sm:h-10" />
</label>
<label class="flex flex-col items-center text-gray-600 cursor-pointer">
<input type="radio" name="satisfaction" value="3" class="form-radio mb-1 sm:mb-2" />
<img src="face3.png" alt="Satisfaction level 3" class="w-9 h-9 sm:w-10 sm:h-10" />
</label>
<label class="flex flex-col items-center text-gray-600 cursor-pointer">
<input type="radio" name="satisfaction" value="4" class="form-radio mb-1 sm:mb-2" />
<img src="face4.png" alt="Satisfaction level 4" class="w-9 h-9 sm:w-10 sm:h-10" />
</label>
<label class="flex flex-col items-center text-gray-600 cursor-pointer">
<input type="radio" name="satisfaction" value="5" class="form-radio mb-1 sm:mb-2" />
<img src="face5.png" alt="Satisfaction level 5" class="w-9 h-9 sm:w-10 sm:h-10" />
</label>
</div>
</div>
<div>
<label class="block text-gray-700 mb-2 font-medium" for="course_number">Course Number or Name (optional):</label>
<input id="course_number" name="course_number" list="courses" type="text" placeholder="e.g. 01003 - Mathematics 1a" class="w-full border border-gray-300 p-2 sm:p-3 rounded focus:ring-2 focus:ring-red-500 focus:border-red-500"/>
<datalist id="courses"></datalist>
</div>
<button id="submitButton" type="submit" class="bg-red-500 text-white px-6 py-3 rounded-lg hover:bg-red-600 w-full font-medium transition-colors">
Submit Survey
</button>
</form>
</div>
</div>
<!-- Analytics -->
<div id="analyticsPage" class="flex-1 p-0 hidden">
<div class="h-full w-full bg-white">
<div class="h-full w-full">
<iframe loading="lazy" title="Python Support Statistics BACKUP" class="w-full h-full" style="min-height: calc(100vh - 4rem);" src="https://app.powerbi.com/reportEmbed?reportId=c477ad7d-6b44-46ad-9c62-c9b66d6ac02b&autoAuth=true&ctid=f251f123-c9ce-448e-9277-34bb285911d9" frameborder="0" allowFullScreen="true"></iframe>
</div>
</div>
</div>
</div>
<!-- Supporter Login Modal -->
<div id="loginModal" class="fixed inset-0 bg-white flex items-center justify-center z-[1000]">
<div class="bg-white p-6 rounded-lg shadow-lg text-center max-w-xs w-full">
<h2 class="text-xl font-semibold mb-3 text-gray-700">Supporter Login</h2>
<input id="accessCodeInput" type="password" placeholder="Enter daily code" autofocus autocomplete="one-time-code" class="border border-gray-300 p-2 w-full rounded mb-4" />
<button id="codeSubmit" class="bg-red-500 text-white px-4 py-2 rounded-lg hover:bg-red-600 w-full">Enter</button>
<p id="loginError" class="text-sm text-red-600 mt-2 hidden">Incorrect code. Try again.</p>
</div>
</div>
<!-- Modals -->
<div id="thankYouModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-white p-6 rounded-lg shadow-lg text-center max-w-xs mx-auto">
<h2 class="text-xl font-semibold mb-2">We value your time</h2>
<p class="mb-4">Thank you for your feedback!</p>
<button id="closeModal" class="mt-2 bg-red-500 text-white px-4 py-2 rounded-lg hover:bg-red-600">Close</button>
</div>
</div>
<div id="errorModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white p-6 rounded-lg shadow-lg text-center max-w-xs mx-auto">
<div class="flex justify-center mb-3">
<svg class="w-16 h-16 text-red-600" fill="currentColor" stroke="currentColor" xmlns="http://www.w3.org/2000/svg" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" image-rendering="optimizeQuality" fill-rule="evenodd" clip-rule="evenodd" viewBox="0 0 511.999 463.377"><path d="M289.639 9.137c12.411 7.25 23.763 18.883 33.037 34.913l.97 1.813 1.118 1.941 174.174 302.48c33.712 56.407-1.203 113.774-66.174 112.973v.12H73.485c-.895 0-1.78-.04-2.657-.112-59.104-.799-86.277-54.995-61.909-106.852.842-1.805 1.816-3.475 2.816-5.201L189.482 43.959l-.053-.032c9.22-15.786 20.717-27.457 33.411-34.805C243.788-3 268.711-3.086 289.639 9.137zM255.7 339.203c13.04 0 23.612 10.571 23.612 23.612 0 13.041-10.572 23.613-23.612 23.613-13.041 0-23.613-10.572-23.613-23.613s10.572-23.612 23.613-23.612zm17.639-35.379c-.794 19.906-34.506 19.931-35.278-.006-3.41-34.108-12.129-111.541-11.853-143.591.284-9.874 8.469-15.724 18.939-17.955 3.231-.686 6.781-1.024 10.357-1.019 3.595.008 7.153.362 10.387 1.051 10.818 2.303 19.309 8.392 19.309 18.446l-.043 1.005-11.818 142.069z"/></svg>
</div>
<h2 id="errorTitle" class="text-xl font-semibold mb-2 text-gray-800">We couldn't submit your response</h2>
<p class="error-message mb-4 text-gray-600">An error occurred while submitting your response.</p>
<button id="closeErrorModal" class="mt-2 bg-red-500 text-white px-4 py-2 rounded-full hover:bg-red-600">Try Again</button>
</div>
</div>
<!-- QR Modal -->
<div id="qrModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-md">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Generate QR for Building</h3>
<div class="space-y-3 mb-4">
<p class="text-sm text-gray-600">Quick select:</p>
<div class="flex gap-2">
<button type="button" class="qr-quick btn-302 bg-gray-100 hover:bg-gray-200 px-3 py-1 rounded border" data-building="302">302</button>
<button type="button" class="qr-quick btn-358 bg-gray-100 hover:bg-gray-200 px-3 py-1 rounded border" data-building="358">358</button>
<button type="button" class="qr-quick btn-324 bg-gray-100 hover:bg-gray-200 px-3 py-1 rounded border" data-building="324">324</button>
</div>
<div>
<label for="qrBuilding" class="block text-sm text-gray-700 mb-1">Or enter any building (000–990):</label>
<input id="qrBuilding" type="number" min="0" max="990" placeholder="e.g. 324" class="w-full border border-gray-300 p-2 rounded focus:ring-2 focus:ring-red-500 focus:border-red-500"/>
</div>
<label class="inline-flex items-center text-gray-700">
<input id="qrWorkshopDay" type="checkbox" class="h-4 w-4 text-red-500 border-gray-300 rounded">
<span class="ml-2">Preselect Workshop</span>
</label>
</div>
<div class="flex items-center gap-2 mb-4">
<button id="qrCreate" class="bg-red-500 text-white px-4 py-2 rounded hover:bg-red-600">Create QR</button>
<button id="qrClose" class="bg-gray-200 text-gray-800 px-4 py-2 rounded hover:bg-gray-300">Close</button>
</div>
<p id="qrInlineError" class="text-sm text-red-600 mb-3 hidden"></p>
<div id="qrResult" class="hidden">
<canvas id="qrCanvas" class="mx-auto mb-3"></canvas>
<img id="qrImg" class="mx-auto mb-3 hidden" alt="QR code"/>
<div class="flex items-center gap-2">
<input id="qrLink" type="text" readonly class="flex-1 border border-gray-300 p-2 rounded text-xs" />
<button id="qrCopy" class="bg-gray-100 border px-3 py-2 rounded hover:bg-gray-200 text-sm">Copy</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.3/build/qrcode.min.js"></script>
<script type="module">
const endpoint = "https://python-support-proxy.azurewebsites.net/api/surveyProxy";
const tokenEndpoint = "https://python-support-proxy.azurewebsites.net/api/issueToken";
const qrSignEndpoint = "https://python-support-proxy.azurewebsites.net/api/qrRedirect";
const STORAGE_KEY = "surveySupportAuth";
// Reset support
(function () {
const params = new URLSearchParams(location.search);
if (params.get('reset') === '1') {
try { localStorage.removeItem(STORAGE_KEY); } catch {}
try { localStorage.removeItem('selectedBuilding'); } catch {}
['reset','t','token','b','wd'].forEach(k=>params.delete(k));
const next = location.pathname + (params.toString() ? `?${params.toString()}` : '');
location.replace(next);
}
})();
function getSavedKey() {
try { const saved = localStorage.getItem(STORAGE_KEY); return saved ? saved.split("|") : [null,null]; }
catch { return [null,null]; }
}
function isAuthValid() {
const [date, key] = getSavedKey();
const today = new Date().toISOString().slice(0, 10);
return date === today && !!key;
}
function showLogin() {
document.getElementById("loginModal").classList.remove("hidden");
document.getElementById("mainWrapper").classList.add("pointer-events-none", "opacity-40");
setTimeout(() => { const inp = document.getElementById("accessCodeInput"); if (inp) { inp.focus(); inp.select(); } }, 0);
}
function hideLogin() {
document.getElementById("loginModal").classList.add("hidden");
document.getElementById("mainWrapper").classList.remove("pointer-events-none", "opacity-40");
document.getElementById("loginError").classList.add("hidden");
}
// One-time token / QR flags
const sp = new URLSearchParams(window.location.search);
const hasOneTimeToken = sp.get('t') || sp.get('token');
const isQrLink = sp.has('b');
// If a supporter login is required, ensure kiosk mode is OFF so typing isn't blocked
if (!hasOneTimeToken && !isQrLink && !isAuthValid()) {
try { localStorage.removeItem('kioskMode'); } catch {}
document.body.classList.remove('kiosk-mode');
}
if (hasOneTimeToken || isQrLink) { hideLogin(); }
else if (isAuthValid()) { hideLogin(); }
else { showLogin(); }
// Login submit
document.getElementById("codeSubmit").addEventListener("click", async () => {
const input = document.getElementById("accessCodeInput").value.trim();
const ok = await fetch(endpoint, {
method: "POST",
headers: { "Content-Type": "application/json", "x-api-key": input },
body: JSON.stringify({ ping: true })
}).then(r => r.ok).catch(() => false);
if (ok) {
const today = new Date().toISOString().slice(0, 10);
try { localStorage.setItem(STORAGE_KEY, `${today}|${input}`); } catch {}
hideLogin();
document.getElementById("accessCodeInput").value = "";
} else {
document.getElementById("loginError").classList.remove("hidden");
}
});
document.getElementById("accessCodeInput").addEventListener("keydown", (e) => {
if (e.key === "Enter") { e.preventDefault(); document.getElementById("codeSubmit").click(); }
});
document.addEventListener('keydown', (e) => {
const modal = document.getElementById('loginModal');
if (modal && !modal.classList.contains('hidden') && e.key === 'Enter') {
e.preventDefault();
document.getElementById('codeSubmit')?.click();
}
});
// Selected building / query params
let selectedBuilding = (()=>{
try { const v = localStorage.getItem('selectedBuilding'); return v ? Number(v) : null; }
catch { return null; }
})();
const urlParams = new URLSearchParams(location.search);
const linkToken = urlParams.get('t') || urlParams.get('token');
const qpBuilding = urlParams.get('b');
const qpWD = urlParams.get('wd') === '1';
if (qpBuilding) {
selectedBuilding = Number(qpBuilding);
try { localStorage.setItem('selectedBuilding', selectedBuilding); } catch {}
}
if (linkToken) { selectedBuilding = null; } // one-time link = Online
/* Student-flow toggles (token/QR/kiosk) */
function isKiosk(){ try { return localStorage.getItem('kioskMode') === '1'; } catch { return false; } }
function applyStudentFlowLayout() {
const tokenOrQr = !!(linkToken || qpBuilding);
const on = tokenOrQr || isKiosk();
document.body.classList.toggle('student-flow', on);
}
// Sidebar lock for token/QR/kiosk
const tokenOrQr = !!linkToken || !!qpBuilding;
function applySidebarVisibility() {
const sidebar = document.getElementById('sidebar');
const overlay = document.getElementById('sidebarOverlay');
const openBtn = document.getElementById('openSidebar');
const hide = tokenOrQr || isKiosk();
if (sidebar) {
if (hide) {
sidebar.hidden = true;
sidebar.style.display = 'none';
sidebar.setAttribute('aria-hidden','true');
sidebar.setAttribute('inert','');
} else {
sidebar.hidden = false;
sidebar.style.display = '';
sidebar.removeAttribute('aria-hidden');
sidebar.removeAttribute('inert');
}
}
if (overlay) { overlay.classList.add('hidden'); overlay.style.display = 'none'; }
if (openBtn) { openBtn.style.display = hide ? 'none' : ''; }
if (hide) {
const analyticsPage = document.getElementById('analyticsPage');
if (analyticsPage && !analyticsPage.classList.contains('hidden')) {
switchToSurvey();
}
}
applyStudentFlowLayout();
}
// Token verify (non-blocking)
async function verifyOneTimeToken() {
if (!linkToken) return true;
try {
const resp = await fetch(endpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'x-token': linkToken },
body: JSON.stringify({ ping: true })
});
if (!resp.ok) {
showError('Oops, this link has expired. Please request a new one-time link from your supporter.');
document.querySelectorAll('#surveyForm input, #surveyForm select, #surveyForm textarea, #surveyForm button')
.forEach(el => { if (el.id !== 'closeErrorModal') el.disabled = true; });
return false;
}
return true;
} catch { return true; }
}
const buildingSelectionPage = document.getElementById('buildingSelectionPage');
const surveyPage = document.getElementById('surveyPage');
const analyticsPage = document.getElementById('analyticsPage');
async function generateOneTimeLink() {
if (isKiosk()) return;
try {
const resp = await fetch(tokenEndpoint, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'x-api-key': getSavedKey()[1] || '' },
body: JSON.stringify({ expiresHours: 24, building_Number: 'Online' })
});
if (!resp.ok) {
const txt = await resp.text().catch(()=> '');
showError('Could not generate link. ' + (txt || ''), resp.status);
return;
}
const data = await resp.json().catch(()=>({}));
const baseUrl = window.location.origin + window.location.pathname;
const wd = (document.getElementById('workshopDayToggle')?.checked) ? '&wd=1' : '';
const url = data.url || data.oneTimeUrl || `${baseUrl}?token=${encodeURIComponent(data.token)}${wd}`;
try { await navigator.clipboard.writeText(url); } catch {}
alert('Discord link copied to clipboard:\n' + url);
} catch (e) {
console.error(e);
showError('Unexpected error while generating the link.');
}
}
(function onReady(cb){ if (document.readyState==='loading'){ document.addEventListener('DOMContentLoaded', cb, {once:true}); } else { cb(); } })(() => {
const btnLink = document.getElementById('btnGenerateLink');
if (btnLink) btnLink.addEventListener('click', generateOneTimeLink);
const wdToggle = document.getElementById('workshopDayToggle');
if (wdToggle) {
try { wdToggle.checked = localStorage.getItem("workshopDay") === 'true'; } catch {}
wdToggle.addEventListener('change', () => {
try { localStorage.setItem("workshopDay", String(wdToggle.checked)); } catch {}
});
}
// QR modal wiring
const qrModal = document.getElementById('qrModal');
const qrCreate = document.getElementById('qrCreate');
const qrClose = document.getElementById('qrClose');
const qrCopy = document.getElementById('qrCopy');
const qrCanvas = document.getElementById('qrCanvas');
const qrImg = document.getElementById('qrImg');
const qrLinkInp = document.getElementById('qrLink');
const qrResult = document.getElementById('qrResult');
const qrBuildingInp = document.getElementById('qrBuilding');
const qrWorkshopDay = document.getElementById('qrWorkshopDay');
const qrInlineError = document.getElementById('qrInlineError');
function openQrModal() {
if (isKiosk()) return;
if (selectedBuilding !== null && !isNaN(selectedBuilding)) {
qrBuildingInp.value = String(selectedBuilding);
} else {
qrBuildingInp.value = '';
}
try { qrWorkshopDay.checked = (localStorage.getItem("workshopDay") === 'true'); } catch {}
if (qrImg) { qrImg.src = ''; qrImg.classList.add('hidden'); }
qrCanvas.classList.remove('hidden');
qrResult.classList.add('hidden');
if (qrInlineError) { qrInlineError.textContent = ''; qrInlineError.classList.add('hidden'); }
qrModal.classList.remove('hidden');
}
function closeQrModal() { qrModal.classList.add('hidden'); }
if (document.getElementById('btnGenerateQR')) {
document.getElementById('btnGenerateQR').addEventListener('click', openQrModal);
}
qrModal?.querySelectorAll('.qr-quick').forEach(btn => {
btn.addEventListener('click', () => {
const v = btn.getAttribute('data-building');
qrBuildingInp.value = v;
if (qrInlineError) { qrInlineError.textContent = ''; qrInlineError.classList.add('hidden'); }
});
});
if (qrBuildingInp) {
qrBuildingInp.addEventListener('input', () => {
if (qrInlineError) { qrInlineError.textContent = ''; qrInlineError.classList.add('hidden'); }
});
}
async function createQr() {
if (isKiosk()) return;
const bVal = qrBuildingInp.value.trim();
const bNum = Number(bVal);
if (bVal === '' || isNaN(bNum) || bNum < 0 || bNum > 990) {
if (qrInlineError) {
qrInlineError.textContent = 'Please enter a valid building between 000 and 990 or use a quick option.';
qrInlineError.classList.remove('hidden');
}
return;
} else if (qrInlineError) {
qrInlineError.textContent = '';
qrInlineError.classList.add('hidden');
}
try {
const resp = await fetch(`${qrSignEndpoint}?sign=1&b=${encodeURIComponent(String(bNum))}&wd=${qrWorkshopDay.checked ? 1 : 0}`, {
method: 'GET',
headers: { 'x-api-key': getSavedKey()[1] || '' }
});
if (!resp.ok) {
const txt = await resp.text().catch(()=> '');
showError('Could not create static QR. ' + (txt || ''), resp.status);
return;
}
const data = await resp.json();
const url = data.url;
qrLinkInp.value = url;
if (window.QRCode && QRCode.toCanvas) {
const ctx = qrCanvas.getContext('2d');
ctx.clearRect(0, 0, qrCanvas.width, qrCanvas.height);
await QRCode.toCanvas(qrCanvas, url, { width: 280, margin: 2 });
qrCanvas.classList.remove('hidden');
qrImg.classList.add('hidden');
} else {
const encoded = encodeURIComponent(url);
qrCanvas.classList.add('hidden');
qrImg.classList.remove('hidden');
qrImg.src = `https://api.qrserver.com/v1/create-qr-code/?size=280x280&data=${encoded}`;
qrImg.onerror = function () {
qrImg.onerror = null;
qrImg.src = `https://chart.googleapis.com/chart?chs=280x280&cht=qr&chl=${encoded}`;
};
}
qrResult.classList.remove('hidden');
} catch (e) {
console.error(e);
showError('Unexpected error while generating the QR.');
}
}
qrCreate?.addEventListener('click', createQr);
qrClose?.addEventListener('click', closeQrModal);
qrCopy?.addEventListener('click', async () => {
try { await navigator.clipboard.writeText(qrLinkInp.value); } catch {}
});
applySidebarVisibility();
applyStudentFlowLayout();
});
// Building selection helpers
function selectBuilding(buildingNumber) {
if (isKiosk()) return;
selectedBuilding = buildingNumber;
try { localStorage.setItem('selectedBuilding', buildingNumber); } catch {}
showSurveyForm();
}
function selectCustomBuilding() {
if (isKiosk()) return;
const customInput = document.getElementById('customBuilding');
const buildingNumber = parseInt(customInput.value);
if (!customInput.value || isNaN(buildingNumber) || buildingNumber <= 100 || buildingNumber >= 500) {
showError('Please enter a valid building number (101-499).');
return;
}
selectBuilding(buildingNumber);
}
function handleEnterKey(event) { if (event.key === 'Enter') { selectCustomBuilding(); } }
function showBuildingSelection() {
if (isKiosk()) return;
buildingSelectionPage.classList.remove('hidden');
surveyPage.classList.add('hidden');
analyticsPage.classList.add('hidden');
syncFabVisibility();
syncBackSelectorVisibility();
}
function showSurveyForm() {
buildingSelectionPage.classList.add('hidden');
surveyPage.classList.remove('hidden');
analyticsPage.classList.add('hidden');
const preferWD = qpWD || (localStorage.getItem("workshopDay") === 'true');
const workshopYes = document.getElementById('workshop_yes');
const workshopNo = document.getElementById('workshop_no');
if (workshopYes && workshopNo) { workshopYes.checked = !!preferWD; workshopNo.checked = !preferWD; }
if (linkToken) { verifyOneTimeToken(); }
syncFabVisibility();
syncBackSelectorVisibility();
}
window.selectBuilding = selectBuilding;
window.selectCustomBuilding = selectCustomBuilding;
window.handleEnterKey = handleEnterKey;
window.showBuildingSelection = showBuildingSelection;
// Sidebar & nav
const sidebar = document.getElementById('sidebar');
const sidebarOverlay = document.getElementById('sidebarOverlay');
const openSidebarBtn = document.getElementById('openSidebar');
const closeSidebarBtn = document.getElementById('closeSidebar');
const surveyTab = document.getElementById('surveyTab');
const analyticsTab = document.getElementById('analyticsTab');
const backSelectorTab = document.getElementById('backSelectorTab');
const resetTab = document.getElementById('resetTab');
function openSidebar() {
if (isKiosk() || tokenOrQr) return;
sidebar.classList.remove('-translate-x-full');
sidebarOverlay.classList.remove('hidden');
document.body.classList.add('overflow-hidden');
}
function closeSidebar() {
sidebar.classList.add('-translate-x-full');
sidebarOverlay.classList.add('hidden');
document.body.classList.remove('overflow-hidden');
}
openSidebarBtn?.addEventListener('click', openSidebar);
closeSidebarBtn?.addEventListener('click', closeSidebar);
sidebarOverlay?.addEventListener('click', closeSidebar);
function switchToSurvey(e) {
if (e) e.preventDefault();
if (isKiosk()) { showSurveyForm(); return; }
if (selectedBuilding === null) showBuildingSelection(); else showSurveyForm();
surveyTab.classList.add('border-r-4','border-red-500','bg-gray-50');
analyticsTab.classList.remove('border-r-4','border-red-500','bg-gray-50');
closeSidebar();
}
function switchToAnalytics(e) {
if (e) e.preventDefault();
if (isKiosk() || tokenOrQr) return;
buildingSelectionPage.classList.add('hidden');
surveyPage.classList.add('hidden');
analyticsPage.classList.remove('hidden');
analyticsTab.classList.add('border-r-4','border-red-500','bg-gray-50');
surveyTab.classList.remove('border-r-4','border-red-500','bg-gray-50');
closeSidebar();
syncFabVisibility();
syncBackSelectorVisibility();
}
surveyTab?.addEventListener('click', switchToSurvey);
analyticsTab?.addEventListener('click', switchToAnalytics);
backSelectorTab?.addEventListener('click', e => { e.preventDefault(); showBuildingSelection(); closeSidebar(); });
resetTab?.addEventListener('click', e => { e.preventDefault(); location.href = location.pathname + '?reset=1'; });
function syncBackSelectorVisibility(){
if (!backSelectorTab) return;
const onSelectorPage = !buildingSelectionPage.classList.contains('hidden');
backSelectorTab.style.display = onSelectorPage ? 'none' : '';
}
function friendlyError(raw, status = 0, usingToken = false) {
const text = (typeof raw === 'string') ? raw : (raw?.message || '');
const l = (text || '').toLowerCase();
let title = "We couldn't submit your response";
let message = 'Please try again in a moment.';
const roleNow = (document.querySelector('input[name="role"]:checked')?.value || 'student');
if (l.includes('study number does not exist') || l.includes('student number does not exist')) {
if (roleNow === 'employee') { title = 'DTU username not found'; message = "We couldn't find that DTU username. Please enter your DTU credentials (letters only, e.g. 'manufer') and try again."; }
else { title = 'Student number not found'; message = "We couldn't find that student number. Please check the six digits after 's' on your DTU ID (e.g. s123456) and try again."; }
} else if (l.includes('invalid or used token') || l.includes('token expired') || (status === 401 && usingToken) || l.includes('link has expired')) {
title = "Oops, this link has expired"; message = 'This one-time link has already been used or expired. Please request a new link from your supporter.';
} else if (l.includes('unauthorized')) {
title = 'Not authorised'; message = 'Your session has expired. Please refresh and try again.';
} else if (status >= 500) {
title = 'Service temporarily unavailable'; message = 'We are experiencing a temporary problem. Please try again in a minute.';
} else if (status === 429) {
title = 'Too many attempts'; message = 'Please wait a moment and try again.';
} else if (text && text.trim()) { message = text; }
return { title, message };
}
function showError(input, status) {
const usingToken = !!(new URLSearchParams(location.search).get('t') || new URLSearchParams(location.search).get('token'));
const { title, message } = (typeof input === 'string')
? friendlyError(input, status, usingToken)
: (input && typeof input === 'object') ? input : friendlyError('', status, usingToken);
const titleEl = document.getElementById('errorTitle');
if (titleEl) titleEl.textContent = title;
document.querySelector('.error-message').textContent = message;
let redirectOnErrorClose = false;
const combo = (title + ' ' + message).toLowerCase();
const isExpiredTokenError = usingToken && (
combo.includes('link has expired') ||
combo.includes('invalid or used token') ||
combo.includes('token expired')
);
const closeBtn = document.getElementById('closeErrorModal');
if (closeBtn) {
if (isExpiredTokenError) { redirectOnErrorClose = true; closeBtn.textContent = 'Go to Python Support'; }
else { closeBtn.textContent = 'Try Again'; }
closeBtn.onclick = () => {
document.getElementById('errorModal').classList.add('hidden');
if (redirectOnErrorClose && usingToken) { window.location.replace('https://pythonsupport.dtu.dk/'); }
};
}
document.getElementById('errorModal').classList.remove('hidden');
}
// Role toggle (resets abandoned field)
const form = document.getElementById("surveyForm");
const roleInputs = form.querySelectorAll('input[name="role"]');
const studentWrapper = document.getElementById('studentWrapper');
const usernameWrapper = document.getElementById('usernameWrapper');
const studentNumInput = document.getElementById('student_number');
const usernameInput = document.getElementById('dtu_username');
roleInputs.forEach(radio => radio.addEventListener('change', toggleRole));
function toggleRole() {
const isStudent = form.role.value === 'student';
studentWrapper.classList.toggle('hidden', !isStudent);
usernameWrapper.classList.toggle('hidden', isStudent);
studentNumInput.required = isStudent;
usernameInput.required = !isStudent;
if (isStudent) {
studentNumInput.disabled = false;
usernameInput.disabled = true;
usernameInput.value = '';
usernameInput.setCustomValidity('');
} else {
usernameInput.disabled = false;
studentNumInput.disabled = true;
studentNumInput.value = '';
studentNumInput.setCustomValidity('');
}
}
toggleRole();
function setStudentCustomValidation() {
const isStudent = (form.role.value === 'student');
if (!isStudent || studentNumInput.disabled) { studentNumInput.setCustomValidity(''); return; }
const v = (studentNumInput.value || '').trim();
if (!v) studentNumInput.setCustomValidity("Please enter your student number: type the 6 digits after 's' (e.g. s123456).");
else if (!/^\d{6}$/.test(v)) studentNumInput.setCustomValidity("Format: exactly 6 digits. Example: s123456. Don’t type the 's'—it's already filled in.");
else studentNumInput.setCustomValidity('');
}
if (studentNumInput) {
studentNumInput.addEventListener('input', () => { studentNumInput.setCustomValidity(''); });
studentNumInput.addEventListener('blur', setStudentCustomValidation);
studentNumInput.addEventListener('invalid', setStudentCustomValidation);
}
const thankYouModal = document.getElementById("thankYouModal");
const closeBtn = document.getElementById("closeModal");
const submitButton = document.getElementById("submitButton");
let redirectOnThankYouClose = false;
form.addEventListener("submit", async (e) => {
e.preventDefault();
submitButton.disabled = true;
submitButton.textContent = 'Submitting...';
submitButton.classList.add('opacity-50', 'cursor-not-allowed');
const isStudent = form.role.value === 'student';
const linkToken = new URLSearchParams(location.search).get('t') || new URLSearchParams(location.search).get('token');
const payload = {
role: form.role.value,
student_number: isStudent ? 's' + studentNumInput.value.trim() : null,
username: !isStudent ? usernameInput.value.trim() : null,
satisfaction: Number(form.querySelector('input[name="satisfaction"]:checked').value),
course_number: (document.getElementById('course_number').value || '').trim() || null,
building_Number: linkToken ? null : selectedBuilding,
workshop: (form.elements['workshop'] && form.elements['workshop'].value === 'yes'),
token: linkToken || null,
};
try {
const headers = { "Content-Type": "application/json" };
if (linkToken) { headers["x-token"] = linkToken; } else { headers["x-api-key"] = getSavedKey()[1] || ""; }
const response = await fetch(endpoint, { method: "POST", headers, body: JSON.stringify(payload) });
if (response.ok) {
if (linkToken) {
thankYouModal.classList.remove('hidden');
redirectOnThankYouClose = true;
setTimeout(() => { window.location.replace('https://pythonsupport.dtu.dk/'); }, 7000);
return;
}
thankYouModal.classList.remove('hidden');
form.reset();
form.role.value = 'student';
toggleRole();
{
const preferWD = qpWD || (localStorage.getItem("workshopDay") === 'true');
const workshopYes = document.getElementById('workshop_yes');
const workshopNo = document.getElementById('workshop_no');
if (workshopYes && workshopNo) { workshopYes.checked = !!preferWD; workshopNo.checked = !preferWD; }
}
studentNumInput.value = '';
studentNumInput.focus();
document.activeElement?.blur();
setTimeout(() => { thankYouModal.classList.add('hidden'); }, 3000);
} else {
let raw = '';
try {
const ct = (response.headers.get('Content-Type') || '').toLowerCase();
if (ct.includes('application/json')) {
const j = await response.json();
raw = j?.message || (typeof j === 'string' ? j : JSON.stringify(j));
} else {
const t = await response.text();
if (t && t.trim().length) raw = t.trim();
}
} catch {}
showError(friendlyError(raw, response.status, !!linkToken), response.status);
if (form.role.value === 'student') { studentNumInput.focus(); } else { usernameInput?.focus(); }
}
} catch (err) {
console.error("Background submit failed:", err);
showError('A network error occurred. Please check your connection and try again.');
} finally {
submitButton.disabled = false;
submitButton.textContent = 'Submit Survey';
submitButton.classList.remove('opacity-50', 'cursor-not-allowed');
}
});
closeBtn.addEventListener('click', () => {
const linkToken = new URLSearchParams(location.search).get('t') || new URLSearchParams(location.search).get('token');
if (redirectOnThankYouClose && linkToken) {
window.location.replace('https://pythonsupport.dtu.dk/');
} else {
thankYouModal.classList.add('hidden');
}
});
/* ===== Kiosk helpers (now 30% zoom) ===== */
const kioskEnterBtn = document.getElementById('kioskEnter');
const kioskExitBtn = document.getElementById('kioskExit');
const KIOSK_KEY = 'kioskMode';
function setKiosk(v){ try { v ? localStorage.setItem(KIOSK_KEY,'1') : localStorage.removeItem(KIOSK_KEY); } catch {} applyKiosk(v); }
let kioskHistoryTrap = false;
function onPop(){ if (kioskHistoryTrap) { history.pushState({kiosk:1}, '', location.href); } }
/* bump to 1.30 for +15% more than before */
function setViewportLock(lock, scale = 1.0) {
const vp = document.querySelector('meta[name="viewport"]');
if (!vp) return;
vp.setAttribute('content', lock
? `width=device-width, initial-scale=${scale}, maximum-scale=${scale}, user-scalable=no`
: 'width=device-width, initial-scale=1.0');
}
function applyKiosk(state){
if(state){
document.body.classList.add('kiosk-mode');
setViewportLock(true, 1.30); // ← was 1.15, now +15% more
try { if (screen.orientation && screen.orientation.lock) screen.orientation.lock('portrait').catch(()=>{}); } catch {}
try { const el=document.documentElement; if (!document.fullscreenElement && el.requestFullscreen) el.requestFullscreen().catch(()=>{}); } catch {}
kioskHistoryTrap = true;
try { history.pushState({kiosk:1}, '', location.href); } catch {}
window.addEventListener('popstate', onPop);
window.scrollTo(0,0);
} else {
document.body.classList.remove('kiosk-mode');
setViewportLock(false);
kioskHistoryTrap = false;
window.removeEventListener('popstate', onPop);
try { if (document.fullscreenElement && document.exitFullscreen) document.exitFullscreen().catch(()=>{}); } catch {}
}
syncFabVisibility();
applySidebarVisibility();
applyStudentFlowLayout();
}
function syncFabVisibility(){
const onSurvey = !document.getElementById('surveyPage').classList.contains('hidden');
const tokenMode = !!(new URLSearchParams(location.search).get('t') || new URLSearchParams(location.search).get('token'));
const kioskActive = isKiosk();
if (kioskEnterBtn) kioskEnterBtn.style.display = (!tokenMode && onSurvey && !kioskActive) ? '' : 'none';
}
kioskEnterBtn?.addEventListener('click', ()=> setKiosk(true));
function fsChangeHandler(){
if (isKiosk() && !document.fullscreenElement) {
setKiosk(false);
}
}
document.addEventListener('fullscreenchange', fsChangeHandler);
document.addEventListener('webkitfullscreenchange', fsChangeHandler);
// 5-tap exit