diff --git a/resources/views/modules/form/index-mitigasi.blade.php b/resources/views/modules/form/index-mitigasi.blade.php index ca383d6..6acf027 100644 --- a/resources/views/modules/form/index-mitigasi.blade.php +++ b/resources/views/modules/form/index-mitigasi.blade.php @@ -1172,365 +1172,6 @@ (subKategori || sessionSubKategori); } - // function loadQuestion(mitigation_id) { - // $('#section4').show(); - // $('#accordion-4').html('

Loading...

'); - - // $.get('/mitigasi/form-mitigasi-question', { mitigation_id }) - // .done(data => { - // if (!data || !data.length) { - // $('#accordion-4').html( - // '

Pertanyaan tidak tersedia.

' - // ); - // return; - // } - // window.lastQuestionData = data; - - // // --- Build map - // const questionMap = {}; - // const childMap = {}; - // data.forEach(q => { - // questionMap[q.sequence] = q; - // if (q.ad_sequence) { - // if (!childMap[q.ad_sequence]) childMap[q.ad_sequence] = []; - // childMap[q.ad_sequence].push(q.sequence); - // } - // }); - - // // --- Kumpulkan multiQs - // const multiQs = []; - // data.forEach(q => { - // if (q.is_multiple) multiQs.push(q); - // }); - - // // --- Dapatkan sequence method dan question_plus - // const methodQuestion = data.find(q => q.type === 'method'); - // const methodSequence = methodQuestion?.sequence; - // let allowedMethodValue; - - // // --- Helper buat satu row - // function makeRow(q, idx, showRemove) { - // let inputEl = ""; - - // if (q.type === 'text') { - // inputEl = ``; - // } else if (q.type === 'form' || q.type === 'method') { - // inputEl = ` - // - // `; - // } else { - // inputEl = ``; - // } - - // const removeBtn = showRemove - // ? `` - // : ``; - - // return ` - //
- // ${inputEl} - // ${removeBtn} - //
`; - // } - - // // --- Build HTML utama - // let allHtml = ''; - // data.forEach((q, idx) => { - // // --- Build unit/desc - // let unitOrDesc = ''; - // if (q.type === 'form' || q.type === 'method') { - // unitOrDesc = ` - //
- // ${q.choices.map(c => ` - // - // `).join('')} - //
`; - // } else if (q.units && q.units.length === 1) { - // unitOrDesc = ` - // ${q.units[0]}`; - // } else if (q.units && q.units.length > 1) { - // unitOrDesc = ``; - // } - - // if (!q.is_multiple) { - // allHtml += ` - //
- // - // ${makeRow(q, 0, false)} - // ${unitOrDesc ? `
${unitOrDesc}
` : ''} - //
`; - // } - // }); - - // // --- Multiple-card builder (khusus jika ada multiQs) - // function makeMultipleCard(idx) { - // let title; - // const rowsHtml = multiQs.map((q, qIdx) => { - // // title = q.title_group; - // if (q.method && q['title_group_' + q.method]) { - // title = q['title_group_' + q.method]; - // } else { - // // fallback ke default - // title = q.title_group; - // } - - // let unitOrDesc = ''; - // if (q.type === 'form' || q.type === 'method') { - // unitOrDesc = ` - //
- // ${q.choices.map(c => ` - // - // `).join('')} - //
`; - // } else if (q.units && q.units.length === 1) { - // unitOrDesc = ` - // ${q.units[0]}`; - // } else if (q.units && q.units.length > 1) { - // unitOrDesc = ``; - // } - - // return ` - //
- // - //
- // ${makeRow(q, idx, false)} - //
- // ${unitOrDesc ? `
${unitOrDesc}
` : ''} - //
`; - // }).join(''); - - // return ` - //
- //
- // ${title} - // - //
- //
- // ${rowsHtml} - //
- //
`; - // } - - // // --- HANYA render multipleLayout jika ADA multiQs! - // let multipleLayout = ''; - // if (multiQs.length > 0) { - // multipleLayout = ` - // `; - // } - - // // --- Render final HTML ke DOM - // const html = ` - //
- //
- //
- // - //
- //
- //
- //
- //

${data[0].activity_desc}

