Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
1252 lines (1130 loc) · 74.5 KB
/
Copy pathindex.html
File metadata and controls
1252 lines (1130 loc) · 74.5 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">
<title>SIMPL Assessment Module Builder</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="https://unpkg.com/mammoth@1.6.0/mammoth.browser.min.js"></script>
<style>
:root {
--primary: #1a5f7a;
--primary-light: #2980b9;
--primary-bg: #eaf4fb;
--accent: #e67e22;
--accent-bg: #fff4ea;
--success: #27ae60;
--danger: #c0392b;
--danger-light: #fadbd8;
--purple: #7d3c98;
--purple-bg: #f5eef8;
--gray-100: #f8f9fa;
--gray-200: #e9ecef;
--gray-300: #dee2e6;
--gray-500: #6c757d;
--gray-700: #495057;
--gray-900: #212529;
--radius: 8px;
--shadow: 0 2px 8px rgba(0,0,0,0.08);
--shadow-lg: 0 4px 20px rgba(0,0,0,0.14);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f0f4f8; color: var(--gray-900); min-height: 100vh; }
/* ── Top Bar ─────────────────────────── */
.top-bar { background: var(--primary); color: white; padding: 14px 28px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow-lg); position: sticky; top: 0; z-index: 200; }
.top-bar .logo { font-size: 21px; font-weight: 700; letter-spacing: .5px; }
.top-bar .subtitle { font-size: 13px; opacity: .75; margin-left: 4px; }
.top-bar .export-btn { margin-left: auto; background: white; color: var(--primary); border: none; padding: 9px 20px; border-radius: 6px; font-weight: 600; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 7px; transition: all .2s; }
.top-bar .export-btn:hover { background: var(--primary-bg); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.top-bar .upload-btn { background: rgba(255,255,255,.15); color: white; border: 1.5px solid rgba(255,255,255,.4); padding: 9px 18px; border-radius: 6px; font-weight: 600; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 7px; transition: all .2s; }
.top-bar .upload-btn:hover { background: rgba(255,255,255,.25); border-color: white; }
#templateFileInput { display: none; }
/* Upload success banner */
.upload-banner { background: #d5f5e3; border: 1.5px solid #27ae60; color: #1e8449; padding: 12px 18px; border-radius: var(--radius); margin-bottom: 18px; font-size: 13px; font-weight: 600; display: none; align-items: center; gap: 10px; }
.upload-banner.show { display: flex; }
.upload-banner .ub-close { margin-left: auto; background: none; border: none; font-size: 16px; color: #1e8449; cursor: pointer; }
.container { max-width: 940px; margin: 0 auto; padding: 28px 18px; }
/* ── Step Tabs ───────────────────────── */
.steps-nav { display: flex; background: white; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 28px; }
.step-tab { flex: 1; padding: 13px 10px; text-align: center; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--gray-500); background: white; border: none; border-bottom: 3px solid transparent; transition: all .2s; }
.step-tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--primary-bg); font-weight: 600; }
.step-tab.completed { color: var(--success); border-bottom-color: var(--success); }
.step-tab.hidden-tab { display: none; }
.step-tab .sn { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--gray-200); color: var(--gray-500); font-size: 10px; font-weight: 700; margin-right: 5px; }
.step-tab.active .sn { background: var(--primary); color: white; }
.step-tab.completed .sn { background: var(--success); color: white; }
/* ── Sections ───────────────────────── */
.section { display: none; }
.section.active { display: block; }
/* ── Cards ───────────────────────────── */
.card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; margin-bottom: 18px; }
.card-title { font-size: 17px; font-weight: 700; color: var(--primary); margin-bottom: 5px; }
.card-desc { font-size: 13px; color: var(--gray-500); margin-bottom: 22px; line-height: 1.55; }
/* ── Mode Toggle ─────────────────────── */
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 26px; }
.mode-option { border: 2px solid var(--gray-300); border-radius: 10px; padding: 16px 18px; cursor: pointer; transition: all .2s; background: white; text-align: left; }
.mode-option:hover { border-color: var(--primary-light); background: var(--primary-bg); }
.mode-option.selected { border-color: var(--primary); background: var(--primary-bg); }
.mode-option .mo-icon { font-size: 22px; margin-bottom: 8px; }
.mode-option .mo-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; color: var(--gray-900); }
.mode-option .mo-desc { font-size: 12px; color: var(--gray-500); line-height: 1.45; }
.mode-option.selected .mo-title { color: var(--primary); }
.mode-check { display: none; width: 20px; height: 20px; border-radius: 50%; background: var(--primary); color: white; font-size: 11px; align-items: center; justify-content: center; float: right; margin-top: -4px; }
.mode-option.selected .mode-check { display: flex; }
/* ── Form Fields ─────────────────────── */
.fg { margin-bottom: 16px; }
.fg:last-child { margin-bottom: 0; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--gray-700); margin-bottom: 5px; }
label .req { color: var(--danger); margin-left: 2px; }
label .hint { font-weight: 400; color: var(--gray-500); font-size: 11.5px; margin-left: 5px; }
input[type="text"], textarea, select { width: 100%; padding: 9px 13px; border: 1.5px solid var(--gray-300); border-radius: 6px; font-size: 13.5px; font-family: inherit; color: var(--gray-900); transition: border-color .2s, box-shadow .2s; background: white; }
input[type="text"]:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(41,128,185,.12); }
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
@media(max-width:600px) { .two-col,.three-col { grid-template-columns: 1fr; } }
/* ── Shared: Activities (single-instrument mode) ── */
.act-list { display: flex; flex-direction: column; gap: 8px; }
.act-item { display: flex; align-items: center; gap: 9px; background: var(--gray-100); border: 1.5px solid var(--gray-200); border-radius: 6px; padding: 9px 12px; transition: border-color .2s; }
.act-item:focus-within { border-color: var(--primary-light); background: var(--primary-bg); }
.act-item .drag-h { color: var(--gray-300); font-size: 16px; flex-shrink: 0; cursor: grab; }
.act-item input { flex: 1; border: none; background: transparent; padding: 3px 0; font-size: 13.5px; }
.act-item input:focus { outline: none; box-shadow: none; }
/* Activity with extra fields (multi-instrument mode) */
.act-row { background: var(--gray-100); border: 1.5px solid var(--gray-200); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; transition: border-color .2s; }
.act-row:focus-within { border-color: var(--primary-light); background: var(--primary-bg); }
.act-row-top { display: flex; align-items: center; gap: 9px; }
.act-row-top input { flex: 1; border: none; background: transparent; padding: 3px 0; font-size: 13.5px; }
.act-row-top input:focus { outline: none; box-shadow: none; }
.act-row-extras { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
@media(max-width:600px) { .act-row-extras { grid-template-columns: 1fr; } }
.act-row-extras input { font-size: 12px; padding: 6px 10px; color: var(--gray-500); }
/* ── Shared: Buttons ─────────────────── */
.rm-btn { background: none; border: none; color: var(--gray-300); cursor: pointer; font-size: 16px; padding: 2px 5px; border-radius: 4px; transition: color .2s, background .2s; line-height: 1; flex-shrink: 0; }
.rm-btn:hover { color: var(--danger); background: var(--danger-light); }
.add-btn { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 10px; padding: 9px 16px; background: var(--primary-bg); color: var(--primary); border: 1.5px dashed var(--primary-light); border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; width: 100%; transition: all .2s; }
.add-btn:hover { background: #cde8f7; border-style: solid; }
.add-btn.lib { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.add-btn.lib:hover { background: #fde3c1; border-style: solid; }
.add-btn.purple { background: var(--purple-bg); color: var(--purple); border-color: var(--purple); }
.add-btn.purple:hover { background: #eadaf5; border-style: solid; }
/* ── Questions ───────────────────────── */
.q-add-row { display: flex; gap: 10px; margin-top: 12px; }
.q-add-row .add-btn { flex: 1; margin-top: 0; }
.q-card { background: white; border: 1.5px solid var(--gray-200); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; box-shadow: var(--shadow); }
.q-card.from-lib { border-left: 4px solid var(--accent); }
.q-hdr { display: flex; align-items: center; gap: 10px; padding: 12px 15px; background: var(--gray-100); border-bottom: 1px solid var(--gray-200); cursor: pointer; user-select: none; }
.q-hdr:hover { background: var(--primary-bg); }
.qn { width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: white; font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.q-label { font-weight: 600; font-size: 13px; flex: 1; color: var(--gray-700); }
.q-badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--primary-bg); color: var(--primary); }
.q-badge.lib { background: var(--accent-bg); color: #a04000; }
.q-body { padding: 16px 15px; }
.opts-section { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--gray-300); }
.opts-label { font-size: 12.5px; font-weight: 600; color: var(--gray-700); margin-bottom: 8px; }
.opt-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.opt-num { width: 20px; height: 32px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: var(--gray-500); flex-shrink: 0; }
.opt-fields { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.opt-fields input { font-size: 12.5px; padding: 6px 10px; }
.opt-fields input:last-child { font-size: 11.5px; color: var(--gray-500); }
.toggle-row { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.toggle-row label { margin-bottom: 0; font-size: 12.5px; }
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.tog-sl { position: absolute; cursor: pointer; top:0; left:0; right:0; bottom:0; background: var(--gray-300); border-radius: 22px; transition: .2s; }
.tog-sl:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked + .tog-sl { background: var(--primary); }
.toggle input:checked + .tog-sl:before { transform: translateX(18px); }
/* ── Multi-Instrument Cards ───────────── */
.inst-card { border: 2px solid var(--gray-200); border-radius: 10px; margin-bottom: 18px; overflow: hidden; box-shadow: var(--shadow); background: white; }
.inst-hdr { display: flex; align-items: center; gap: 12px; padding: 14px 18px; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%); color: white; cursor: pointer; user-select: none; }
.inst-hdr:hover { opacity: .95; }
.inst-num { width: 30px; height: 30px; border-radius: 50%; background: rgba(255,255,255,.25); color: white; font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.inst-title-display { font-weight: 700; font-size: 14px; flex: 1; }
.inst-toggle-icon { font-size: 12px; opacity: .8; }
.inst-rm-btn { background: rgba(255,255,255,.15); border: none; color: rgba(255,255,255,.9); cursor: pointer; font-size: 14px; padding: 4px 8px; border-radius: 4px; transition: background .2s; }
.inst-rm-btn:hover { background: rgba(255,0,0,.3); }
.inst-body { padding: 20px 18px; }
.inst-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding-bottom: 18px; border-bottom: 1px solid var(--gray-200); margin-bottom: 18px; }
@media(max-width:600px) { .inst-meta { grid-template-columns: 1fr; } }
.subsection-title { font-size: 13px; font-weight: 700; color: var(--gray-700); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.subsection-title .badge { font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 20px; background: var(--gray-200); color: var(--gray-500); }
.subsection { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px dashed var(--gray-200); }
.subsection:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
/* ── Nav buttons ─────────────────────── */
.nav-btns { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--gray-200); }
.btn { padding: 10px 24px; border-radius: 6px; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: all .2s; border: none; display: inline-flex; align-items: center; gap: 7px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1.5px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-success { background: var(--success); color: white; font-size: 14.5px; padding: 12px 30px; }
.btn-success:hover { background: #219a52; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(39,174,96,.3); }
/* ── Info Banner ─────────────────────── */
.info { background: var(--primary-bg); border-left: 4px solid var(--primary); padding: 11px 15px; border-radius: 0 6px 6px 0; font-size: 12.5px; color: var(--gray-700); margin-bottom: 18px; line-height: 1.55; }
.info.orange { background: var(--accent-bg); border-left-color: var(--accent); }
/* ── Preview table ───────────────────── */
.preview-card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 18px; }
.preview-hdr { background: var(--primary); color: white; padding: 14px 22px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; font-size: 14px; }
.preview-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
th { background: var(--gray-100); padding: 8px 12px; text-align: left; font-size: 10px; font-weight: 700; color: var(--gray-500); text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--gray-300); white-space: nowrap; }
td { padding: 7px 12px; border-bottom: 1px solid var(--gray-200); vertical-align: top; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:hover td { background: var(--gray-100); }
.tp { display: inline-block; padding: 2px 7px; border-radius: 20px; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.tp-instrument { background:#d5f5e3; color:#1e8449; }
.tp-assessment { background:#d6eaf8; color:#1a5276; }
.tp-activity { background:#fef9e7; color:#9a7d0a; }
.tp-question { background:#fdebd0; color:#a04000; }
.tp-answeroption { background:#f9ebea; color:#922b21; }
/* ── Library Modal ───────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 500; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 830px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-hdr { background: var(--primary); color: white; padding: 15px 22px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-hdr h2 { font-size: 15px; font-weight: 700; }
.modal-close { background: rgba(255,255,255,.2); border: none; color: white; width: 28px; height: 28px; border-radius: 50%; font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background .2s; }
.modal-close:hover { background: rgba(255,255,255,.35); }
.modal-sub { padding: 14px 22px 0; flex-shrink: 0; }
.modal-sub p { font-size: 12.5px; color: var(--gray-500); margin-bottom: 10px; }
.lib-filters { display: flex; gap: 7px; flex-wrap: wrap; }
.f-chip { padding: 4px 12px; border-radius: 20px; font-size: 11.5px; font-weight: 600; border: 1.5px solid var(--gray-300); background: white; color: var(--gray-500); cursor: pointer; transition: all .2s; }
.f-chip.active { background: var(--primary); color: white; border-color: var(--primary); }
.modal-body { padding: 14px 22px 22px; overflow-y: auto; }
.lib-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
@media(max-width:600px) { .lib-grid { grid-template-columns: 1fr; } }
.lib-card { border: 1.5px solid var(--gray-200); border-radius: 8px; padding: 13px 15px; cursor: pointer; transition: all .2s; position: relative; background: white; }
.lib-card:hover { border-color: var(--primary-light); box-shadow: 0 3px 12px rgba(41,128,185,.15); transform: translateY(-1px); }
.lib-card.selected { border-color: var(--primary); background: var(--primary-bg); }
.lc-name { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.lc-prompt { font-size: 11.5px; color: var(--gray-500); margin-bottom: 8px; line-height: 1.4; }
.lc-opts { display: flex; flex-wrap: wrap; gap: 3px; }
.lc-opt { font-size: 10px; padding: 2px 7px; border-radius: 20px; background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); }
.lc-type { position: absolute; top: 9px; right: 9px; font-size: 9.5px; font-weight: 700; padding: 2px 7px; border-radius: 20px; background: var(--primary-bg); color: var(--primary); }
.lc-type.fb { background: var(--accent-bg); color: #a04000; }
.lc-check { position: absolute; top: 9px; right: 9px; width: 18px; height: 18px; border-radius: 50%; background: var(--primary); color: white; font-size: 10px; display: none; align-items: center; justify-content: center; }
.lib-card.selected .lc-type { display: none; }
.lib-card.selected .lc-check { display: flex; }
.modal-ftr { padding: 13px 22px; border-top: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; background: var(--gray-100); }
.modal-ftr .sc { font-size: 12.5px; color: var(--gray-500); }
.modal-ftr .sc strong { color: var(--primary); }
/* ── Toast ───────────────────────────── */
.toast { position: fixed; bottom: 28px; right: 28px; background: var(--success); color: white; padding: 12px 20px; border-radius: 8px; font-weight: 600; font-size: 13px; box-shadow: var(--shadow-lg); display: none; align-items: center; gap: 8px; z-index: 1000; }
.toast.show { display: flex; animation: slideIn .3s ease; }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
</style>
</head>
<body>
<!-- Top Bar -->
<div class="top-bar">
<div>
<div class="logo">SIMPL</div>
<div class="subtitle">Assessment Module Builder</div>
</div>
<button class="upload-btn" onclick="document.getElementById('templateFileInput').click()">📂 Upload Template</button>
<input type="file" id="templateFileInput" accept=".xlsx,.docx" onchange="handleTemplateUpload(event)" />
<button class="export-btn" onclick="exportCSV()">⬇ Download CSV</button>
</div>
<!-- Library Modal -->
<div class="modal-overlay" id="libraryModal">
<div class="modal">
<div class="modal-hdr">
<h2>📚 Standard Question Library</h2>
<button class="modal-close" onclick="closeLibrary()">✕</button>
</div>
<div class="modal-sub">
<p>Select one or more constructs to add. You can edit them after adding.</p>
<div class="lib-filters" id="libFilters">
<button class="f-chip active" onclick="filterLib('all',this)">All</button>
<button class="f-chip" onclick="filterLib('Radio',this)">Radio</button>
<button class="f-chip" onclick="filterLib('Feedback',this)">Feedback</button>
</div>
</div>
<div class="modal-body"><div class="lib-grid" id="libGrid"></div></div>
<div class="modal-ftr">
<span class="sc">Selected: <strong id="selCount">0</strong></span>
<div style="display:flex;gap:10px;">
<button class="btn btn-secondary" onclick="closeLibrary()">Cancel</button>
<button class="btn btn-primary" onclick="addFromLibrary()">+ Add Selected</button>
</div>
</div>
</div>
</div>
<div class="container">
<!-- Upload success banner -->
<div class="upload-banner" id="uploadBanner">
✓ <span id="uploadBannerText">Template loaded successfully.</span>
<button class="ub-close" onclick="document.getElementById('uploadBanner').classList.remove('show')">✕</button>
</div>
<!-- Steps Nav -->
<div class="steps-nav">
<button class="step-tab active" onclick="goToStep(1)" id="tab-1"><span class="sn">1</span> Module Setup</button>
<button class="step-tab" onclick="goToStep(2)" id="tab-2"><span class="sn">2</span> <span id="tab2-label">Activities</span></button>
<button class="step-tab" onclick="goToStep(3)" id="tab-3"><span class="sn">3</span> Questions</button>
<button class="step-tab" onclick="goToStep(4)" id="tab-4"><span class="sn">4</span> Preview & Export</button>
</div>
<!-- ═══════════════════════════════════════════════ -->
<!-- STEP 1: Module Setup -->
<!-- ═══════════════════════════════════════════════ -->
<div class="section active" id="step-1">
<div class="card">
<div class="card-title">📋 Module Setup</div>
<div class="card-desc">Choose how your module is structured, then fill in the top-level details.</div>
<div class="mode-toggle">
<button class="mode-option selected" id="mode-single" onclick="setMode('single')">
<span class="mode-check">✓</span>
<div class="mo-icon">📄</div>
<div class="mo-title">Single Instrument</div>
<div class="mo-desc">All activities share the same instrument — one set of questions applies to every activity.</div>
</button>
<button class="mode-option" id="mode-multi" onclick="setMode('multi')">
<span class="mode-check">✓</span>
<div class="mo-icon">📂</div>
<div class="mo-title">Multiple Instruments</div>
<div class="mo-desc">Activities are grouped into instrument blocks, each with its own questions and constructs.</div>
</button>
</div>
<!-- Single-instrument fields -->
<div id="single-fields">
<div class="fg">
<label>Instrument Title <span class="req">*</span></label>
<input type="text" id="instrumentTitle" placeholder="e.g., Zwisch Bedside Evaluation" />
</div>
<div class="fg">
<label>Assessment Title <span class="req">*</span> <span class="hint">The name of this specific assessment</span></label>
<input type="text" id="assessmentTitle" placeholder="e.g., SIMPL Bedside Assessment" />
</div>
</div>
<!-- Multi-instrument note (no global fields needed) -->
<div id="multi-fields" style="display:none;">
<div class="info orange">📂 In multiple-instrument mode, each instrument block has its own title, description, activities, and questions. You'll define all of these in the next step.</div>
</div>
</div>
<div class="nav-btns">
<div></div>
<button class="btn btn-primary" onclick="goToStep(2)" id="step1-next">Next: Activities →</button>
</div>
</div>
<!-- ═══════════════════════════════════════════════ -->
<!-- STEP 2a: Activities (single-instrument mode) -->
<!-- ═══════════════════════════════════════════════ -->
<div class="section" id="step-2-single">
<div class="card">
<div class="card-title">🏥 Activities</div>
<div class="card-desc">Add each procedure or activity that trainees can be evaluated on. These will all share the same set of questions.</div>
<div class="info">💡 Enter one activity per line. Optionally add a <strong>category tag</strong> (e.g., "Primary Care Clinic") to each activity — leave blank if not needed.</div>
<div class="act-list" id="activitiesList"></div>
<button class="add-btn" onclick="addActivity()">+ Add Activity</button>
</div>
<div class="nav-btns">
<button class="btn btn-secondary" onclick="goToStep(1)">← Back</button>
<button class="btn btn-primary" onclick="goToStep(3)">Next: Questions →</button>
</div>
</div>
<!-- ═══════════════════════════════════════════════ -->
<!-- STEP 2b: Instruments (multi-instrument mode) -->
<!-- ═══════════════════════════════════════════════ -->
<div class="section" id="step-2-multi">
<div class="card">
<div class="card-title">📂 Instrument Groups</div>
<div class="card-desc">Each instrument block contains its own activities and questions. Add one block per instrument.</div>
<div class="info orange">💡 Each instrument can have a <strong>title</strong>, <strong>description</strong>, a list of <strong>activities</strong> (with optional descriptions and category tags), and its own <strong>questions</strong> with answer options.</div>
</div>
<div id="instList"></div>
<button class="add-btn purple" onclick="addInstrument()">+ Add Instrument Block</button>
<div class="nav-btns">
<button class="btn btn-secondary" onclick="goToStep(1)">← Back</button>
<button class="btn btn-primary" onclick="goToStep(4)">Preview & Export →</button>
</div>
</div>
<!-- ═══════════════════════════════════════════════ -->
<!-- STEP 3: Questions (single-instrument mode only) -->
<!-- ═══════════════════════════════════════════════ -->
<div class="section" id="step-3">
<div class="card">
<div class="card-title">❓ Questions</div>
<div class="card-desc">These questions apply to every activity in this module. Add from the standard library or create custom questions.</div>
<div class="info">💡 <strong>Library questions</strong> come pre-filled with standard prompts and answer options. <strong>Custom questions</strong> start blank.</div>
<div id="questionsList"></div>
<div class="q-add-row">
<button class="add-btn lib" onclick="openLibrary('main')">📚 Add from Library</button>
<button class="add-btn" onclick="addQuestion('main')">✏️ Add Custom Question</button>
</div>
</div>
<div class="nav-btns">
<button class="btn btn-secondary" onclick="goToStep(2)">← Back</button>
<button class="btn btn-primary" onclick="goToStep(4)">Preview & Export →</button>
</div>
</div>
<!-- ═══════════════════════════════════════════════ -->
<!-- STEP 4: Preview & Export -->
<!-- ═══════════════════════════════════════════════ -->
<div class="section" id="step-4">
<div class="preview-card">
<div class="preview-hdr">
<span>📄 CSV Preview</span>
<span style="font-size:11px;opacity:.8;" id="rowCount"></span>
</div>
<div class="preview-wrap">
<table>
<thead><tr id="previewHead"></tr></thead>
<tbody id="previewBody"></tbody>
</table>
</div>
</div>
<div style="text-align:center;margin-top:8px;">
<button class="btn btn-success" onclick="exportCSV()">⬇ Download CSV for Upload</button>
</div>
<div class="nav-btns">
<button class="btn btn-secondary" id="preview-back-btn" onclick="goToStep(3)">← Back to Questions</button>
<div></div>
</div>
</div>
</div>
<div class="toast" id="toast">✓ CSV downloaded successfully!</div>
<script>
// ═══════════════════════════════════════════════════════════
// QUESTION LIBRARY
// ═══════════════════════════════════════════════════════════
const LIBRARY = [
{ id:'complexity', name:'Complexity', type:'Radio', prompt:'How complex was the case relative to similar procedures?', selfPrompt:'How complex was the procedure relative to similar procedures?', helpText:'', required:true, options:[{anchor:'Easiest',help:''},{anchor:'Average',help:''},{anchor:'Hardest',help:''}] },
{ id:'guidance', name:'Guidance / Autonomy', type:'Radio', prompt:'How much guidance did you provide for the majority of the critical portion of this procedure?', selfPrompt:'How much guidance did you receive for the majority of the critical portion of this procedure?', helpText:'', required:true, options:[{anchor:'Show & Tell',help:''},{anchor:'Active Help',help:''},{anchor:'Passive Help',help:''},{anchor:'Supervision Only',help:''}] },
{ id:'performance', name:'Performance', type:'Radio', prompt:"What was this trainee's performance for the majority of the critical portion of this procedure?", selfPrompt:'Please rate your performance for the majority of the critical portion of this procedure:', helpText:'', required:true, options:[{anchor:'Unprepared/Critical Deficiency',help:'Demonstrated significant gaps in preparation and execution for this procedure, with performance issues that required close supervision to support patient safety and procedural success.'},{anchor:'Inexperienced w/ Procedure',help:'Trainee is in an early stage of development with this procedure and would benefit from additional practice and guidance to improve technique, efficiency, and anticipatory planning.'},{anchor:'Intermediate Performance',help:"Performance reflects an intermediate stage of development. Procedural elements are generally appropriate for the trainee's level of experience, with some variability."},{anchor:'Practice-Ready Performance',help:'Trainee is ready to perform this operation safely, effectively and independently.'},{anchor:'Exceptional Performance',help:'An exceptional performance that exceeds the level typically expected of graduating trainees.'}] },
{ id:'supervision', name:'Supervision', type:'Radio', prompt:'How much supervision did the trainee need when performing this activity?', selfPrompt:'How much supervision did you need when performing this activity?', helpText:'', required:true, options:[{anchor:'SUPERVISOR PERFORMED: Resident was an observer',help:''},{anchor:'SUPERVISOR LED CARE: Required supervising physician(s) to direct the majority of the care',help:''},{anchor:'SUPERVISOR AND RESIDENT CO-LED CARE: Required supervising physician(s) to direct some aspects of the care',help:''},{anchor:'RESIDENT LED CARE WITH MINIMAL SUPERVISION NEEDED: Resident directed care, supervision only led to small adjustments in care',help:''},{anchor:'RESIDENT LED CARE WITHOUT SUPERVISION NEEDED: May benefit from continued learning and growth; however, care would have been safe and effective without a supervisor',help:'Checking this box does not imply that supervision did not occur as all trainees are supervised in training.'}] },
{ id:'entrustability', name:'Entrustability', type:'Radio', prompt:'Based on this performance, I would entrust the trainee at this level for the next similar case:', selfPrompt:'', helpText:'', required:true, options:[{anchor:'Limited participation',help:''},{anchor:'Direct supervision',help:''},{anchor:'Indirect supervision',help:''},{anchor:'Practice ready',help:''}] },
{ id:'involvement', name:'Involvement Rating', type:'Radio', prompt:'What was your involvement with the EPA?', selfPrompt:'', helpText:'', required:true, options:[{anchor:'I had to do it',help:''},{anchor:'I helped a lot',help:''},{anchor:'I helped a little',help:''},{anchor:'I needed to be there but did not help',help:''},{anchor:"I didn't need to be there at all",help:''}] },
{ id:'sup-entrustment', name:'Supervision-Entrustment', type:'Radio', prompt:'To what extent can the trainee be trusted to perform this activity?', selfPrompt:'', helpText:'', required:true, options:[{anchor:'Trust to observe or assist',help:''},{anchor:'Trust with direct supervision',help:''},{anchor:'Trust with indirect supervision for most simple and some complex situations',help:''},{anchor:'Trust without supervision for all situations; needs coaching to supervise others effectively',help:''},{anchor:'Trust without supervision for all situations; also trusted to supervise others',help:''}] },
{ id:'practice-readiness', name:'Practice Readiness', type:'Radio', prompt:'Do you believe this resident would be able to perform this activity without supervision if they were to enter general practice today?', selfPrompt:'Do you believe you would be able to perform this activity without supervision if you were to enter general practice today?', helpText:'', required:true, options:[{anchor:'Yes',help:''},{anchor:'Not Yet',help:''}] },
{ id:'observations', name:'Number of Observations', type:'Radio', prompt:'How many times did you observe this on your shift prior to providing your ratings?', selfPrompt:'', helpText:'', required:true, options:[{anchor:'1',help:''},{anchor:'2',help:''},{anchor:'3+',help:''}] },
{ id:'feedback-general', name:'Narrative Feedback — General', type:'Feedback', prompt:'When performing this activity, what does the trainee do well and how can the trainee improve?', selfPrompt:'Please reflect on what you did well that you should continue doing, and what you should do differently when next caring for a similar patient.', helpText:'', required:true, options:[] },
{ id:'feedback-nextsteps', name:'Narrative Feedback — Next Steps', type:'Feedback', prompt:'What goals do you have for the trainee to make further progress on this EPA during their next shift? Please be specific.', selfPrompt:'', helpText:'', required:true, options:[] },
];
// ═══════════════════════════════════════════════════════════
// STATE
// ═══════════════════════════════════════════════════════════
let currentMode = 'single';
let qCount = 0;
let instCount = 0;
let libSelected = new Set();
let libTarget = null; // DOM container to inject questions into
let libFilter = 'all';
// ═══════════════════════════════════════════════════════════
// MODE SWITCHING
// ═══════════════════════════════════════════════════════════
function setMode(mode) {
currentMode = mode;
document.getElementById('mode-single').classList.toggle('selected', mode === 'single');
document.getElementById('mode-multi').classList.toggle('selected', mode === 'multi');
document.getElementById('single-fields').style.display = mode === 'single' ? '' : 'none';
document.getElementById('multi-fields').style.display = mode === 'multi' ? '' : 'none';
// Update step labels and visibility
if (mode === 'single') {
document.getElementById('tab2-label').textContent = 'Activities';
document.getElementById('tab-3').classList.remove('hidden-tab');
document.getElementById('step1-next').textContent = 'Next: Activities →';
document.getElementById('preview-back-btn').setAttribute('onclick', 'goToStep(3)');
document.getElementById('preview-back-btn').textContent = '← Back to Questions';
} else {
document.getElementById('tab2-label').textContent = 'Instruments';
document.getElementById('tab-3').classList.add('hidden-tab');
document.getElementById('step1-next').textContent = 'Next: Instruments →';
document.getElementById('preview-back-btn').setAttribute('onclick', 'goToStep(2)');
document.getElementById('preview-back-btn').textContent = '← Back to Instruments';
}
}
// ═══════════════════════════════════════════════════════════
// NAVIGATION
// ═══════════════════════════════════════════════════════════
function goToStep(n) {
// Resolve which physical section to show for step 2
document.querySelectorAll('.section').forEach(s => s.classList.remove('active'));
document.querySelectorAll('.step-tab').forEach(t => t.classList.remove('active'));
if (n === 2) {
document.getElementById(currentMode === 'single' ? 'step-2-single' : 'step-2-multi').classList.add('active');
} else {
document.getElementById('step-' + n).classList.add('active');
}
document.getElementById('tab-' + n).classList.add('active');
// Mark previous steps completed
const tabs = currentMode === 'single' ? [1,2,3,4] : [1,2,4];
tabs.forEach(i => { if (i < n) document.getElementById('tab-' + i).classList.add('completed'); });
if (n === 4) buildPreview();
window.scrollTo({ top: 0, behavior: 'smooth' });
}
// ═══════════════════════════════════════════════════════════
// SINGLE MODE: ACTIVITIES
// ═══════════════════════════════════════════════════════════
function addActivity(val = '', tag = '') {
const list = document.getElementById('activitiesList');
const div = document.createElement('div');
div.className = 'act-row';
div.innerHTML = `
<div class="act-row-top">
<span class="drag-h">⋮⋮</span>
<input type="text" placeholder="Activity name (e.g., Chest Tube Placement)" value="${esc(val)}" style="flex:1;border:none;background:transparent;padding:3px 0;font-size:13.5px;" />
<button class="rm-btn" onclick="this.closest('.act-row').remove()" title="Remove">✕</button>
</div>
<div style="margin-top:7px;padding-left:26px;">
<input type="text" placeholder="Category tag (optional — e.g., Primary Care Clinic)" value="${esc(tag)}" style="font-size:12px;padding:6px 10px;color:var(--gray-500);" />
</div>
`;
list.appendChild(div);
}
// ═══════════════════════════════════════════════════════════
// MULTI MODE: INSTRUMENTS
// ═══════════════════════════════════════════════════════════
function addInstrument() {
instCount++;
const n = instCount;
const list = document.getElementById('instList');
const num = list.children.length + 1;
const div = document.createElement('div');
div.className = 'inst-card';
div.id = 'inst-' + n;
div.innerHTML = `
<div class="inst-hdr" onclick="toggleInst(${n})">
<div class="inst-num">${num}</div>
<div class="inst-title-display" id="inst-title-display-${n}">New Instrument</div>
<span class="inst-toggle-icon" id="inst-tog-${n}">▲</span>
<button class="inst-rm-btn" onclick="event.stopPropagation();document.getElementById('inst-${n}').remove();renumberInsts()" title="Remove instrument">✕</button>
</div>
<div class="inst-body" id="inst-body-${n}">
<div class="inst-meta">
<div class="fg" style="margin:0">
<label>Instrument Title <span class="req">*</span></label>
<input type="text" id="inst-title-${n}" placeholder="e.g., Assess and manage a patient" oninput="updateInstTitle(${n})" />
</div>
<div class="fg" style="margin:0">
<label>Instrument Description <span class="hint">Usually same as title; shown in system</span></label>
<input type="text" id="inst-desc-${n}" placeholder="Same as title, or a fuller description" />
</div>
</div>
<div class="subsection">
<div class="subsection-title">🏥 Activities <span class="badge" id="inst-act-count-${n}">0</span></div>
<div class="info" style="margin-bottom:12px;font-size:11.5px;">Each activity can have an optional <em>description</em> and <em>category tag</em> (e.g., "Primary Care Clinic").</div>
<div id="inst-acts-${n}"></div>
<button class="add-btn" style="font-size:12px;padding:8px 12px;" onclick="addInstActivity(${n})">+ Add Activity</button>
</div>
<div class="subsection">
<div class="subsection-title">❓ Questions <span class="badge" id="inst-q-count-${n}">0</span></div>
<div id="inst-qs-${n}"></div>
<div class="q-add-row">
<button class="add-btn lib" style="font-size:12px;padding:8px 12px;" onclick="openLibrary('inst-${n}')">📚 Add from Library</button>
<button class="add-btn" style="font-size:12px;padding:8px 12px;" onclick="addQuestion('inst-${n}')">✏️ Add Custom</button>
</div>
</div>
</div>
`;
list.appendChild(div);
}
function toggleInst(n) {
const body = document.getElementById('inst-body-' + n);
const tog = document.getElementById('inst-tog-' + n);
const collapsed = body.style.display === 'none';
body.style.display = collapsed ? '' : 'none';
tog.textContent = collapsed ? '▲' : '▼';
}
function updateInstTitle(n) {
const v = document.getElementById('inst-title-' + n).value;
document.getElementById('inst-title-display-' + n).textContent = v || 'New Instrument';
// Auto-fill description if empty
const descEl = document.getElementById('inst-desc-' + n);
if (!descEl.dataset.edited) descEl.placeholder = v || 'Same as title, or a fuller description';
}
function renumberInsts() {
document.querySelectorAll('.inst-card .inst-num').forEach((el, i) => { el.textContent = i + 1; });
}
function addInstActivity(instN, title = '', desc = '', tag = '') {
const container = document.getElementById('inst-acts-' + instN);
const div = document.createElement('div');
div.className = 'act-row';
div.innerHTML = `
<div class="act-row-top">
<span class="drag-h">⋮⋮</span>
<input type="text" placeholder="Activity title" value="${esc(title)}" style="flex:1;border:none;background:transparent;padding:3px 0;font-size:13.5px;" oninput="this.style.outline='none'" />
<button class="rm-btn" onclick="this.closest('.act-row').remove();updateInstCounts(${instN})" title="Remove">✕</button>
</div>
<div class="act-row-extras">
<input type="text" placeholder="Description (optional — often same as title)" value="${esc(desc)}" />
<input type="text" placeholder="Category tag (optional — e.g., Primary Care Clinic)" value="${esc(tag)}" />
</div>
`;
container.appendChild(div);
updateInstCounts(instN);
}
function updateInstCounts(instN) {
const acts = document.getElementById('inst-acts-' + instN).querySelectorAll('.act-row').length;
const qs = document.getElementById('inst-qs-' + instN).querySelectorAll('.q-card').length;
document.getElementById('inst-act-count-' + instN).textContent = acts;
document.getElementById('inst-q-count-' + instN).textContent = qs;
}
// ═══════════════════════════════════════════════════════════
// QUESTIONS (shared logic for both modes)
// ═══════════════════════════════════════════════════════════
function addQuestion(targetKey, template = null) {
qCount++;
const id = qCount;
const container = getQContainer(targetKey);
if (!container) return;
const num = container.querySelectorAll('.q-card').length + 1;
const isLib = template !== null;
const title = template ? template.name : '';
const type = template ? template.type : 'Radio';
const prompt = template ? template.prompt : '';
const selfP = template ? template.selfPrompt : '';
const helpT = template ? template.helpText : '';
const req = template ? template.required : true;
const div = document.createElement('div');
div.className = 'q-card' + (isLib ? ' from-lib' : '');
div.id = 'q-' + id;
div.innerHTML = `
<div class="q-hdr" onclick="toggleQ(${id})">
<div class="qn">${num}</div>
<div class="q-label" id="ql-${id}">${esc(title) || 'New Question'}</div>
${isLib ? '<span style="font-size:9.5px;color:#a04000;background:#fdebd0;padding:2px 6px;border-radius:20px;font-weight:600;">Library</span>' : ''}
<span class="q-badge ${isLib ? 'lib' : ''}" id="qb-${id}">${type}</span>
<span style="color:var(--gray-500);font-size:11px;" id="qt-${id}">▲</span>
<button class="rm-btn" onclick="event.stopPropagation();document.getElementById('q-${id}').remove();renumberQsIn('${targetKey}');if('${targetKey}'.startsWith('inst-'))updateInstCounts('${targetKey}'.split('-')[1])" title="Remove">✕</button>
</div>
<div class="q-body" id="qbody-${id}">
<div class="two-col">
<div class="fg">
<label>Question Title <span class="req">*</span></label>
<input type="text" id="qtitle-${id}" placeholder="e.g., Guidance" value="${esc(title)}" oninput="updateQL(${id})" />
</div>
<div class="fg">
<label>Input Type <span class="req">*</span></label>
<select id="qtype-${id}" onchange="handleTypeChange(${id})">
<option value="Radio" ${type==='Radio'?'selected':''}>Radio (multiple choice)</option>
<option value="Feedback" ${type==='Feedback'?'selected':''}>Feedback (free text)</option>
</select>
</div>
</div>
<div class="fg">
<label>Faculty / Evaluator Prompt <span class="hint">Shown to evaluator (Col 3)</span></label>
<textarea id="qprompt-${id}" rows="2">${esc(prompt)}</textarea>
</div>
<div class="fg">
<label>Trainee / Self-Assessment Prompt <span class="hint">Shown to trainee (Col 4)</span></label>
<textarea id="qself-${id}" rows="2">${esc(selfP)}</textarea>
</div>
<div class="fg">
<label>Question Help Text <span class="hint">Optional tooltip</span></label>
<input type="text" id="qhelp-${id}" value="${esc(helpT)}" placeholder="Optional" />
</div>
<div class="toggle-row">
<label class="toggle"><input type="checkbox" id="qreq-${id}" ${req?'checked':''} /><span class="tog-sl"></span></label>
<label for="qreq-${id}" style="cursor:pointer;">Required</label>
</div>
<div class="opts-section" id="qopts-section-${id}" ${type==='Feedback'?'style="display:none"':''}>
<div class="opts-label">Answer Options</div>
<div id="qopts-${id}"></div>
<button class="add-btn" style="margin-top:7px;font-size:12px;padding:7px 12px;" onclick="addOpt(${id})">+ Add Answer Option</button>
</div>
</div>
`;
container.appendChild(div);
if (template && template.options) template.options.forEach(o => addOpt(id, o.anchor, o.help));
if (targetKey.startsWith('inst-')) updateInstCounts(targetKey.split('-')[1]);
renumberQsIn(targetKey);
}
function getQContainer(targetKey) {
if (targetKey === 'main') return document.getElementById('questionsList');
if (targetKey.startsWith('inst-')) return document.getElementById(targetKey + '-qs-' + targetKey.split('-')[1]);
return null;
}
// "inst-5" → container id "inst-qs-5"
// Let me fix the getQContainer function for instrument targets
// targetKey for instrument is "inst-{n}", container id is "inst-qs-{n}"
function toggleQ(id) {
const body = document.getElementById('qbody-' + id);
const t = document.getElementById('qt-' + id);
const hidden = body.style.display === 'none';
body.style.display = hidden ? '' : 'none';
t.textContent = hidden ? '▲' : '▼';
}
function updateQL(id) {
const v = document.getElementById('qtitle-' + id).value;
document.getElementById('ql-' + id).textContent = v || 'New Question';
}
function handleTypeChange(id) {
const type = document.getElementById('qtype-' + id).value;
document.getElementById('qb-' + id).textContent = type;
document.getElementById('qopts-section-' + id).style.display = type === 'Radio' ? '' : 'none';
}
function renumberQsIn(targetKey) {
const container = getQContainer(targetKey);
if (!container) return;
container.querySelectorAll('.q-card .qn').forEach((el, i) => { el.textContent = i + 1; });
}
function addOpt(id, anchor = '', help = '') {
const c = document.getElementById('qopts-' + id);
const idx = c.children.length + 1;
const row = document.createElement('div');
row.className = 'opt-row';
row.innerHTML = `
<div class="opt-num">${idx}</div>
<div class="opt-fields">
<input type="text" placeholder="Answer label" value="${esc(anchor)}" />
<input type="text" placeholder="Help text (optional)" value="${esc(help)}" />
</div>
<button class="rm-btn" onclick="this.parentElement.remove();renumberOpts(${id})" title="Remove">✕</button>
`;
c.appendChild(row);
}
function renumberOpts(id) {
document.getElementById('qopts-' + id).querySelectorAll('.opt-num').forEach((el, i) => { el.textContent = i + 1; });
}
// ═══════════════════════════════════════════════════════════
// LIBRARY MODAL
// ═══════════════════════════════════════════════════════════
function openLibrary(targetKey) {
libTarget = targetKey;
libSelected.clear();
renderLibGrid();
document.getElementById('selCount').textContent = '0';
document.getElementById('libraryModal').classList.add('open');
}
function closeLibrary() {
document.getElementById('libraryModal').classList.remove('open');
}
function filterLib(type, btn) {
libFilter = type;
document.querySelectorAll('.f-chip').forEach(c => c.classList.remove('active'));
btn.classList.add('active');
renderLibGrid();
}
function renderLibGrid() {
const grid = document.getElementById('libGrid');
grid.innerHTML = '';
const items = libFilter === 'all' ? LIBRARY : LIBRARY.filter(c => c.type === libFilter);
items.forEach(c => {
const div = document.createElement('div');
div.className = 'lib-card' + (libSelected.has(c.id) ? ' selected' : '');
div.onclick = () => {
if (libSelected.has(c.id)) { libSelected.delete(c.id); div.classList.remove('selected'); }
else { libSelected.add(c.id); div.classList.add('selected'); }
document.getElementById('selCount').textContent = libSelected.size;
};
const opts = c.options.slice(0,4).map(o => `<span class="lc-opt">${esc(o.anchor)}</span>`).join('');
const more = c.options.length > 4 ? `<span class="lc-opt" style="opacity:.6">+${c.options.length-4}</span>` : '';
div.innerHTML = `
<div class="lc-type ${c.type==='Feedback'?'fb':''}">${c.type}</div>
<div class="lc-check">✓</div>
<div class="lc-name">${esc(c.name)}</div>
<div class="lc-prompt">${esc(c.prompt)}</div>
${c.options.length ? `<div class="lc-opts">${opts}${more}</div>` : ''}
`;
grid.appendChild(div);
});
}
function addFromLibrary() {
if (libSelected.size > 0) {
LIBRARY.filter(c => libSelected.has(c.id)).forEach(c => addQuestion(libTarget, c));
}
closeLibrary();
}
// ═══════════════════════════════════════════════════════════
// CSV BUILD
// ═══════════════════════════════════════════════════════════
function buildRows() {
if (currentMode === 'single') return buildSingleRows();
return buildMultiRows();
}
function buildSingleRows() {
const rows = [];
const inst = (document.getElementById('instrumentTitle').value || '').trim();
const assess = (document.getElementById('assessmentTitle').value || '').trim();
// Collect activities and detect whether any have category tags
const activities = [];
document.querySelectorAll('#activitiesList .act-row').forEach(row => {
const inputs = row.querySelectorAll('input');
const title = inputs[0]?.value.trim() || '';
const tag = inputs[1]?.value.trim() || '';
if (title) activities.push({ title, tag });
});
const hasTags = activities.some(a => a.tag !== '');
if (hasTags) {
rows.push(['Type','Activity Title, Instrument Title, Question Title, AnswerOption anchor','Activity Description, Instrument Description, Question Default Prompt, AnswerOption Help Text','Question Self-assessment prompt','Question Help Text','Question input type','Required','Category Tags']);
rows.push(['Instrument', inst, '', '', '', '', '', '']);
rows.push(['Assessment', assess, '', '', '', '', '', '']);
activities.forEach(a => rows.push(['Activity', a.title, '', '', '', '', '', a.tag]));
collectQuestions('main').forEach(r => rows.push([...r, '']));
} else {
rows.push(['Type','Activity Title, Instrument Title, Question Title, AnswerOption anchor','Activity Description, Instrument Description, Question Default Prompt, AnswerOption Help Text','Question Self-assessment prompt','Question Help Text','Question input type','Required']);
rows.push(['Instrument', inst, '', '', '', '', '']);
rows.push(['Assessment', assess, '', '', '', '', '']);
activities.forEach(a => rows.push(['Activity', a.title, '', '', '', '', '']));
collectQuestions('main').forEach(r => rows.push(r));
}
return rows;
}
function buildMultiRows() {
const rows = [];
rows.push(['Type','Activity Title, Instrument Title, Question Title, Answer Option anchor','Activity Description, Instrument Description, Question Default Prompt, AnswerOption Help Text','Question Self-assessment prompt','Question Help Text','Question input type','Required','Category Tags']);
document.querySelectorAll('.inst-card').forEach(card => {
const n = card.id.replace('inst-', '');
const title = (document.getElementById('inst-title-' + n) || {}).value?.trim() || '';
const desc = (document.getElementById('inst-desc-' + n) || {}).value?.trim() || title;
rows.push(['Instrument', title, desc, '', '', '', '', '']);
// Activities
card.querySelectorAll('.act-row').forEach(row => {
const inputs = row.querySelectorAll('input');
const actTitle = inputs[0]?.value.trim() || '';
const actDesc = inputs[1]?.value.trim() || actTitle;
const actTag = inputs[2]?.value.trim() || '';
if (actTitle) rows.push(['Activity', actTitle, actDesc, '', '', '', '', actTag]);
});
// Questions
collectQuestions('inst-' + n).forEach(r => rows.push(r));
});
return rows;
}
function collectQuestions(targetKey) {
const rows = [];
const container = getQContainer(targetKey);
if (!container) return rows;
container.querySelectorAll('.q-card').forEach(qc => {
const id = qc.id.replace('q-', '');
const title = (document.getElementById('qtitle-' + id) || {}).value?.trim() || '';
const prompt = (document.getElementById('qprompt-' + id) || {}).value?.trim() || '';
const selfP = (document.getElementById('qself-' + id) || {}).value?.trim() || '';
const helpT = (document.getElementById('qhelp-' + id) || {}).value?.trim() || '';
const type = (document.getElementById('qtype-' + id) || {}).value || 'Radio';
const req = (document.getElementById('qreq-' + id) || {}).checked;
const base = currentMode === 'single' ? 7 : 8;
const qRow = ['Question', title, prompt, selfP, helpT, type, req ? 'True' : 'False'];
if (base === 8) qRow.push('');
rows.push(qRow);
const opts = document.getElementById('qopts-' + id);
if (opts) {
opts.querySelectorAll('.opt-row').forEach(row => {
const ins = row.querySelectorAll('input');
const anchor = ins[0]?.value.trim() || '';
const optH = ins[1]?.value.trim() || '';
if (anchor) {
const oRow = ['AnswerOption', anchor, optH, '', '', '', ''];
if (base === 8) oRow.push('');
rows.push(oRow);
}
});
}
});
return rows;
}
// ═══════════════════════════════════════════════════════════
// PREVIEW
// ═══════════════════════════════════════════════════════════
function buildPreview() {
const rows = buildRows();
const head = document.getElementById('previewHead');
const tbody = document.getElementById('previewBody');
head.innerHTML = '';
tbody.innerHTML = '';
if (!rows.length) return;
rows[0].forEach(h => {
const th = document.createElement('th');
th.textContent = h.length > 20 ? h.split(',')[0] : h;
head.appendChild(th);
});
const data = rows.slice(1);
document.getElementById('rowCount').textContent = data.length + ' rows (excl. header)';
data.forEach(row => {
const tr = document.createElement('tr');
const type = row[0];
tr.innerHTML = `<td><span class="tp tp-${type.toLowerCase()}">${type}</span></td>` +
row.slice(1).map(c => `<td title="${esc(c)}">${esc(c)||'<span style="color:#ccc">—</span>'}</td>`).join('');
tbody.appendChild(tr);
});
}
// ═══════════════════════════════════════════════════════════
// EXPORT CSV
// ═══════════════════════════════════════════════════════════
function exportCSV() {
const rows = buildRows();
const csv = rows.map(row =>
row.map(cell => {
const s = String(cell);
return (s.includes(',') || s.includes('"') || s.includes('\n'))
? '"' + s.replace(/"/g, '""') + '"' : s;
}).join(',')
).join('\n');
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
const name = currentMode === 'single'
? ((document.getElementById('instrumentTitle').value||'module').trim().replace(/\s+/g,'_'))
: 'multi_instrument_module';
a.href = url; a.download = name + '_assessment_module.csv';
document.body.appendChild(a); a.click();
document.body.removeChild(a); URL.revokeObjectURL(url);
const t = document.getElementById('toast');
t.classList.add('show');
setTimeout(() => t.classList.remove('show'), 3000);
}
// ═══════════════════════════════════════════════════════════
// UTILITY
// ═══════════════════════════════════════════════════════════
function esc(str) {
return String(str||'').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
}
document.getElementById('libraryModal').addEventListener('click', function(e) {
if (e.target === this) closeLibrary();
});
// Fix getQContainer for instrument targets
const _origGetQC = getQContainer;
window.getQContainer = function(targetKey) {
if (targetKey === 'main') return document.getElementById('questionsList');
// "inst-5" → look for element "inst-qs-5"
const m = targetKey.match(/^inst-(\d+)$/);
if (m) return document.getElementById('inst-qs-' + m[1]);
return null;
};
// ═══════════════════════════════════════════════════════════
// TEMPLATE UPLOAD & PARSE (handles both .xlsx and .docx)
// ═══════════════════════════════════════════════════════════
function handleTemplateUpload(event) {
const file = event.target.files[0];
if (!file) return;
const isDocx = file.name.toLowerCase().endsWith('.docx');
const reader = new FileReader();
reader.onload = function(e) {
try {
if (isDocx) parseDocxTemplate(e.target.result);
else parseTemplate(e.target.result);
} catch(err) {
alert('Could not parse file: ' + err.message);
}
};
reader.readAsArrayBuffer(file);
event.target.value = '';
}
// ── DOCX parser ───────────────────────────────────────────
function parseDocxTemplate(arrayBuffer) {
mammoth.convertToHtml({ arrayBuffer }).then(function(result) {
const html = result.value;
const dp = new DOMParser();
const doc = dp.parseFromString(html, 'text/html');
const tables = Array.from(doc.querySelectorAll('table'));
// Helper: get all text in a cell
const cellText = td => (td ? td.textContent.trim() : '');
// Helper: parse a 2-col label:value table into an object