-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
893 lines (769 loc) · 29.7 KB
/
Copy pathscript.js
File metadata and controls
893 lines (769 loc) · 29.7 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
const vagueVerbs = [
'understand',
'demonstrate an understanding of',
'develop an understanding of',
'explore',
'read',
'think about',
'learn about'
];
const assessmentTypes = [
'Discussion',
'Quiz/Exam',
'Written Assignment',
'Interactive Activity',
'Other'
];
const materialTypes = [
'Reading',
'Lecture Video',
'Other Video',
'Website',
'Interactive Object',
'Other'
];
const storageKey = 'courseMapDraft';
let state = {
courseNumber: '',
courseName: '',
clos: ['', '', ''],
modules: []
};
const elements = {
courseNumber: document.getElementById('courseNumber'),
courseName: document.getElementById('courseName'),
cloList: document.getElementById('cloList'),
addCloBtn: document.getElementById('addCloBtn'),
modulesSection: document.getElementById('modulesSection'),
addModuleBtn: document.getElementById('addModuleBtn'),
alignmentSummary: document.getElementById('alignmentSummary'),
alignmentCheckBtn: document.getElementById('alignmentCheckBtn'),
downloadWordBtn: document.getElementById('downloadWordBtn')
};
function createDefaultMO() {
return {
text: '',
alignedClos: state.clos.map(() => false),
expanded: true
};
}
function createDefaultAssessment(moCount) {
return {
type: '',
desc: '',
alignedMos: Array.from({ length: moCount }, () => false),
expanded: true
};
}
function createDefaultMaterial() {
return {
type: '',
desc: '',
expanded: true
};
}
function createDefaultModule() {
return {
title: '',
mos: [],
assessments: [],
materials: []
};
}
function loadState() {
try {
const stored = localStorage.getItem(storageKey);
if (stored) {
const parsed = JSON.parse(stored);
state = {
...state,
...parsed,
clos: Array.isArray(parsed.clos) && parsed.clos.length ? parsed.clos : state.clos,
modules: Array.isArray(parsed.modules) ? parsed.modules : []
};
}
} catch (error) {
console.warn('Unable to load saved course map:', error);
}
if (!Array.isArray(state.clos) || state.clos.length < 1) {
state.clos = ['', '', ''];
}
if (state.clos.length > 10) {
state.clos = state.clos.slice(0, 10);
}
if (!Array.isArray(state.modules)) {
state.modules = [];
}
if (state.modules.length === 0) {
state.modules.push(createDefaultModule());
}
state.modules = state.modules.map(module => {
if (!Array.isArray(module.mos) || module.mos.length < 1) {
module.mos = [];
}
module.mos = module.mos.map(mo => {
if (!Array.isArray(mo.alignedClos) || mo.alignedClos.length !== state.clos.length) {
mo.alignedClos = state.clos.map((_, index) => mo.alignedClos?.[index] ?? false);
}
return {
text: typeof mo.text === 'string' ? mo.text : '',
alignedClos: mo.alignedClos,
expanded: typeof mo.expanded === 'boolean' ? mo.expanded : true
};
});
module.assessments = Array.isArray(module.assessments) ? module.assessments : [];
module.assessments = module.assessments.map(assessment => {
const alignedMos = Array.isArray(assessment.alignedMos) ? assessment.alignedMos : [];
return {
type: assessmentTypes.includes(assessment.type) ? assessment.type : '',
desc: typeof assessment.desc === 'string' ? assessment.desc : '',
alignedMos: module.mos.map((_, index) => alignedMos[index] ?? false),
expanded: typeof assessment.expanded === 'boolean' ? assessment.expanded : true
};
});
module.materials = Array.isArray(module.materials) ? module.materials : [];
module.materials = module.materials.map(material => ({
type: materialTypes.includes(material.type) ? material.type : '',
desc: typeof material.desc === 'string' ? material.desc : '',
expanded: typeof material.expanded === 'boolean' ? material.expanded : true
}));
return module;
});
}
function saveState() {
localStorage.setItem(storageKey, JSON.stringify(state));
}
function containsVagueLanguage(value) {
const normalized = value.trim().toLowerCase();
return vagueVerbs.some(verb => normalized.includes(verb));
}
function typeSlug(value) {
return value.toString().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
}
const typeStyleMap = {
discussion: { color: '#C99076' },
'quiz-exam': { color: '#D9B27B' },
'written-assignment': { color: '#B9BE9A' },
'interactive-activity': { color: '#9FAFC6' },
other: { color: '#A89EA8' },
reading: { color: '#C99076' },
'lecture-video': { color: '#D9B27B' },
'other-video': { color: '#B9BE9A' },
website: { color: '#9FAFC6' },
'interactive-object': { color: '#A89EA8' }
};
function buildCustomDropdown(options, selectedValue, placeholder, onSelect) {
const wrapper = document.createElement('div');
wrapper.className = 'custom-select';
const toggle = document.createElement('button');
toggle.type = 'button';
toggle.className = 'custom-select-toggle';
toggle.setAttribute('aria-haspopup', 'listbox');
toggle.setAttribute('aria-expanded', 'false');
const dot = document.createElement('span');
dot.className = 'custom-select-dot';
const selectedLabel = document.createElement('span');
selectedLabel.className = 'custom-select-value';
selectedLabel.textContent = selectedValue || placeholder;
if (selectedValue) {
const style = typeStyleMap[typeSlug(selectedValue)];
if (style) dot.style.backgroundColor = style.color;
else dot.style.opacity = '0.3';
} else {
dot.style.border = '1px solid rgba(20,20,19,0.12)';
dot.style.backgroundColor = 'transparent';
}
const icon = document.createElement('span');
icon.className = 'custom-select-icon';
icon.textContent = '▾';
toggle.append(dot, selectedLabel, icon);
const list = document.createElement('ul');
list.className = 'custom-select-list';
list.setAttribute('role', 'listbox');
list.hidden = true;
options.forEach(option => {
const item = document.createElement('li');
item.className = 'custom-select-item';
item.setAttribute('role', 'option');
item.tabIndex = 0;
item.dataset.value = option;
const itemDot = document.createElement('span');
itemDot.className = 'custom-option-dot';
const style = typeStyleMap[typeSlug(option)];
itemDot.style.backgroundColor = style ? style.color : 'transparent';
const itemLabel = document.createElement('span');
itemLabel.textContent = option;
item.append(itemDot, itemLabel);
item.addEventListener('click', () => {
setValue(option);
});
item.addEventListener('keydown', event => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
setValue(option);
}
});
list.appendChild(item);
});
function closeDropdown() {
list.hidden = true;
toggle.setAttribute('aria-expanded', 'false');
wrapper.classList.remove('open');
list.style.top = '';
list.style.bottom = '';
}
function openDropdown() {
list.hidden = false;
toggle.setAttribute('aria-expanded', 'true');
wrapper.classList.add('open');
// Check if dropdown would go off-screen
setTimeout(() => {
const toggleRect = toggle.getBoundingClientRect();
const listRect = list.getBoundingClientRect();
const spaceBelow = window.innerHeight - toggleRect.bottom;
if (spaceBelow < listRect.height + 20) {
// Position above instead
list.style.top = 'auto';
list.style.bottom = 'calc(100% + 10px)';
} else {
// Position below (default)
list.style.top = 'calc(100% + 10px)';
list.style.bottom = 'auto';
}
}, 0);
}
function setValue(value) {
selectedLabel.textContent = value;
const style = typeStyleMap[typeSlug(value)];
if (style) {
dot.style.backgroundColor = style.color;
dot.style.border = 'none';
}
closeDropdown();
onSelect(value);
}
toggle.addEventListener('click', event => {
event.stopPropagation();
if (list.hidden) {
closeAllCustomDropdowns();
openDropdown();
} else {
closeDropdown();
}
});
wrapper.addEventListener('keydown', event => {
if (event.key === 'Escape') {
closeDropdown();
toggle.focus();
}
});
wrapper.closeDropdown = closeDropdown;
wrapper.setValue = setValue;
wrapper.append(toggle, list);
return wrapper;
}
function closeAllCustomDropdowns() {
document.querySelectorAll('.custom-select.open').forEach(control => {
control.classList.remove('open');
const list = control.querySelector('.custom-select-list');
const toggle = control.querySelector('.custom-select-toggle');
if (list) list.hidden = true;
if (toggle) toggle.setAttribute('aria-expanded', 'false');
});
}
function getAlignmentIssues() {
const issues = [];
if (state.modules.length === 0) {
issues.push('Add at least one module.');
}
state.modules.forEach((module, moduleIndex) => {
const moduleNumber = moduleIndex + 1;
if (!Array.isArray(module.mos) || module.mos.length === 0) {
issues.push(`Module ${moduleNumber} needs at least one module objective.`);
}
module.mos.forEach((mo, moIndex) => {
const moNumber = `${moduleNumber}.${moIndex + 1}`;
if (!mo.alignedClos.some(Boolean)) {
issues.push(`Module ${moduleNumber} MO ${moNumber} must align with at least one CLO.`);
}
const alignedToAssessment = module.assessments.some(assessment => assessment.alignedMos[moIndex]);
if (!alignedToAssessment) {
issues.push(`Module ${moduleNumber} MO ${moNumber} must align with at least one assessment.`);
}
});
module.assessments.forEach((assessment, assessmentIndex) => {
const assessmentNumber = assessmentIndex + 1;
if (!assessment.type) {
issues.push(`Module ${moduleNumber} assessment ${assessmentNumber} needs a type.`);
}
if (!assessment.alignedMos.some(Boolean)) {
issues.push(`Module ${moduleNumber} assessment ${assessmentNumber} must align with at least one MO.`);
}
});
});
state.clos.forEach((_, cloIndex) => {
const cloMatched = state.modules.some(module => module.mos.some(mo => mo.alignedClos[cloIndex]));
if (!cloMatched) {
issues.push(`CLO ${cloIndex + 1} is not aligned with any module objective.`);
}
});
return issues;
}
function buildToggleButton(labelText, active) {
const button = document.createElement('button');
button.type = 'button';
button.className = 'pill-button';
if (active) {
button.classList.add('active');
button.setAttribute('aria-pressed', 'true');
} else {
button.setAttribute('aria-pressed', 'false');
}
button.textContent = labelText;
return button;
}
function renderCLOs(alignmentIssues) {
elements.cloList.innerHTML = '';
state.clos.forEach((clo, index) => {
const template = document.getElementById('cloTemplate');
const node = template.content.cloneNode(true);
const item = node.querySelector('.clo-item');
item.dataset.cloIndex = index;
item.querySelector('.clo-number').textContent = index + 1;
const input = item.querySelector('.clo-text');
input.value = clo;
input.addEventListener('input', event => {
state.clos[index] = event.target.value;
syncClosInMos();
saveState();
});
const deleteButton = item.querySelector('.delete-clo');
deleteButton.disabled = state.clos.length <= 1;
deleteButton.addEventListener('click', () => {
if (state.clos.length <= 1) return;
state.clos.splice(index, 1);
state.modules.forEach(module => module.mos.forEach(mo => mo.alignedClos.splice(index, 1)));
saveState();
render();
});
const vagueWarning = item.querySelector('.vague-warning');
if (clo && containsVagueLanguage(clo)) {
vagueWarning.textContent = 'This objective may use vague language. Try a stronger Bloom verb.';
vagueWarning.classList.remove('hidden');
}
const unassigned = item.querySelector('.clo-unassigned');
const cloIssue = alignmentIssues.find(issue => issue.includes(`CLO ${index + 1}`));
if (cloIssue) {
unassigned.textContent = 'This CLO is not aligned to any module objective yet.';
unassigned.classList.remove('hidden');
item.classList.add('invalid');
}
elements.cloList.appendChild(node);
});
}
function syncClosInMos() {
state.modules.forEach(module => {
module.mos.forEach(mo => {
while (mo.alignedClos.length < state.clos.length) {
mo.alignedClos.push(false);
}
if (mo.alignedClos.length > state.clos.length) {
mo.alignedClos = mo.alignedClos.slice(0, state.clos.length);
}
});
});
}
function renderModules(alignmentIssues) {
elements.modulesSection.innerHTML = '';
if (!Array.isArray(state.modules) || state.modules.length === 0) {
state.modules = [createDefaultModule()];
}
const moduleTemplate = document.getElementById('moduleTemplate');
if (!moduleTemplate) {
const errorMessage = document.createElement('div');
errorMessage.textContent = 'Module template not found.';
elements.modulesSection.appendChild(errorMessage);
return;
}
state.modules.forEach((module, moduleIndex) => {
const moduleNode = moduleTemplate.content.cloneNode(true);
const moduleCard = moduleNode.querySelector('.module-card');
const moduleIndexLabel = moduleNode.querySelector('.module-index');
moduleIndexLabel.textContent = moduleIndex + 1;
const titleInput = moduleNode.querySelector('.module-title-input');
titleInput.value = module.title;
titleInput.addEventListener('input', event => {
state.modules[moduleIndex].title = event.target.value;
saveState();
});
const deleteModuleBtn = moduleNode.querySelector('.delete-module');
deleteModuleBtn.disabled = state.modules.length <= 1;
deleteModuleBtn.addEventListener('click', () => {
if (state.modules.length <= 1) return;
state.modules.splice(moduleIndex, 1);
saveState();
render();
});
const moList = moduleNode.querySelector('.mo-list');
const addMoButton = moduleNode.querySelector('.add-mo');
addMoButton.addEventListener('click', () => {
if (state.modules[moduleIndex].mos.length >= 10) return;
state.modules[moduleIndex].mos.push(createDefaultMO());
state.modules[moduleIndex].assessments.forEach(assessment => assessment.alignedMos.push(false));
saveState();
render();
});
module.mos.forEach((mo, moIndex) => {
const moTemplate = document.getElementById('moTemplate');
const moNode = moTemplate.content.cloneNode(true);
const card = moNode.querySelector('.mo-item');
const toggle = moNode.querySelector('.card-toggle');
const content = moNode.querySelector('.collapsible-content');
const summary = moNode.querySelector('.mo-card-summary');
const moNumber = `${moduleIndex + 1}.${moIndex + 1}`;
moNode.querySelector('.mo-number').textContent = moNumber;
card.classList.toggle('collapsed', !mo.expanded);
if (!mo.expanded) {
summary.classList.remove('hidden');
summary.textContent = mo.text ? mo.text : 'Tap to expand';
}
toggle.addEventListener('click', () => {
state.modules[moduleIndex].mos[moIndex].expanded = !state.modules[moduleIndex].mos[moIndex].expanded;
saveState();
render();
});
const moInput = moNode.querySelector('.mo-text');
moInput.value = mo.text;
moInput.addEventListener('input', event => {
state.modules[moduleIndex].mos[moIndex].text = event.target.value;
saveState();
});
const pillContainer = moNode.querySelector('.mo-clo-pills');
state.clos.forEach((_, cloIndex) => {
const pill = buildToggleButton(`CLO ${cloIndex + 1}`, mo.alignedClos[cloIndex]);
pill.addEventListener('click', () => {
state.modules[moduleIndex].mos[moIndex].alignedClos[cloIndex] = !state.modules[moduleIndex].mos[moIndex].alignedClos[cloIndex];
saveState();
render();
});
pillContainer.appendChild(pill);
});
const vagueWarning = moNode.querySelector('.vague-warning');
if (mo.text && containsVagueLanguage(mo.text)) {
vagueWarning.textContent = 'This objective may use vague language. Try a stronger Bloom verb.';
vagueWarning.classList.remove('hidden');
}
const moUnassigned = moNode.querySelector('.mo-unassigned');
const moIssue = alignmentIssues.find(issue => issue.includes(`MO ${moNumber}`));
if (moIssue) {
moUnassigned.textContent = 'This MO must align with a CLO and at least one assessment.';
moUnassigned.classList.remove('hidden');
}
const deleteMoBtn = moNode.querySelector('.delete-mo');
deleteMoBtn.addEventListener('click', () => {
if (state.modules[moduleIndex].mos.length <= 1) return;
state.modules[moduleIndex].mos.splice(moIndex, 1);
state.modules[moduleIndex].assessments.forEach(assessment => assessment.alignedMos.splice(moIndex, 1));
saveState();
render();
});
moList.appendChild(moNode);
});
const assessmentList = moduleNode.querySelector('.assessment-list');
const addAssessmentButton = moduleNode.querySelector('.add-assessment');
addAssessmentButton.addEventListener('click', () => {
if (state.modules[moduleIndex].assessments.length >= 10) return;
state.modules[moduleIndex].assessments.push(createDefaultAssessment(state.modules[moduleIndex].mos.length));
saveState();
render();
});
module.assessments.forEach((assessment, assessmentIndex) => {
const assessmentTemplate = document.getElementById('assessmentTemplate');
const assessmentNode = assessmentTemplate.content.cloneNode(true);
const assessmentItem = assessmentNode.querySelector('.assessment-item');
const toggle = assessmentNode.querySelector('.card-toggle');
const content = assessmentNode.querySelector('.collapsible-content');
const details = assessmentNode.querySelector('.assessment-details');
const summary = assessmentNode.querySelector('.assessment-card-summary');
if (assessment.type) {
assessmentItem.classList.add(typeSlug(assessment.type));
}
cardExpandState(assessmentItem, assessment, summary);
toggle.addEventListener('click', () => {
state.modules[moduleIndex].assessments[assessmentIndex].expanded = !state.modules[moduleIndex].assessments[assessmentIndex].expanded;
saveState();
render();
});
const typeSelect = assessmentNode.querySelector('.assessment-type');
const assessmentDropdown = buildCustomDropdown(assessmentTypes, assessment.type, 'Select a type', selected => {
state.modules[moduleIndex].assessments[assessmentIndex].type = selected;
if (!selected) {
state.modules[moduleIndex].assessments[assessmentIndex].desc = '';
}
saveState();
render();
});
typeSelect.replaceWith(assessmentDropdown);
const descInput = assessmentNode.querySelector('.assessment-desc');
descInput.value = assessment.desc;
if (assessment.type) {
details.classList.remove('hidden');
}
descInput.addEventListener('input', event => {
state.modules[moduleIndex].assessments[assessmentIndex].desc = event.target.value;
saveState();
});
const mosContainer = assessmentNode.querySelector('.mos-pills');
module.mos.forEach((_, moIndex) => {
const pill = buildToggleButton(`MO ${moduleIndex + 1}.${moIndex + 1}`, assessment.alignedMos[moIndex]);
pill.addEventListener('click', () => {
state.modules[moduleIndex].assessments[assessmentIndex].alignedMos[moIndex] = !state.modules[moduleIndex].assessments[assessmentIndex].alignedMos[moIndex];
saveState();
render();
});
mosContainer.appendChild(pill);
});
const assessmentWarning = assessmentNode.querySelector('.assessment-mos-warning');
const assessmentIssue = alignmentIssues.find(issue => issue.includes(`assessment ${assessmentIndex + 1}`));
if (assessmentIssue) {
assessmentWarning.textContent = 'This assessment must be aligned with at least one MO.';
assessmentWarning.classList.remove('hidden');
}
const deleteAssessmentBtn = assessmentNode.querySelector('.delete-assessment');
deleteAssessmentBtn.addEventListener('click', () => {
state.modules[moduleIndex].assessments.splice(assessmentIndex, 1);
saveState();
render();
});
assessmentList.appendChild(assessmentNode);
});
const materialList = moduleNode.querySelector('.material-list');
const addMaterialButton = moduleNode.querySelector('.add-material');
addMaterialButton.addEventListener('click', () => {
if (state.modules[moduleIndex].materials.length >= 10) return;
state.modules[moduleIndex].materials.push(createDefaultMaterial());
saveState();
render();
});
module.materials.forEach((material, materialIndex) => {
const materialTemplate = document.getElementById('materialTemplate');
const materialNode = materialTemplate.content.cloneNode(true);
const materialItem = materialNode.querySelector('.material-item');
const toggle = materialNode.querySelector('.card-toggle');
const details = materialNode.querySelector('.material-details');
const summary = materialNode.querySelector('.material-card-summary');
if (material.type) {
materialItem.classList.add(typeSlug(material.type));
}
cardExpandState(materialItem, material, summary);
toggle.addEventListener('click', () => {
state.modules[moduleIndex].materials[materialIndex].expanded = !state.modules[moduleIndex].materials[materialIndex].expanded;
saveState();
render();
});
const typeSelect = materialNode.querySelector('.material-type');
const materialDropdown = buildCustomDropdown(materialTypes, material.type, 'Select a type', selected => {
state.modules[moduleIndex].materials[materialIndex].type = selected;
if (!selected) {
state.modules[moduleIndex].materials[materialIndex].desc = '';
}
saveState();
render();
});
typeSelect.replaceWith(materialDropdown);
const descInput = materialNode.querySelector('.material-desc');
descInput.value = material.desc;
if (material.type) {
details.classList.remove('hidden');
}
descInput.addEventListener('input', event => {
state.modules[moduleIndex].materials[materialIndex].desc = event.target.value;
saveState();
});
const deleteMaterialBtn = materialNode.querySelector('.delete-material');
deleteMaterialBtn.addEventListener('click', () => {
state.modules[moduleIndex].materials.splice(materialIndex, 1);
saveState();
render();
});
materialList.appendChild(materialNode);
});
elements.modulesSection.appendChild(moduleNode);
});
}
function cardExpandState(cardItem, itemState, summary) {
cardItem.classList.toggle('collapsed', !itemState.expanded);
if (!itemState.expanded) {
summary.classList.remove('hidden');
summary.textContent = itemState.type ? `${itemState.type}` : 'Tap to expand';
}
}
function renderAlignmentSummary(alignmentIssues) {
elements.alignmentSummary.innerHTML = '';
if (!alignmentIssues.length) {
const item = document.createElement('div');
item.className = 'notice-item';
item.textContent = 'All alignment rules are satisfied. Great work!';
elements.alignmentSummary.appendChild(item);
return;
}
alignmentIssues.forEach(issue => {
const item = document.createElement('div');
item.className = 'notice-item';
item.textContent = issue;
elements.alignmentSummary.appendChild(item);
});
}
function render() {
elements.courseNumber.value = state.courseNumber;
elements.courseName.value = state.courseName;
const issues = getAlignmentIssues();
renderCLOs(issues);
renderModules(issues);
renderAlignmentSummary(issues);
}
function initEventBindings() {
elements.courseNumber.addEventListener('input', event => {
state.courseNumber = event.target.value;
saveState();
});
elements.courseName.addEventListener('input', event => {
state.courseName = event.target.value;
saveState();
});
elements.addCloBtn.addEventListener('click', () => {
if (state.clos.length >= 10) return;
state.clos.push('');
syncClosInMos();
try { saveState(); } catch (e) { /* ignore storage errors */ }
render();
});
if (elements.addModuleBtn) {
elements.addModuleBtn.addEventListener('click', () => {
console.log('addModuleBtn clicked');
try {
state.modules.push(createDefaultModule());
// render first so user sees immediate feedback
render();
try { saveState(); } catch (e) { console.warn('saveState failed', e); }
} catch (err) {
console.error('Error in addModule handler:', err);
}
});
}
elements.alignmentCheckBtn.addEventListener('click', () => {
const issues = getAlignmentIssues();
if (!issues.length) {
alert('Great work! All alignment rules are satisfied.');
return;
}
alert(`Alignment issues found:\n\n${issues.join('\n')}`);
});
elements.downloadWordBtn.addEventListener('click', createWordDownload);
document.addEventListener('click', event => {
if (!event.target.closest('.custom-select')) {
closeAllCustomDropdowns();
}
});
document.addEventListener('keydown', event => {
if (event.key === 'Escape') {
closeAllCustomDropdowns();
}
});
}
function createWordDownload() {
const wrapper = document.createElement('div');
const header = document.createElement('h1');
header.textContent = 'Course Mapping Report';
wrapper.appendChild(header);
const courseInfo = document.createElement('p');
courseInfo.innerHTML = `<strong>Course Number:</strong> ${state.courseNumber || 'N/A'}<br><strong>Course Name:</strong> ${state.courseName || 'N/A'}`;
wrapper.appendChild(courseInfo);
const cloTitle = document.createElement('h2');
cloTitle.textContent = 'Course Learning Objectives';
wrapper.appendChild(cloTitle);
const cloList = document.createElement('ol');
state.clos.forEach((clo) => {
const item = document.createElement('li');
item.textContent = clo || '—';
cloList.appendChild(item);
});
wrapper.appendChild(cloList);
const modulesTitle = document.createElement('h2');
modulesTitle.textContent = 'Course Modules';
wrapper.appendChild(modulesTitle);
state.modules.forEach((module, moduleIndex) => {
const moduleHeading = document.createElement('h3');
moduleHeading.textContent = `Module ${moduleIndex + 1}: ${module.title || 'Untitled Module'}`;
wrapper.appendChild(moduleHeading);
const mosHeading = document.createElement('h4');
mosHeading.textContent = 'Module Objectives';
wrapper.appendChild(mosHeading);
const mosList = document.createElement('ol');
module.mos.forEach((mo, moIndex) => {
const moItem = document.createElement('li');
const cloLabels = mo.alignedClos
.map((aligned, cloIndex) => (aligned ? `CLO ${cloIndex + 1}` : null))
.filter(Boolean)
.join(', ');
moItem.innerHTML = `${mo.text || '—'}<br><em>Aligned CLOs:</em> ${cloLabels || 'None'}`;
mosList.appendChild(moItem);
});
wrapper.appendChild(mosList);
const assessmentHeading = document.createElement('h4');
assessmentHeading.textContent = 'Assessments';
wrapper.appendChild(assessmentHeading);
const assessmentList = document.createElement('ol');
module.assessments.forEach((assessment, assessmentIndex) => {
const item = document.createElement('li');
const alignedMos = assessment.alignedMos
.map((aligned, moIndex) => (aligned ? `${moduleIndex + 1}.${moIndex + 1}` : null))
.filter(Boolean)
.join(', ');
item.innerHTML = `<strong>${assessment.type || 'Unspecified'}</strong>: ${assessment.desc || '—'}<br><em>Aligned MOs:</em> ${alignedMos || 'None'}`;
assessmentList.appendChild(item);
});
wrapper.appendChild(assessmentList);
const materialsHeading = document.createElement('h4');
materialsHeading.textContent = 'Instructional Materials';
wrapper.appendChild(materialsHeading);
const materialsList = document.createElement('ol');
module.materials.forEach(material => {
const item = document.createElement('li');
item.innerHTML = `<strong>${material.type || 'Unspecified'}</strong>: ${material.desc || '—'}`;
materialsList.appendChild(item);
});
wrapper.appendChild(materialsList);
});
const html = `<!DOCTYPE html><html><head><meta charset="utf-8"><title>Course Mapping Report</title></head><body>${wrapper.innerHTML}</body></html>`;
const blob = new Blob([html], { type: 'application/msword' });
const url = URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = url;
anchor.download = `${(state.courseNumber || 'course-map').replace(/\s+/g, '_')}.doc`;
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
URL.revokeObjectURL(url);
}
function init() {
loadState();
initEventBindings();
render();
}
// Global fallback for environments where event binding fails.
window.__lastAddModule = 0;
window.__fallbackAddModule = function() {
try {
const now = Date.now();
if (now - (window.__lastAddModule || 0) < 500) return; // debounce duplicates
window.__lastAddModule = now;
if (!state || !Array.isArray(state.modules)) state.modules = [createDefaultModule()];
state.modules.push(createDefaultModule());
try { render(); } catch (e) { console.warn('render failed in fallback', e); }
try { saveState(); } catch (e) { console.warn('saveState failed in fallback', e); }
} catch (err) {
console.error('fallback addModule error', err);
}
};
init();