@@ -5,6 +5,26 @@ const downloadBtn = document.getElementById('downloadBtn');
55// Declare questions array for use throughout the script
66let questions = [ ] ;
77
8+ // Categories list from categories.json
9+ const categoriesList = [
10+ "Genesis" , "Exodus" , "Leviticus" , "Numeri" , "Deuteronomium" ,
11+ "Jozua" , "Richteren" , "Ruth" , "1 Samuël" , "2 Samuël" ,
12+ "1 Koningen" , "2 Koningen" , "1 Kronieken" , "2 Kronieken" ,
13+ "Ezra" , "Nehemia" , "Esther" , "Job" , "Psalmen" , "Spreuken" ,
14+ "Prediker" , "Hooglied" , "Jesaja" , "Jeremia" , "Klaagliederen" ,
15+ "Ezechiël" , "Daniël" , "Hosea" , "Joël" , "Amos" , "Obadja" ,
16+ "Jona" , "Micha" , "Nahum" , "Habakuk" , "Zefanja" , "Haggai" ,
17+ "Zacharia" , "Maleachi" , "Matteüs" , "Marcus" , "Lucas" ,
18+ "Johannes" , "Handelingen" , "Romeinen" , "1 Korintiërs" ,
19+ "2 Korintiërs" , "Galaten" , "Efeziërs" , "Filippenzen" ,
20+ "Kolossenzen" , "1 Tessalonicenzen" , "2 Tessalonicenzen" ,
21+ "1 Timoteüs" , "2 Timoteüs" , "Titus" , "Filemon" , "Hebreeën" ,
22+ "Jakobus" , "1 Petrus" , "2 Petrus" , "1 Johannes" , "2 Johannes" ,
23+ "3 Johannes" , "Judas" , "Openbaring" , "Kerst" , "Pasen" ,
24+ "Pinksteren" , "Hemelvaart" , "Goede Vrijdag" , "Stille Zaterdag" ,
25+ "Paasmaandag" , "Pinkstermaandag"
26+ ] ;
27+
828// Toast utility
929function showToast ( message , isError = false ) {
1030 let toast = document . createElement ( 'div' ) ;
@@ -36,6 +56,41 @@ function saveLastQuestionType(type) {
3656 localStorage . setItem ( 'bijbelquiz_last_type' , type ) ;
3757}
3858
59+ // Generate the next question ID based on existing questions
60+ function getNextQuestionId ( ) {
61+ if ( questions . length === 0 ) {
62+ return '000001' ;
63+ }
64+ // Find the highest ID number
65+ let maxId = 0 ;
66+ questions . forEach ( q => {
67+ if ( q . id ) {
68+ const idNum = parseInt ( q . id , 10 ) ;
69+ if ( ! isNaN ( idNum ) && idNum > maxId ) {
70+ maxId = idNum ;
71+ }
72+ }
73+ } ) ;
74+ // Generate next ID with leading zeros
75+ const nextId = ( maxId + 1 ) . toString ( ) . padStart ( 6 , '0' ) ;
76+ return nextId ;
77+ }
78+
79+ // Render category checkboxes
80+ function renderCategories ( ) {
81+ let html = '<label>Categorieën (optioneel):</label>' ;
82+ html += '<div class="categories-container">' ;
83+ categoriesList . forEach ( cat => {
84+ const catId = 'cat_' + cat . replace ( / \s + / g, '_' ) . replace ( / [ ^ a - z A - Z 0 - 9 _ ] / g, '' ) ;
85+ html += `<div class="category-item">` ;
86+ html += `<input type="checkbox" id="${ catId } " name="categories" value="${ cat } ">` ;
87+ html += `<label for="${ catId } ">${ cat } </label>` ;
88+ html += `</div>` ;
89+ } ) ;
90+ html += '</div>' ;
91+ return html ;
92+ }
93+
3994window . addEventListener ( 'DOMContentLoaded' , ( ) => {
4095 // Restore last selected question type
4196 const lastType = localStorage . getItem ( 'bijbelquiz_last_type' ) ;
@@ -78,6 +133,7 @@ function renderFields(type) {
78133` ;
79134 html += `<input type="text" id="biblicalReference" name="biblicalReference" placeholder="Bijv. Genesis 1:1">
80135` ;
136+ html += renderCategories ( ) ;
81137 } else if ( type === 'fitb' ) {
82138 html += `<label for="vraag">Vraag (gebruik _____ voor het invulveld):</label>
83139` ;
@@ -99,6 +155,7 @@ function renderFields(type) {
99155` ;
100156 html += `<input type="text" id="biblicalReference" name="biblicalReference" placeholder="Bijv. Exodus 3:14">
101157` ;
158+ html += renderCategories ( ) ;
102159 } else if ( type === 'tf' ) {
103160 html += `<label for="vraag">Stelling:</label>
104161` ;
@@ -112,6 +169,7 @@ function renderFields(type) {
112169` ;
113170 html += `<input type="text" id="biblicalReference" name="biblicalReference" placeholder="Bijv. Johannes 3:16">
114171` ;
172+ html += renderCategories ( ) ;
115173 }
116174 dynamicFields . innerHTML = html ;
117175}
@@ -126,6 +184,12 @@ form.type.addEventListener('change', e => {
126184// Initial render
127185renderFields ( form . type . value ) ;
128186
187+ // Collect selected categories from checkboxes
188+ function getSelectedCategories ( ) {
189+ const checkboxes = form . querySelectorAll ( 'input[name="categories"]:checked' ) ;
190+ return Array . from ( checkboxes ) . map ( cb => cb . value ) ;
191+ }
192+
129193// In form submit, use checked checkboxes for categories
130194form . addEventListener ( 'submit' , function ( e ) {
131195 e . preventDefault ( ) ;
@@ -134,8 +198,10 @@ form.addEventListener('submit', function(e) {
134198 const juisteAntwoord = form . querySelector ( '#juisteAntwoord' ) ? form . querySelector ( '#juisteAntwoord' ) . value . trim ( ) : '' ;
135199 const moeilijkheidsgraad = Number ( form . difficulty . value ) ;
136200 const biblicalReference = form . querySelector ( '#biblicalReference' ) ? form . querySelector ( '#biblicalReference' ) . value . trim ( ) : '' ;
137- // Always set categories to empty array to match guidelines
138- const categories = [ ] ;
201+ // Get selected categories from checkboxes
202+ const categories = getSelectedCategories ( ) ;
203+ // Generate unique ID
204+ const id = getNextQuestionId ( ) ;
139205
140206 let questionObj = {
141207 vraag,
@@ -144,7 +210,8 @@ form.addEventListener('submit', function(e) {
144210 type,
145211 categories,
146212 biblicalReference : biblicalReference || null , // Set to null if empty
147- fouteAntwoorden : [ ] // Always present for all types
213+ fouteAntwoorden : [ ] , // Always present for all types
214+ id
148215 } ;
149216
150217 if ( type === 'mc' || type === 'fitb' ) {
@@ -172,7 +239,7 @@ form.addEventListener('submit', function(e) {
172239 questions . push ( questionObj ) ;
173240 saveBackup ( ) ;
174241 updatePreview ( ) ;
175- showToast ( 'Vraag toegevoegd!' ) ;
242+ showToast ( 'Vraag toegevoegd! ID: ' + id ) ;
176243 form . reset ( ) ;
177244 form . type . value = type ; // Keep the same question type selected
178245 saveLastQuestionType ( type ) ; // Save the type
@@ -231,4 +298,4 @@ downloadBtn.addEventListener('click', function() {
231298 updatePreview ( true ) ;
232299} ) ;
233300
234- document . getElementById ( 'restoreBtn' ) . addEventListener ( 'click' , restoreBackup ) ;
301+ document . getElementById ( 'restoreBtn' ) . addEventListener ( 'click' , restoreBackup ) ;
0 commit comments