update
parent
039c3df3ac
commit
c599242bc8
|
|
@ -1172,365 +1172,6 @@
|
||||||
(subKategori || sessionSubKategori);
|
(subKategori || sessionSubKategori);
|
||||||
}
|
}
|
||||||
|
|
||||||
// function loadQuestion(mitigation_id) {
|
|
||||||
// $('#section4').show();
|
|
||||||
// $('#accordion-4').html('<p class="text-muted ml-1">Loading...</p>');
|
|
||||||
|
|
||||||
// $.get('/mitigasi/form-mitigasi-question', { mitigation_id })
|
|
||||||
// .done(data => {
|
|
||||||
// if (!data || !data.length) {
|
|
||||||
// $('#accordion-4').html(
|
|
||||||
// '<p class="text-muted ml-1" style="font-size:12px">Pertanyaan tidak tersedia.</p>'
|
|
||||||
// );
|
|
||||||
// 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 = `<input type="text"
|
|
||||||
// name="activity_data_${q.sequence}[${idx}]"
|
|
||||||
// class="form-control mb-2 w-95 question-input"
|
|
||||||
// data-sequence="${q.sequence}" data-parent="${q.ad_sequence || ''}"
|
|
||||||
// ${q.is_required ? 'required' : ''}>`;
|
|
||||||
// } else if (q.type === 'form' || q.type === 'method') {
|
|
||||||
// inputEl = `
|
|
||||||
// <select name="activity_data_${q.sequence}[${idx}]"
|
|
||||||
// class="form-control mb-2 w-95 question-input"
|
|
||||||
// data-sequence="${q.sequence}" data-parent="${q.ad_sequence || ''}"
|
|
||||||
// ${q.is_required ? 'required' : ''}>
|
|
||||||
// ${q.choices.map(c => `<option value="${c.form}">${c.form}</option>`).join('')}
|
|
||||||
// </select>
|
|
||||||
// `;
|
|
||||||
// } else {
|
|
||||||
// inputEl = `<select name="activity_data_${q.sequence}[${idx}]"
|
|
||||||
// class="form-control mb-2 w-95 question-input"
|
|
||||||
// data-sequence="${q.sequence}" data-parent="${q.ad_sequence || ''}"
|
|
||||||
// ${q.is_required ? 'required' : ''}>
|
|
||||||
// ${q.choices.map(c => `<option>${c}</option>`).join('')}
|
|
||||||
// </select>`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const removeBtn = showRemove
|
|
||||||
// ? `<button type="button" class="btn btn-danger btn-sm ml-2 remove-row">Hapus</button>`
|
|
||||||
// : `<button type="button" class="btn btn-danger btn-sm ml-2 remove-row d-none">Hapus</button>`;
|
|
||||||
|
|
||||||
// return `
|
|
||||||
// <div class="mb-2 row-input question-row"
|
|
||||||
// data-sequence="${q.sequence}" data-parent="${q.ad_sequence || ''}" data-question-plus="${q.question_plus || ''}">
|
|
||||||
// ${inputEl}
|
|
||||||
// ${removeBtn}
|
|
||||||
// </div>`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // --- Build HTML utama
|
|
||||||
// let allHtml = '';
|
|
||||||
// data.forEach((q, idx) => {
|
|
||||||
// // --- Build unit/desc
|
|
||||||
// let unitOrDesc = '';
|
|
||||||
// if (q.type === 'form' || q.type === 'method') {
|
|
||||||
// unitOrDesc = `
|
|
||||||
// <div class="form-desc-list mt-1" data-sequence="${q.sequence}">
|
|
||||||
// ${q.choices.map(c => `
|
|
||||||
// <p class="form-desc" data-form="${c.form}" style="display:none;font-size:12px;margin-bottom:0;">
|
|
||||||
// ${c.desc}
|
|
||||||
// </p>
|
|
||||||
// `).join('')}
|
|
||||||
// </div>`;
|
|
||||||
// } else if (q.units && q.units.length === 1) {
|
|
||||||
// unitOrDesc = `<input type="hidden" name="unit_${q.sequence}" value="${q.units[0]}">
|
|
||||||
// <span class="text-muted small ml-1">${q.units[0]}</span>`;
|
|
||||||
// } else if (q.units && q.units.length > 1) {
|
|
||||||
// unitOrDesc = `<select name="unit_${q.sequence}"
|
|
||||||
// class="form-control-sm d-inline-block w-auto unit-select mt-2" required>
|
|
||||||
// ${q.units.map(u => `<option>${u}</option>`).join('')}
|
|
||||||
// </select>`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!q.is_multiple) {
|
|
||||||
// allHtml += `
|
|
||||||
// <div class="form-group question-group" id="group-${q.sequence}" style="${q.ad_sequence ? 'display:none' : ''}">
|
|
||||||
// <label class="${q.is_required ? 'required-label' : ''} font-weight-bold">
|
|
||||||
// ${q.activity_data}
|
|
||||||
// </label>
|
|
||||||
// ${makeRow(q, 0, false)}
|
|
||||||
// ${unitOrDesc ? `<div class="mt-2">${unitOrDesc}</div>` : ''}
|
|
||||||
// </div>`;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // --- 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 = `
|
|
||||||
// <div class="form-desc-list mt-1" data-sequence="${q.sequence}">
|
|
||||||
// ${q.choices.map(c => `
|
|
||||||
// <p class="form-desc" data-form="${c.form}" style="display:none;font-size:12px;margin-bottom:0;">
|
|
||||||
// ${c.desc}
|
|
||||||
// </p>
|
|
||||||
// `).join('')}
|
|
||||||
// </div>`;
|
|
||||||
// } else if (q.units && q.units.length === 1) {
|
|
||||||
// unitOrDesc = `<input type="hidden" name="unit_${q.sequence}" value="${q.units[0]}">
|
|
||||||
// <span class="text-muted small ml-1">${q.units[0]}</span>`;
|
|
||||||
// } else if (q.units && q.units.length > 1) {
|
|
||||||
// unitOrDesc = `<select name="unit_${q.sequence}"
|
|
||||||
// class="form-control-sm d-inline-block w-auto unit-select mt-2" required>
|
|
||||||
// ${q.units.map(u => `<option>${u}</option>`).join('')}
|
|
||||||
// </select>`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return `
|
|
||||||
// <div class="form-group question-group" id="group-${q.sequence}-${idx}" style="${q.ad_sequence ? 'display:none' : ''}">
|
|
||||||
// <label class="${q.is_required ? 'required-label' : ''} font-weight-bold">
|
|
||||||
// ${q.activity_data}
|
|
||||||
// </label>
|
|
||||||
// <div class="multiple-input-group" data-sequence="${q.sequence}">
|
|
||||||
// ${makeRow(q, idx, false)}
|
|
||||||
// </div>
|
|
||||||
// ${unitOrDesc ? `<div class="mt-2">${unitOrDesc}</div>` : ''}
|
|
||||||
// </div>`;
|
|
||||||
// }).join('');
|
|
||||||
|
|
||||||
// return `
|
|
||||||
// <div class="card multiple-card" data-index="${idx}">
|
|
||||||
// <div class="card-header d-flex justify-content-between align-items-center">
|
|
||||||
// <strong>${title}</strong>
|
|
||||||
// <button type="button" class="btn btn-danger btn-delete btn-sm remove-card">
|
|
||||||
// Hapus Data
|
|
||||||
// </button>
|
|
||||||
// </div>
|
|
||||||
// <div class="card-body">
|
|
||||||
// ${rowsHtml}
|
|
||||||
// </div>
|
|
||||||
// </div>`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // --- HANYA render multipleLayout jika ADA multiQs!
|
|
||||||
// let multipleLayout = '';
|
|
||||||
// if (multiQs.length > 0) {
|
|
||||||
// multipleLayout = `
|
|
||||||
// <div id="card-data-1-wrapper" style="display:none">
|
|
||||||
// <div id="multiple-container">
|
|
||||||
// ${makeMultipleCard(0)}
|
|
||||||
// </div>
|
|
||||||
// <button type="button" id="add-group" class="btn btn-add-data add-row btn-sm mt-2" style="display:none">
|
|
||||||
// Tambah Data
|
|
||||||
// </button>
|
|
||||||
// </div>`;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // --- Render final HTML ke DOM
|
|
||||||
// const html = `
|
|
||||||
// <div class="card">
|
|
||||||
// <div class="card-header">
|
|
||||||
// <h5 class="mb-0">
|
|
||||||
// <button class="btn d-flex justify-content-between w-100 align-items-center form-title-accordion collapsed"
|
|
||||||
// data-toggle="collapse" data-target="#collapse6">
|
|
||||||
// ${data[0].title.toUpperCase()}
|
|
||||||
// <span class="arrow mr-2"><i class="bx bx-plus"></i></span>
|
|
||||||
// </button>
|
|
||||||
// </h5>
|
|
||||||
// </div>
|
|
||||||
// <div id="collapse6" class="collapse" data-parent="#accordion-4">
|
|
||||||
// <div class="card-body">
|
|
||||||
// <p class="text-muted small">${data[0].activity_desc}</p>
|
|
||||||
// ${allHtml}
|
|
||||||
// ${multipleLayout}
|
|
||||||
// <div class="mt-4 text-right">
|
|
||||||
// <button type="submit" id="final-submit" class="btn btn-submit px-4 py-2">
|
|
||||||
// Submit
|
|
||||||
// </button>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// </div>
|
|
||||||
// `;
|
|
||||||
|
|
||||||
// $('#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(
|
|
||||||
// '<p class="text-danger small">Terjadi kesalahan saat memuat pertanyaan.</p>'
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
function loadQuestion(mitigation_id) {
|
function loadQuestion(mitigation_id) {
|
||||||
$('#section4').show();
|
$('#section4').show();
|
||||||
$('#accordion-4').html('<p class="text-muted ml-1">Loading...</p>');
|
$('#accordion-4').html('<p class="text-muted ml-1">Loading...</p>');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue