|
|
<!DOCTYPE html><html lang="en" dir="ltr"><html xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{fragments/modules/base/head :: head}"></head><style> body { background-color: #f8f9fa; /* font-family: Arial, sans-serif;*/ }
.header { font-size: 22px; font-weight: bold; margin-bottom: 20px; }
.table { border: 1px solid #dee2e6; }
.table th, .table td { border: 1px solid #dee2e6; padding: 10px; }
.section-title { font-size: 18px; font-weight: bold; margin-top: 20px; border-bottom: 2px solid #007bff; padding-bottom: 5px; }
.form-group { margin-top: 15px; }
.radio-group { display: flex; gap: 20px; margin-top: 10px; } .custom-card-wrapper { padding: 0; margin-left: -233px;}
@media (max-width: 768px) { .custom-card-wrapper { margin-left: 0; padding: 0 15px; /* Optional: adds spacing on small screens */ }}.kitchen-data-wrapper { padding: 18px; margin-top: -58px; margin-left: -256px;}
@media (max-width: 768px) { .kitchen-data-wrapper { margin-left: 0; padding: 15px; }}
</style>
<body> <div class="wrapper"> <header th:replace="~{fragments/modules/base/header :: header}"></header> <div class="page-wrap"> <div th:replace="~{fragments/modules/base/menu :: menu}"></div> <div class="card"> <div class="main-content" style="background-color: white;"> <div class="container"> <!-- Card 2: Other Details --> <div class="col-md-12"> <div class="kitchen-data-wrapper">
<div class="card-header"><b>CMBFS-Kitchen</b></div>
<div id="kitchenDataContainer" style="display: none; padding: 15px;"> <table class="table table-bordered"> <tr> <th>CMBFS Present</th> <td id="td_k_cmbfs"></td> <th>CMBFS Building</th> <td id="td_k_cmbfs_building"></td> </tr> <tr> <th>Noon Meal Present</th> <td id="td_k_noon"></td> <th>Noon Meal Building</th> <td id="td_k_noon_building"></td> </tr> <tr> <th>Vegetable Garden</th> <td id="td_k_veg"></td> <th>Anganwadi Present</th> <td id="td_k_ang"></td> </tr> <tr> <th>Anganwadi Unique No</th> <td id="td_k_ang_unique"></td> <th>Anganwadi Building</th> <td id="td_k_ang_building"></td> </tr> </table> <div class="text-center"> <button type="button" class="btn btn-primary" id="editKitchenBtn">Update</button> </div> </div>
</div>
<!-- This block wraps the form --> <div id="kitchenFormContainer" style="display: none;"> <!-- Card 2: Other Details --> <div class="col-md-12"> <div class="custom-card-wrapper"> <div class="card-header"><b>CMBFS-Kitchens</b></div> <div class="row" style=" padding: 15px;"> <div class="col-md-4 form-group"> <label>Is CMBFS-Kitchen Present <span class="text-danger">*</span></label> <div class="radio-group"> <input type="radio" id="cmbfskitchenPresentYes" name="cmbfskitchenPresent" value="1"> Yes <input type="radio" id="cmbfskitchenPresentNo" name="cmbfskitchenPresent" value="0"> No </div> </div>
<div class="col-md-4 form-group" id="CMBFSfield" style="display: none;"> <label>Individual Building Present <span class="text-danger">*</span></label> <div class="radio-group"> <input type="radio" id="cmbfskitchenBuildingYes" name="cmbfskitchenBuilding" value="1"> Yes <input type="radio" id="cmbfskitchenBuildingNo" name="cmbfskitchenBuilding" value="0"> No </div> </div>
</div>
</div> </div>
<!-- card 2 --> <div class="col-md-12"> <div class="custom-card-wrapper"> <div class="card-header"><b>Noon Meal Center</b></div> <div class="row" style=" padding: 15px;"> <div class="col-md-4 form-group"> <label>Is Noon Meal Kitchen Present <span class="text-danger">*</span></label> <div class="radio-group"> <input type="radio" id="noonMealpresentYes" name="noonMealpresent" value="1"> Yes <input type="radio" id="noonMealpresentNo" name="noonMealpresent" value="0"> No </div> </div> <div id="noonMealfield" style="display: none;" class="col-12"> <div class="row"> <div class="col-md-6 form-group"> <label>Individual Building Present <span class="text-danger">*</span></label> <div class="radio-group"> <input type="radio" id="noonMealBuildingYes" name="noonMealBuilding" value="1"> Yes <input type="radio" id="noonMealBuildingNo" name="noonMealBuilding" value="0"> No </div> </div> <div class="col-md-6 form-group"> <label>Presence of Vegetable Garden <span class="text-danger">*</span></label> <div class="radio-group"> <input type="radio" id="vegetableGardenYes" name="vegetableGarden" value="1"> Yes <input type="radio" id="vegetableGardenNo" name="vegetableGarden" value="0"> No </div> </div> </div> </div> </div>
</div> </div>
<!-- card -3 -->
<div class="col-md-12"> <div class="custom-card-wrapper"> <div class="card-header"><b>Anganwadi</b></div> <div class="row" style=" padding: 15px;"> <div class="col-md-4 form-group"> <label>Is Anganwadi Present <span class="text-danger">*</span></label> <div class="radio-group"> <input type="radio" id="anganwadiPresentYes" name="anganwadiPresent" value="1"> Yes <input type="radio" id="anganwadiPresentNo" name="anganwadiPresent" value="0"> No </div> </div> <div id="anganwadifield" style="display: none" class="col-12"> <div class="row"> <div class="col-md-6 form-group"> <label>Anganwadi unique Number<span class="text-danger">*</span></label> <input type="text" class="form-control" placeholder="Enter Anganwadi unique Number" id="anganwadiNumber" required /> </div> <div class="col-md-4 form-group"> <label>Individual Building Present <span class="text-danger">*</span></label> <div class="radio-group"> <input type="radio" id="anganwadiBuildingYes" name="anganwadiBuilding" value="1"> Yes <input type="radio" id="anganwadiBuildingNo" name="anganwadiBuilding" value="0"> No </div> </div> </div> </div> </div>
<div class="card-footer text-center"> <button type="submit" class="btn btn-primary" id="requestSubmitBtn"><i class="ik ik-save"></i>Submit </button> <button type="reset" class="btn btn-secondary mr-2" id="resetButton"><i class="ik ik-refresh-cw"></i>Reset </button>
</div> </div> </div>
</div> <div id="pageLoader" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.8); z-index: 9999; text-align: center;"> <div style="position: relative; top: 50%; transform: translateY(-50%);"> <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;"> <span class="sr-only">Loading...</span> </div> <!-- Add the 'Please wait' text below the spinner --> <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p> </div> </div>
</div> </div> </div> <!-- Modal --> <div class="modal fade" id="editKitchenModal" tabindex="-1" aria-labelledby="editKitchenModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <form id="kitchenForm"> <div class="modal-header"> <h5 class="modal-title">Edit Kitchen Details</h5> <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close"><span aria-hidden>×</span></button> </div> <div class="modal-body">
<!-- Kitchen Form --> <div class="row mb-3"> <div class="col-md-6"> <label>Is CMBFS-Kitchen Present? *</label> <div class="radio-group"> <input type="radio" name="modalcmbfskitchenPresent" value="1"> Yes <input type="radio" name="modalcmbfskitchenPresent" value="0"> No </div> </div> <div class="col-md-6" id="modalCMBFSfield" style="display: none;"> <label>Individual Building Present *</label> <div class="radio-group"> <input type="radio" name="modalcmbfskitchenBuilding" value="1"> Yes <input type="radio" name="modalcmbfskitchenBuilding" value="0"> No </div> </div> </div>
<div class="row mb-3"> <div class="col-md-6"> <label>Is Noon Meal Kitchen Present? *</label> <div class="radio-group"> <input type="radio" name="modalnoonMealpresent" value="1"> Yes <input type="radio" name="modalnoonMealpresent" value="0"> No </div> </div> </div>
<div class="row mb-3" id="modalnoonMealfield" style="display: none;"> <div class="col-md-6"> <label>Individual Building Present *</label> <div class="radio-group"> <input type="radio" name="modalnoonMealBuilding" value="1"> Yes <input type="radio" name="modalnoonMealBuilding" value="0"> No </div> </div> <div class="col-md-6"> <label>Presence of Vegetable Garden *</label> <div class="radio-group"> <input type="radio" name="modalvegetableGarden" value="1"> Yes <input type="radio" name="modalvegetableGarden" value="0"> No </div> </div> </div>
<div class="row mb-3"> <div class="col-md-6"> <label>Is Anganwadi Present? *</label> <div class="radio-group"> <input type="radio" name="modalanganwadiPresent" value="1"> Yes <input type="radio" name="modalanganwadiPresent" value="0"> No </div> </div> </div>
<div class="row mb-3" id="modalanganwadifield" style="display: none;"> <div class="col-md-6"> <label>Anganwadi Unique Number *</label> <input type="text" id="modalanganwadiNumber" class="form-control" /> </div> <div class="col-md-6"> <label>Individual Building Present *</label> <div class="radio-group"> <input type="radio" name="modalanganwadiBuilding" value="1"> Yes <input type="radio" name="modalanganwadiBuilding" value="0"> No </div> </div> </div>
</div> <div class="modal-footer"> <button type="submit" class="btn btn-primary" id="updateSubmitBtn">Submit</button> <button type="reset" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> </div> </form> </div> </div> </div> </div> </div> </div>
<script th:replace="~{fragments/modules/base/script :: script}"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script> <script type="text/javascript">
$(document).ready(function () {
document.querySelectorAll('input[name="cmbfskitchenPresent"]').forEach(radio => { radio.addEventListener('change', function () { const CMBFSfieldDiv = document.getElementById('CMBFSfield'); if (this.value === '1') { CMBFSfieldDiv.style.display = 'block'; // Show the input field } else { CMBFSfieldDiv.style.display = 'none'; // Hide the input field document.querySelectorAll('input[name="cmbfskitchenBuilding"]').forEach(radio => { radio.checked = false; }); } }); });
document.querySelectorAll('input[name="noonMealpresent"]').forEach(radio => { radio.addEventListener('change', function () { const noonMealfieldDiv = document.getElementById('noonMealfield'); if (this.value === '1') { noonMealfieldDiv.style.display = 'block'; // Show the input field } else { noonMealfieldDiv.style.display = 'none'; // Hide the input field document.querySelectorAll('input[name="noonMealBuilding"]').forEach(radio => { radio.checked = false; }); document.querySelectorAll('input[name="vegetableGarden"]').forEach(radio => { radio.checked = false; }); } }); });
document.querySelectorAll('input[name="anganwadiPresent"]').forEach(radio => { radio.addEventListener('change', function () { const anganwadifieldDiv = document.getElementById('anganwadifield'); if (this.value === '1') { anganwadifieldDiv.style.display = 'block'; // Show the input field } else { anganwadifieldDiv.style.display = 'none'; // Hide the input field document.querySelectorAll('input[name="anganwadiBuilding"]').forEach(radio => { radio.checked = false; }); document.getElementById('anganwadiNumber').value = ''; } }); }); $("input[name='modalcmbfskitchenPresent']").change(function () { if ($(this).val() === "1") { $("#modalCMBFSfield").show(); } else { $("#modalCMBFSfield").hide(); } });
// 2. Toggle Noon Meal building and garden fields $("input[name='modalnoonMealpresent']").change(function () { if ($(this).val() === "1") { $("#modalnoonMealfield").show(); } else { $("#modalnoonMealfield").hide(); } });
// 3. Toggle Anganwadi fields $("input[name='modalanganwadiPresent']").change(function () { if ($(this).val() === "1") { $("#modalanganwadifield").show(); } else { $("#modalanganwadifield").hide(); } });
});
$(document).ready(function () { const urlParams = new URLSearchParams(window.location.search); const schoolId = urlParams.get("schoolId"); $('input[name="school_id"]').val(schoolId); function toggleField(radioGroup, targetDiv, resetSelectors = []) { document.querySelectorAll(`input[name="${radioGroup}"]`).forEach(radio => { radio.addEventListener('change', function () { if (this.value === '1') { document.getElementById(targetDiv).style.display = 'block'; } else { document.getElementById(targetDiv).style.display = 'none'; resetSelectors.forEach(sel => { $(sel).prop('checked', false); if ($(sel).is('input[type="text"]')) $(sel).val(''); }); } }); }); }
toggleField('cmbfskitchenPresent', 'CMBFSfield', ['input[name="cmbfskitchenBuilding"]']); toggleField('noonMealpresent', 'noonMealfield', ['input[name="noonMealBuilding"]', 'input[name="vegetableGarden"]']); toggleField('anganwadiPresent', 'anganwadifield', ['input[name="anganwadiBuilding"]', '#anganwadiNumber']);
// ---------------- Data Fetch ------------------- $.ajax({ url: '/gcc/api/gccschool/schoolproperty/checkKitchenDetails', type: 'GET', data: {school_id: schoolId}, success: function (response) { const hasValidData = response && response[0] && response[0].Data && Object.values(response[0].Data).some(val => val !== null && val !== false && val !== "");
if (hasValidData) { const data = response[0].Data;
//const yesNo = val => val === true ? 'Yes' : 'No'; const yesNo = val => val === true ? 'Yes' : val === false ? 'No' : '-';
$('#td_k_cmbfs').text(yesNo(data.is_cmbfs)); $('#td_k_cmbfs_building').text(yesNo(data.is_cmbfsIndividual)); $('#td_k_noon').text(yesNo(data.is_noonmeal)); $('#td_k_noon_building').text(yesNo(data.is_noonIndividual)); $('#td_k_veg').text(yesNo(data.is_vegGarden)); $('#td_k_ang').text(yesNo(data.is_anganwadi)); $('#td_k_ang_unique').text(data.anganwadi_unique || '-'); $('#td_k_ang_building').text(yesNo(data.is_anganwadiIndividual));
$('#kitchenDataContainer').show(); // ✅ Show table $('#kitchenFormContainer').hide(); // ❌ Hide form $('#editKitchenBtn').data('kitchenData', data); } else { $('#kitchenDataContainer').hide(); // ❌ Hide table $('#kitchenFormContainer').show(); // ✅ Show form } }, error: function () { $('#kitchenDataContainer').hide(); // ❌ hide table $('#kitchenFormContainer').show(); // ✅ show form } }); $('input[name="modalanganwadiPresent"]').on('change', function () { if (this.value === '1') { $('#editKitchenModalAnganwadiField').show(); } else { $('#editKitchenModalAnganwadiField').hide();
// Clear the Anganwadi Building radio buttons $('input[name="modalanganwadiBuilding"]').prop('checked', false);
// Clear the Anganwadi Number field $('#modalanganwadiNumber').val(''); } }); $('input[name="modalnoonMealpresent"]').on('change', function () { if (this.value === '1') { $('#editKitchenModalNoonField').show(); } else { $('#editKitchenModalNoonField').hide(); $('input[name="modalnoonMealBuilding"]').prop('checked', false); $('input[name="modalvegetableGarden"]').prop('checked', false); } }); $('input[name="modalcmbfskitchenPresent"]').on('change', function () { if (this.value === '1') { $('#editKitchenModalCMBFSfield').show(); } else { $('#editKitchenModalCMBFSfield').hide(); $('input[name="modalcmbfskitchenBuilding"]').prop('checked', false); } });
// ---------------- On Update Button ------------------- $('#editKitchenBtn').click(function () { const data = $(this).data('kitchenData');
$(`input[name="modalcmbfskitchenPresent"][value="${data.is_cmbfs ? 1 : 0}"]`).prop('checked', true); $(`input[name="modalcmbfskitchenBuilding"][value="${data.is_cmbfsIndividual ? 1 : 0}"]`).prop('checked', true);
$(`input[name="modalnoonMealpresent"][value="${data.is_noonmeal ? 1 : 0}"]`).prop('checked', true); $(`input[name="modalnoonMealBuilding"][value="${data.is_noonIndividual ? 1 : 0}"]`).prop('checked', true); $(`input[name="modalvegetableGarden"][value="${data.is_vegGarden ? 1 : 0}"]`).prop('checked', true);
$(`input[name="modalanganwadiPresent"][value="${data.is_anganwadi ? 1 : 0}"]`).prop('checked', true); $(`input[name="modalanganwadiBuilding"][value="${data.is_anganwadiIndividual ? 1 : 0}"]`).prop('checked', true); $('#modalanganwadiNumber').val(data.anganwadi_unique || '');
// 👇 Force the toggle to display the dependent fields $(`#editKitchenModal input[name="modalcmbfskitchenPresent"]:checked`).trigger('change'); $(`#editKitchenModal input[name="modalnoonMealpresent"]:checked`).trigger('change'); $(`#editKitchenModal input[name="modalanganwadiPresent"]:checked`).trigger('change');
// Show modal const kitchenModal = new bootstrap.Modal(document.getElementById('editKitchenModal')); kitchenModal.show(); });
// --- Toggle logic for modal form fields inside editKitchenModal --- function toggleModalField(radioGroupName, fieldId, resetSelectors = []) { $(`#editKitchenModal input[name="${radioGroupName}"]`).on('change', function () { if (this.value === '1') { $(`#editKitchenModal #${fieldId}`).show(); } else { $(`#editKitchenModal #${fieldId}`).hide(); resetSelectors.forEach(sel => { $(`#editKitchenModal ${sel}`).prop('checked', false); if ($(sel).is('input[type="text"]')) $(sel).val(''); }); } }); }
// Apply for each group toggleModalField('cmbfskitchenPresent', 'CMBFSfield', ['input[name="cmbfskitchenBuilding"]']); toggleModalField('noonMealpresent', 'noonMealfield', ['input[name="noonMealBuilding"]', 'input[name="vegetableGarden"]']); toggleModalField('anganwadiPresent', 'anganwadifield', ['input[name="anganwadiBuilding"]', '#anganwadiNumber']);
document.getElementById('anganwadiNumber').addEventListener('input', function () { // Keep only alphanumeric characters this.value = this.value.replace(/[^a-zA-Z0-9]/g, ''); }); document.getElementById('modalanganwadiNumber').addEventListener('input', function () { // Keep only alphanumeric characters this.value = this.value.replace(/[^a-zA-Z0-9]/g, ''); });
$(document).on('click', '#requestSubmitBtn', function () {
let cmbfskitchenPresent = $('input[name="cmbfskitchenPresent"]:checked').val(); let cmbfskitchenBuilding = null; if (cmbfskitchenPresent === '1') { cmbfskitchenBuilding = $('input[name="cmbfskitchenBuilding"]:checked').val(); if (!cmbfskitchenBuilding) { Swal.fire({ icon: 'warning', title: 'Validation Error!', text: 'Individual Building Present is required for CMBFS kitchen .', allowOutsideClick: false, // Disable clicking outside the modal to close it allowEscapeKey: false, // Disable escape key to close the modal allowEnterKey: false, // Disable enter key to close the modal showConfirmButton: true }); return; } }
let noonMealpresent = $('input[name="noonMealpresent"]:checked').val(); let noonMealBuilding = null; let vegetableGarden = null; if (noonMealpresent === '1') { noonMealBuilding = $('input[name="noonMealBuilding"]:checked').val(); if (!noonMealBuilding) { Swal.fire({ icon: 'warning', title: 'Validation Error!', text: 'Individual Building Present is required for Noon Meal Center .', allowOutsideClick: false, // Disable clicking outside the modal to close it allowEscapeKey: false, // Disable escape key to close the modal allowEnterKey: false, // Disable enter key to close the modal showConfirmButton: true }); return; }
vegetableGarden = $('input[name="vegetableGarden"]:checked').val(); if (!vegetableGarden) { Swal.fire({ icon: 'warning', title: 'Validation Error!', text: 'Presence of Vegetable Garden is required .', allowOutsideClick: false, // Disable clicking outside the modal to close it allowEscapeKey: false, // Disable escape key to close the modal allowEnterKey: false, // Disable enter key to close the modal showConfirmButton: true }); return; } }
let anganwadiPresent = $('input[name="anganwadiPresent"]:checked').val(); let anganwadiBuilding = null; let anganwadiNumber = null; if (anganwadiPresent === '1') { anganwadiNumber = $('#anganwadiNumber').val(); anganwadiBuilding = $('input[name="anganwadiBuilding"]:checked').val();
if (!anganwadiNumber) { Swal.fire({ icon: 'warning', title: 'Validation Error!', text: 'AnganwadiNumber is required', allowOutsideClick: false, // Disable clicking outside the modal to close it allowEscapeKey: false, // Disable escape key to close the modal allowEnterKey: false, // Disable enter key to close the modal showConfirmButton: true }); return; } if (!anganwadiBuilding) { Swal.fire({ icon: 'warning', title: 'Validation Error!', text: 'Individual Building Present is required for Anganwadi.', allowOutsideClick: false, // Disable clicking outside the modal to close it allowEscapeKey: false, // Disable escape key to close the modal allowEnterKey: false, // Disable enter key to close the modal showConfirmButton: true }); return; }
}
// let school_id = 1;
console.log("cmbfskitchenPresent=", cmbfskitchenPresent); console.log("anganwadiBuilding=", anganwadiBuilding); console.log("noonMealpresent=", noonMealpresent); console.log("noonMealBuilding=", noonMealBuilding); console.log("vegetableGarden=", vegetableGarden); console.log("anganwadiPresent=", anganwadiPresent); console.log("anganwadiNumber=", anganwadiNumber); console.log("anganwadiBuilding=", anganwadiBuilding); console.log("school_id=", schoolId);
// Validate inputs let fields = { "Is CMBFS-Kitchen Present": cmbfskitchenPresent, "Is noonMealpresent Present": noonMealpresent, "Is Anganwadi Present": anganwadiPresent, };
for (let key in fields) { if (!fields[key] || isNaN(fields[key])) { Swal.fire({ icon: 'info', title: 'Validation Error', text: `Please enter ${key}.`, allowOutsideClick: false, // Disable clicking outside the modal to close it allowEscapeKey: false, // Disable escape key to close the modal allowEnterKey: false, // Disable enter key to close the modal showConfirmButton: true }); return; // Stop execution if validation fails } }
// Prepare Data for AJAX let requestData = { is_cmbfs: cmbfskitchenPresent, is_cmbfsIndividual: cmbfskitchenBuilding, is_noonmeal: noonMealpresent, is_noonIndividual: noonMealBuilding, is_vegGarden: vegetableGarden, is_anganwadi: anganwadiPresent, anganwadi_unique: anganwadiNumber || null, is_anganwadiIndividual: anganwadiBuilding, school_id: schoolId };
$('#requestSubmitBtn').prop('disabled', true).text('Processing...'); $('#pageLoader').show(); $.ajax({ url: '/gcc/api/gccschool/schoolproperty/saveKitchen', type: 'POST', contentType: 'application/x-www-form-urlencoded', data: $.param(requestData), success: function (response) { $('#pageLoader').hide(); $('#requestSubmitBtn').prop('disabled', false).text('Submit'); Swal.fire({ icon: 'success', title: 'Success', text: response, allowOutsideClick: false, allowEscapeKey: false, allowEnterKey: false, confirmButtonText: 'OK' }).then((result) => { if (result.isConfirmed) { $('#requestSubmitBtn').prop('disabled', false).text('Submit'); location.reload(); } }); }, error: function (xhr, status, error) { $('#pageLoader').hide(); $('#requestSubmitBtn').prop('disabled', false).text('Submit'); let errorMessage = xhr.responseText;
Swal.fire({ icon: 'error', title: 'Error', text: errorMessage, allowOutsideClick: false, // Disable clicking outside the modal to close it allowEscapeKey: false, // Disable escape key to close the modal allowEnterKey: false, // Disable enter key to close the modal showConfirmButton: true }); console.error('Error:', xhr.responseText); } });
});
function resetFacilityFields() { console.log("Reset button clicked - Facilities");
// Uncheck all radio buttons $('input[type="radio"]').prop('checked', false);
// Clear input fields $('#anganwadiNumber').val('');
// Hide dependent sections $('#CMBFSfield, #noonMealfield, #anganwadifield').hide(); }
// Event Listener for Reset Button $(document).on('click', '#resetButton', function (event) { event.preventDefault(); resetFacilityFields(); }); $(document).on('click', '#updateSubmitBtn', function (e) { e.preventDefault(); submitModalKitchenUpdate(); });
function submitModalKitchenUpdate() {
let cmbfskitchenPresent = $('#editKitchenModal input[name="modalcmbfskitchenPresent"]:checked').val(); let cmbfskitchenBuilding = cmbfskitchenPresent === '1' ? $('#editKitchenModal input[name="modalcmbfskitchenBuilding"]:checked').val() : null; /*if (cmbfskitchenPresent === '1' && !cmbfskitchenBuilding) { return Swal.fire('Validation Error!', 'Individual Building Present is required for CMBFS kitchen.', 'warning'); }*/ if (cmbfskitchenPresent === '1' && !cmbfskitchenBuilding) { return Swal.fire({ title: 'Validation Error!', text: 'Individual Building Present is required for CMBFS kitchen.', icon: 'warning', allowOutsideClick: false, allowEscapeKey: false, allowEnterKey: false, showConfirmButton: true }); }
let noonMealpresent = $('#editKitchenModal input[name="modalnoonMealpresent"]:checked').val(); let noonMealBuilding = noonMealpresent === '1' ? $('#editKitchenModal input[name="modalnoonMealBuilding"]:checked').val() : null; let vegetableGarden = noonMealpresent === '1' ? $('#editKitchenModal input[name="modalvegetableGarden"]:checked').val() : null; /*if (noonMealpresent === '1' && (!noonMealBuilding || !vegetableGarden)) { return Swal.fire('Validation Error!', 'Fields under Noon Meal Center are required.', 'warning'); }*/ if (noonMealpresent === '1' && (!noonMealBuilding || !vegetableGarden)) { return Swal.fire({ title: 'Validation Error!', text: 'Fields under Noon Meal Center are required.', icon: 'warning', allowOutsideClick: false, allowEscapeKey: false, allowEnterKey: false, showConfirmButton: true }); }
let anganwadiPresent = $('#editKitchenModal input[name="modalanganwadiPresent"]:checked').val(); let anganwadiBuilding = anganwadiPresent === '1' ? $('#editKitchenModal input[name="modalanganwadiBuilding"]:checked').val() : null; let anganwadiNumber = anganwadiPresent === '1' ? $('#editKitchenModal #modalanganwadiNumber').val() : null; /*if (anganwadiPresent === '1' && (!anganwadiBuilding || !anganwadiNumber)) { return Swal.fire('Validation Error!', 'All Anganwadi fields are required.', 'warning'); }*/ if (anganwadiPresent === '1' && (!anganwadiBuilding || !anganwadiNumber)) { return Swal.fire({ title: 'Validation Error!', text: 'All Anganwadi fields are required.', icon: 'warning', allowOutsideClick: false, allowEscapeKey: false, allowEnterKey: false, showConfirmButton: true }); }
const requestData = { is_cmbfs: cmbfskitchenPresent, is_cmbfsIndividual: cmbfskitchenBuilding, is_noonmeal: noonMealpresent, is_noonIndividual: noonMealBuilding, is_vegGarden: vegetableGarden, is_anganwadi: anganwadiPresent, anganwadi_unique: anganwadiNumber || null, is_anganwadiIndividual: anganwadiBuilding, school_id: schoolId };
$('#updateSubmitBtn').prop('disabled', true).text('Updating...'); $('#pageLoader').show();
$.ajax({ url: '/gcc/api/gccschool/schoolproperty/updateKitchenDetails', type: 'POST', contentType: 'application/x-www-form-urlencoded', data: $.param(requestData), success: function (response) { $('#pageLoader').hide(); $('#updateSubmitBtn').prop('disabled', false).text('Submit'); //Swal.fire('Success', response, 'success'). Swal.fire({ title: 'Success', text: 'Kitchen details updated successfully!!', icon: 'success', allowOutsideClick: false, allowEscapeKey: false, allowEnterKey: false, showConfirmButton: true }) .then(() => { $('#editKitchenModal').modal('hide'); location.reload(); }); }, error: function (xhr) { $('#pageLoader').hide(); $('#updateSubmitBtn').prop('disabled', false).text('Submit'); //Swal.fire('Error', xhr.responseText || 'Failed to update.', 'error'); Swal.fire({ title: 'Error', text: xhr.responseText || 'Failed to update.', icon: 'error', allowOutsideClick: false, allowEscapeKey: false, allowEnterKey: false, showConfirmButton: true }); } }); } }); </script>
</body>
</html>
|