- // ${allHtml} - // ${multipleLayout} - //
- // - //
- //
- //
- //
- // `; - - // $('#accordion-4').html(html); - - // // --- Handler Remove Card - // function refreshRemoveButtons() { - // const cards = $('#multiple-container .multiple-card'); - // if (cards.length === 1) { - // cards.find('.remove-card').addClass('d-none'); - // } else { - // cards.find('.remove-card').removeClass('d-none'); - // } - // } - - // // --- Event Handler, hanya aktif jika multiQs.length > 0 - // if (multiQs.length > 0) { - // $('#accordion-4').off('click', '#add-group').on('click', '#add-group', function() { - // const idx = $('#multiple-container .multiple-card').length; - // $('#multiple-container').append(makeMultipleCard(idx)); - // refreshRemoveButtons(); - // updateConditionalQuestions(); - // }); - // $('#accordion-4').off('click', '.remove-card').on('click', '.remove-card', function() { - // $(this).closest('.multiple-card').remove(); - // refreshRemoveButtons(); - // updateConditionalQuestions(); - // }); - // } - - // // --- Handler untuk select.form (show/hide desc di bawah select) - // $('#accordion-4').on('change', 'select.question-input', function() { - // const $select = $(this); - // const seq = $select.data('sequence'); - // const val = $select.val(); - // $select.closest('.question-group').find('.form-desc').hide(); - // $select.closest('.question-group').find(`.form-desc[data-form="${val}"]`).show(); - - // updateConditionalQuestions(); - // }); - - // // --- Logic tampil Card Data 1 (dan tombol) hanya jika multiQs.length > 0 - // function checkShowCardData1() { - // console.log(allowedMethodValue); - // if (multiQs.length === 0) return; // Tidak ada card, skip. - - // // -- Logic show/hide sesuai method & question_plus - // // if (!methodSequence) return; - // const methodVal = $(`[name="activity_data_${methodSequence}[0]"]`).val(); - - // if(methodVal) { - // if (!allowedMethodValue || allowedMethodValue === '') { - // if (methodVal && methodVal !== '') { - // $('#card-data-1-wrapper').show(); - // $('#add-group').show(); - // } else { - // $('#card-data-1-wrapper').hide(); - // $('#add-group').hide(); - // } - // return; - // } - // if (methodVal && String(methodVal) === String(allowedMethodValue)) { - // $('#card-data-1-wrapper').show(); - // $('#add-group').show(); - // } else { - // $('#card-data-1-wrapper').hide(); - // $('#add-group').hide(); - // } - // } else { - // $('#card-data-1-wrapper').show(); - // $('#add-group').show(); - // } - // } - - // // --- Panggil checkShowCardData1 saat method berubah, jika ada multiQs - // if (multiQs.length > 0 && methodSequence) { - // $('#accordion-4').on('change', `select[name="activity_data_${methodSequence}[0]"]`, function() { - // checkShowCardData1(); - // }); - // } - - // // --- Conditional logic show/hide pertanyaan - // function updateConditionalQuestions() { - // // Untuk single (bukan multiple-card) - // $('.question-group').each(function() { - // const seq = $(this).find('.question-row').data('sequence'); - // const q = questionMap[seq]; - // if (q && q.ad_sequence) { - // // Parent - // const parentSeq = q.ad_sequence; - // let parentVal = $(`[name="activity_data_${parentSeq}[0]"]`).val(); - // if (typeof parentVal === "undefined") parentVal = ''; - // const shouldShow = String(parentVal) === String(q.question_plus); - // allowedMethodValue = String(parentVal); - // $(this).toggle(shouldShow); - // if (!shouldShow) { - // $(this).find('input,select').val(''); - // $(this).find('.form-desc').hide(); - // } - // } - // }); - - // // Untuk multiple card (hanya jika ada multiQs) - // if (multiQs.length > 0) { - // $('#multiple-container .multiple-card').each(function(cardIdx) { - // $(this).find('.question-group').each(function() { - // const seq = $(this).find('.question-row').data('sequence'); - // const q = questionMap[seq]; - // if (q && q.ad_sequence) { - // const parentSeq = q.ad_sequence; - // let parentVal = $(`[name="activity_data_${parentSeq}[0]"]`).val(); - // const shouldShow = String(parentVal) === String(q.question_plus); - // $(this).toggle(shouldShow); - // if (!shouldShow) { - // $(this).find('input,select').val(''); - // $(this).find('.form-desc').hide(); - // } - // } - // }); - // }); - // } - - // checkShowCardData1(); - // } - - // // --- Init on load - // $('.form-desc-list').each(function() { - // $(this).find('.form-desc').hide(); - // const $select = $(this).closest('.question-group').find('select.question-input'); - // const val = $select.val(); - // if (val) { - // $(this).find(`.form-desc[data-form="${val}"]`).show(); - // } - // }); - // if (multiQs.length > 0) refreshRemoveButtons(); - // updateConditionalQuestions(); - - // // --- Handler untuk semua input change - // $('#accordion-4').on('change', '.question-input', function() { - // updateConditionalQuestions(); - // }); - - // }) - // .fail((xhr, status, error) => { - // console.error('Gagal mengambil pertanyaan:', status, error); - // $('#accordion-4').html( - // '

Terjadi kesalahan saat memuat pertanyaan.

' - // ); - // }); - // } - function loadQuestion(mitigation_id) { $('#section4').show(); $('#accordion-4').html('

Loading...

');