You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

929 lines
33 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr">
  3. <html xmlns:th="http://www.thymeleaf.org">
  4. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  5. <style>
  6. body {
  7. background-color: #f8f9fa;
  8. /* font-family: Arial, sans-serif;*/
  9. }
  10. .header {
  11. font-size: 22px;
  12. font-weight: bold;
  13. margin-bottom: 20px;
  14. }
  15. .table {
  16. border: 1px solid #dee2e6;
  17. }
  18. .table th,
  19. .table td {
  20. border: 1px solid #dee2e6;
  21. padding: 10px;
  22. }
  23. .section-title {
  24. font-size: 18px;
  25. font-weight: bold;
  26. margin-top: 20px;
  27. border-bottom: 2px solid #007bff;
  28. padding-bottom: 5px;
  29. }
  30. .form-group {
  31. margin-top: 15px;
  32. }
  33. .radio-group {
  34. display: flex;
  35. gap: 20px;
  36. margin-top: 10px;
  37. }
  38. .custom-card-wrapper {
  39. padding: 0;
  40. margin-left: -233px;
  41. }
  42. @media (max-width: 768px) {
  43. .custom-card-wrapper {
  44. margin-left: 0;
  45. padding: 0 15px; /* Optional: adds spacing on small screens */
  46. }
  47. }
  48. .kitchen-data-wrapper {
  49. padding: 18px;
  50. margin-top: -58px;
  51. margin-left: -256px;
  52. }
  53. @media (max-width: 768px) {
  54. .kitchen-data-wrapper {
  55. margin-left: 0;
  56. padding: 15px;
  57. }
  58. }
  59. </style>
  60. <body>
  61. <div class="wrapper">
  62. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  63. <div class="page-wrap">
  64. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  65. <div class="card">
  66. <div class="main-content" style="background-color: white;">
  67. <div class="container">
  68. <!-- Card 2: Other Details -->
  69. <div class="col-md-12">
  70. <div class="kitchen-data-wrapper">
  71. <div class="card-header"><b>CMBFS-Kitchen</b></div>
  72. <div id="kitchenDataContainer" style="display: none; padding: 15px;">
  73. <table class="table table-bordered">
  74. <tr>
  75. <th>CMBFS Present</th>
  76. <td id="td_k_cmbfs"></td>
  77. <th>CMBFS Building</th>
  78. <td id="td_k_cmbfs_building"></td>
  79. </tr>
  80. <tr>
  81. <th>Noon Meal Present</th>
  82. <td id="td_k_noon"></td>
  83. <th>Noon Meal Building</th>
  84. <td id="td_k_noon_building"></td>
  85. </tr>
  86. <tr>
  87. <th>Vegetable Garden</th>
  88. <td id="td_k_veg"></td>
  89. <th>Anganwadi Present</th>
  90. <td id="td_k_ang"></td>
  91. </tr>
  92. <tr>
  93. <th>Anganwadi Unique No</th>
  94. <td id="td_k_ang_unique"></td>
  95. <th>Anganwadi Building</th>
  96. <td id="td_k_ang_building"></td>
  97. </tr>
  98. </table>
  99. <div class="text-center">
  100. <button type="button" class="btn btn-primary" id="editKitchenBtn">Update</button>
  101. </div>
  102. </div>
  103. </div>
  104. <!-- This block wraps the form -->
  105. <div id="kitchenFormContainer" style="display: none;">
  106. <!-- Card 2: Other Details -->
  107. <div class="col-md-12">
  108. <div class="custom-card-wrapper">
  109. <div class="card-header"><b>CMBFS-Kitchens</b></div>
  110. <div class="row" style=" padding: 15px;">
  111. <div class="col-md-4 form-group">
  112. <label>Is CMBFS-Kitchen Present <span
  113. class="text-danger">*</span></label>
  114. <div class="radio-group">
  115. <input type="radio" id="cmbfskitchenPresentYes"
  116. name="cmbfskitchenPresent" value="1"> Yes
  117. <input type="radio" id="cmbfskitchenPresentNo"
  118. name="cmbfskitchenPresent" value="0"> No
  119. </div>
  120. </div>
  121. <div class="col-md-4 form-group" id="CMBFSfield" style="display: none;">
  122. <label>Individual Building Present <span
  123. class="text-danger">*</span></label>
  124. <div class="radio-group">
  125. <input type="radio" id="cmbfskitchenBuildingYes"
  126. name="cmbfskitchenBuilding" value="1"> Yes
  127. <input type="radio" id="cmbfskitchenBuildingNo"
  128. name="cmbfskitchenBuilding" value="0"> No
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. <!-- card 2 -->
  135. <div class="col-md-12">
  136. <div class="custom-card-wrapper">
  137. <div class="card-header"><b>Noon Meal Center</b></div>
  138. <div class="row" style=" padding: 15px;">
  139. <div class="col-md-4 form-group">
  140. <label>Is Noon Meal Kitchen Present <span
  141. class="text-danger">*</span></label>
  142. <div class="radio-group">
  143. <input type="radio" id="noonMealpresentYes" name="noonMealpresent"
  144. value="1"> Yes
  145. <input type="radio" id="noonMealpresentNo" name="noonMealpresent"
  146. value="0"> No
  147. </div>
  148. </div>
  149. <div id="noonMealfield" style="display: none;" class="col-12">
  150. <div class="row">
  151. <div class="col-md-6 form-group">
  152. <label>Individual Building Present <span
  153. class="text-danger">*</span></label>
  154. <div class="radio-group">
  155. <input type="radio" id="noonMealBuildingYes"
  156. name="noonMealBuilding" value="1"> Yes
  157. <input type="radio" id="noonMealBuildingNo"
  158. name="noonMealBuilding" value="0"> No
  159. </div>
  160. </div>
  161. <div class="col-md-6 form-group">
  162. <label>Presence of Vegetable Garden <span
  163. class="text-danger">*</span></label>
  164. <div class="radio-group">
  165. <input type="radio" id="vegetableGardenYes"
  166. name="vegetableGarden" value="1"> Yes
  167. <input type="radio" id="vegetableGardenNo"
  168. name="vegetableGarden" value="0"> No
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. <!-- card -3 -->
  177. <div class="col-md-12">
  178. <div class="custom-card-wrapper">
  179. <div class="card-header"><b>Anganwadi</b></div>
  180. <div class="row" style=" padding: 15px;">
  181. <div class="col-md-4 form-group">
  182. <label>Is Anganwadi Present <span class="text-danger">*</span></label>
  183. <div class="radio-group">
  184. <input type="radio" id="anganwadiPresentYes" name="anganwadiPresent"
  185. value="1"> Yes
  186. <input type="radio" id="anganwadiPresentNo" name="anganwadiPresent"
  187. value="0"> No
  188. </div>
  189. </div>
  190. <div id="anganwadifield" style="display: none" class="col-12">
  191. <div class="row">
  192. <div class="col-md-6 form-group">
  193. <label>Anganwadi unique Number<span
  194. class="text-danger">*</span></label>
  195. <input type="text" class="form-control"
  196. placeholder="Enter Anganwadi unique Number"
  197. id="anganwadiNumber" required />
  198. </div>
  199. <div class="col-md-4 form-group">
  200. <label>Individual Building Present <span
  201. class="text-danger">*</span></label>
  202. <div class="radio-group">
  203. <input type="radio" id="anganwadiBuildingYes"
  204. name="anganwadiBuilding" value="1"> Yes
  205. <input type="radio" id="anganwadiBuildingNo"
  206. name="anganwadiBuilding" value="0"> No
  207. </div>
  208. </div>
  209. </div>
  210. </div>
  211. </div>
  212. <div class="card-footer text-center">
  213. <button type="submit" class="btn btn-primary" id="requestSubmitBtn"><i
  214. class="ik ik-save"></i>Submit
  215. </button>
  216. <button type="reset" class="btn btn-secondary mr-2" id="resetButton"><i
  217. class="ik ik-refresh-cw"></i>Reset
  218. </button>
  219. </div>
  220. </div>
  221. </div>
  222. </div>
  223. <div id="pageLoader"
  224. 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;">
  225. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  226. <div class="spinner-border text-primary" role="status"
  227. style="width: 3rem; height: 3rem;">
  228. <span class="sr-only">Loading...</span>
  229. </div>
  230. <!-- Add the 'Please wait' text below the spinner -->
  231. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  232. </div>
  233. </div>
  234. </div>
  235. </div>
  236. </div>
  237. <!-- Modal -->
  238. <div class="modal fade" id="editKitchenModal" tabindex="-1" aria-labelledby="editKitchenModalLabel"
  239. aria-hidden="true">
  240. <div class="modal-dialog modal-lg">
  241. <div class="modal-content">
  242. <form id="kitchenForm">
  243. <div class="modal-header">
  244. <h5 class="modal-title">Edit Kitchen Details</h5>
  245. <button type="button" class="close" data-bs-dismiss="modal"
  246. aria-label="Close"><span aria-hidden>&times;</span></button>
  247. </div>
  248. <div class="modal-body">
  249. <!-- Kitchen Form -->
  250. <div class="row mb-3">
  251. <div class="col-md-6">
  252. <label>Is CMBFS-Kitchen Present? *</label>
  253. <div class="radio-group">
  254. <input type="radio" name="modalcmbfskitchenPresent" value="1"> Yes
  255. <input type="radio" name="modalcmbfskitchenPresent" value="0"> No
  256. </div>
  257. </div>
  258. <div class="col-md-6" id="modalCMBFSfield" style="display: none;">
  259. <label>Individual Building Present *</label>
  260. <div class="radio-group">
  261. <input type="radio" name="modalcmbfskitchenBuilding" value="1"> Yes
  262. <input type="radio" name="modalcmbfskitchenBuilding" value="0"> No
  263. </div>
  264. </div>
  265. </div>
  266. <div class="row mb-3">
  267. <div class="col-md-6">
  268. <label>Is Noon Meal Kitchen Present? *</label>
  269. <div class="radio-group">
  270. <input type="radio" name="modalnoonMealpresent" value="1"> Yes
  271. <input type="radio" name="modalnoonMealpresent" value="0"> No
  272. </div>
  273. </div>
  274. </div>
  275. <div class="row mb-3" id="modalnoonMealfield" style="display: none;">
  276. <div class="col-md-6">
  277. <label>Individual Building Present *</label>
  278. <div class="radio-group">
  279. <input type="radio" name="modalnoonMealBuilding" value="1"> Yes
  280. <input type="radio" name="modalnoonMealBuilding" value="0"> No
  281. </div>
  282. </div>
  283. <div class="col-md-6">
  284. <label>Presence of Vegetable Garden *</label>
  285. <div class="radio-group">
  286. <input type="radio" name="modalvegetableGarden" value="1"> Yes
  287. <input type="radio" name="modalvegetableGarden" value="0"> No
  288. </div>
  289. </div>
  290. </div>
  291. <div class="row mb-3">
  292. <div class="col-md-6">
  293. <label>Is Anganwadi Present? *</label>
  294. <div class="radio-group">
  295. <input type="radio" name="modalanganwadiPresent" value="1"> Yes
  296. <input type="radio" name="modalanganwadiPresent" value="0"> No
  297. </div>
  298. </div>
  299. </div>
  300. <div class="row mb-3" id="modalanganwadifield" style="display: none;">
  301. <div class="col-md-6">
  302. <label>Anganwadi Unique Number *</label>
  303. <input type="text" id="modalanganwadiNumber" class="form-control" />
  304. </div>
  305. <div class="col-md-6">
  306. <label>Individual Building Present *</label>
  307. <div class="radio-group">
  308. <input type="radio" name="modalanganwadiBuilding" value="1"> Yes
  309. <input type="radio" name="modalanganwadiBuilding" value="0"> No
  310. </div>
  311. </div>
  312. </div>
  313. </div>
  314. <div class="modal-footer">
  315. <button type="submit" class="btn btn-primary" id="updateSubmitBtn">Submit</button>
  316. <button type="reset" class="btn btn-secondary"
  317. data-bs-dismiss="modal">Close</button>
  318. </div>
  319. </form>
  320. </div>
  321. </div>
  322. </div>
  323. </div>
  324. </div>
  325. </div>
  326. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  327. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  328. <script type="text/javascript">
  329. $(document).ready(function () {
  330. document.querySelectorAll('input[name="cmbfskitchenPresent"]').forEach(radio => {
  331. radio.addEventListener('change', function () {
  332. const CMBFSfieldDiv = document.getElementById('CMBFSfield');
  333. if (this.value === '1') {
  334. CMBFSfieldDiv.style.display = 'block'; // Show the input field
  335. } else {
  336. CMBFSfieldDiv.style.display = 'none'; // Hide the input field
  337. document.querySelectorAll('input[name="cmbfskitchenBuilding"]').forEach(radio => {
  338. radio.checked = false;
  339. });
  340. }
  341. });
  342. });
  343. document.querySelectorAll('input[name="noonMealpresent"]').forEach(radio => {
  344. radio.addEventListener('change', function () {
  345. const noonMealfieldDiv = document.getElementById('noonMealfield');
  346. if (this.value === '1') {
  347. noonMealfieldDiv.style.display = 'block'; // Show the input field
  348. } else {
  349. noonMealfieldDiv.style.display = 'none'; // Hide the input field
  350. document.querySelectorAll('input[name="noonMealBuilding"]').forEach(radio => {
  351. radio.checked = false;
  352. });
  353. document.querySelectorAll('input[name="vegetableGarden"]').forEach(radio => {
  354. radio.checked = false;
  355. });
  356. }
  357. });
  358. });
  359. document.querySelectorAll('input[name="anganwadiPresent"]').forEach(radio => {
  360. radio.addEventListener('change', function () {
  361. const anganwadifieldDiv = document.getElementById('anganwadifield');
  362. if (this.value === '1') {
  363. anganwadifieldDiv.style.display = 'block'; // Show the input field
  364. } else {
  365. anganwadifieldDiv.style.display = 'none'; // Hide the input field
  366. document.querySelectorAll('input[name="anganwadiBuilding"]').forEach(radio => {
  367. radio.checked = false;
  368. });
  369. document.getElementById('anganwadiNumber').value = '';
  370. }
  371. });
  372. });
  373. $("input[name='modalcmbfskitchenPresent']").change(function () {
  374. if ($(this).val() === "1") {
  375. $("#modalCMBFSfield").show();
  376. } else {
  377. $("#modalCMBFSfield").hide();
  378. }
  379. });
  380. // 2. Toggle Noon Meal building and garden fields
  381. $("input[name='modalnoonMealpresent']").change(function () {
  382. if ($(this).val() === "1") {
  383. $("#modalnoonMealfield").show();
  384. } else {
  385. $("#modalnoonMealfield").hide();
  386. }
  387. });
  388. // 3. Toggle Anganwadi fields
  389. $("input[name='modalanganwadiPresent']").change(function () {
  390. if ($(this).val() === "1") {
  391. $("#modalanganwadifield").show();
  392. } else {
  393. $("#modalanganwadifield").hide();
  394. }
  395. });
  396. });
  397. $(document).ready(function () {
  398. const urlParams = new URLSearchParams(window.location.search);
  399. const schoolId = urlParams.get("schoolId");
  400. $('input[name="school_id"]').val(schoolId);
  401. function toggleField(radioGroup, targetDiv, resetSelectors = []) {
  402. document.querySelectorAll(`input[name="${radioGroup}"]`).forEach(radio => {
  403. radio.addEventListener('change', function () {
  404. if (this.value === '1') {
  405. document.getElementById(targetDiv).style.display = 'block';
  406. } else {
  407. document.getElementById(targetDiv).style.display = 'none';
  408. resetSelectors.forEach(sel => {
  409. $(sel).prop('checked', false);
  410. if ($(sel).is('input[type="text"]')) $(sel).val('');
  411. });
  412. }
  413. });
  414. });
  415. }
  416. toggleField('cmbfskitchenPresent', 'CMBFSfield', ['input[name="cmbfskitchenBuilding"]']);
  417. toggleField('noonMealpresent', 'noonMealfield', ['input[name="noonMealBuilding"]', 'input[name="vegetableGarden"]']);
  418. toggleField('anganwadiPresent', 'anganwadifield', ['input[name="anganwadiBuilding"]', '#anganwadiNumber']);
  419. // ---------------- Data Fetch -------------------
  420. $.ajax({
  421. url: '/gcc/api/gccschool/schoolproperty/checkKitchenDetails',
  422. type: 'GET',
  423. data: {school_id: schoolId},
  424. success: function (response) {
  425. const hasValidData = response && response[0] && response[0].Data && Object.values(response[0].Data).some(val => val !== null && val !== false && val !== "");
  426. if (hasValidData) {
  427. const data = response[0].Data;
  428. //const yesNo = val => val === true ? 'Yes' : 'No';
  429. const yesNo = val => val === true ? 'Yes' : val === false ? 'No' : '-';
  430. $('#td_k_cmbfs').text(yesNo(data.is_cmbfs));
  431. $('#td_k_cmbfs_building').text(yesNo(data.is_cmbfsIndividual));
  432. $('#td_k_noon').text(yesNo(data.is_noonmeal));
  433. $('#td_k_noon_building').text(yesNo(data.is_noonIndividual));
  434. $('#td_k_veg').text(yesNo(data.is_vegGarden));
  435. $('#td_k_ang').text(yesNo(data.is_anganwadi));
  436. $('#td_k_ang_unique').text(data.anganwadi_unique || '-');
  437. $('#td_k_ang_building').text(yesNo(data.is_anganwadiIndividual));
  438. $('#kitchenDataContainer').show(); // ✅ Show table
  439. $('#kitchenFormContainer').hide(); // ❌ Hide form
  440. $('#editKitchenBtn').data('kitchenData', data);
  441. } else {
  442. $('#kitchenDataContainer').hide(); // ❌ Hide table
  443. $('#kitchenFormContainer').show(); // ✅ Show form
  444. }
  445. },
  446. error: function () {
  447. $('#kitchenDataContainer').hide(); // ❌ hide table
  448. $('#kitchenFormContainer').show(); // ✅ show form
  449. }
  450. });
  451. $('input[name="modalanganwadiPresent"]').on('change', function () {
  452. if (this.value === '1') {
  453. $('#editKitchenModalAnganwadiField').show();
  454. } else {
  455. $('#editKitchenModalAnganwadiField').hide();
  456. // Clear the Anganwadi Building radio buttons
  457. $('input[name="modalanganwadiBuilding"]').prop('checked', false);
  458. // Clear the Anganwadi Number field
  459. $('#modalanganwadiNumber').val('');
  460. }
  461. });
  462. $('input[name="modalnoonMealpresent"]').on('change', function () {
  463. if (this.value === '1') {
  464. $('#editKitchenModalNoonField').show();
  465. } else {
  466. $('#editKitchenModalNoonField').hide();
  467. $('input[name="modalnoonMealBuilding"]').prop('checked', false);
  468. $('input[name="modalvegetableGarden"]').prop('checked', false);
  469. }
  470. });
  471. $('input[name="modalcmbfskitchenPresent"]').on('change', function () {
  472. if (this.value === '1') {
  473. $('#editKitchenModalCMBFSfield').show();
  474. } else {
  475. $('#editKitchenModalCMBFSfield').hide();
  476. $('input[name="modalcmbfskitchenBuilding"]').prop('checked', false);
  477. }
  478. });
  479. // ---------------- On Update Button -------------------
  480. $('#editKitchenBtn').click(function () {
  481. const data = $(this).data('kitchenData');
  482. $(`input[name="modalcmbfskitchenPresent"][value="${data.is_cmbfs ? 1 : 0}"]`).prop('checked', true);
  483. $(`input[name="modalcmbfskitchenBuilding"][value="${data.is_cmbfsIndividual ? 1 : 0}"]`).prop('checked', true);
  484. $(`input[name="modalnoonMealpresent"][value="${data.is_noonmeal ? 1 : 0}"]`).prop('checked', true);
  485. $(`input[name="modalnoonMealBuilding"][value="${data.is_noonIndividual ? 1 : 0}"]`).prop('checked', true);
  486. $(`input[name="modalvegetableGarden"][value="${data.is_vegGarden ? 1 : 0}"]`).prop('checked', true);
  487. $(`input[name="modalanganwadiPresent"][value="${data.is_anganwadi ? 1 : 0}"]`).prop('checked', true);
  488. $(`input[name="modalanganwadiBuilding"][value="${data.is_anganwadiIndividual ? 1 : 0}"]`).prop('checked', true);
  489. $('#modalanganwadiNumber').val(data.anganwadi_unique || '');
  490. // 👇 Force the toggle to display the dependent fields
  491. $(`#editKitchenModal input[name="modalcmbfskitchenPresent"]:checked`).trigger('change');
  492. $(`#editKitchenModal input[name="modalnoonMealpresent"]:checked`).trigger('change');
  493. $(`#editKitchenModal input[name="modalanganwadiPresent"]:checked`).trigger('change');
  494. // Show modal
  495. const kitchenModal = new bootstrap.Modal(document.getElementById('editKitchenModal'));
  496. kitchenModal.show();
  497. });
  498. // --- Toggle logic for modal form fields inside editKitchenModal ---
  499. function toggleModalField(radioGroupName, fieldId, resetSelectors = []) {
  500. $(`#editKitchenModal input[name="${radioGroupName}"]`).on('change', function () {
  501. if (this.value === '1') {
  502. $(`#editKitchenModal #${fieldId}`).show();
  503. } else {
  504. $(`#editKitchenModal #${fieldId}`).hide();
  505. resetSelectors.forEach(sel => {
  506. $(`#editKitchenModal ${sel}`).prop('checked', false);
  507. if ($(sel).is('input[type="text"]')) $(sel).val('');
  508. });
  509. }
  510. });
  511. }
  512. // Apply for each group
  513. toggleModalField('cmbfskitchenPresent', 'CMBFSfield', ['input[name="cmbfskitchenBuilding"]']);
  514. toggleModalField('noonMealpresent', 'noonMealfield', ['input[name="noonMealBuilding"]', 'input[name="vegetableGarden"]']);
  515. toggleModalField('anganwadiPresent', 'anganwadifield', ['input[name="anganwadiBuilding"]', '#anganwadiNumber']);
  516. document.getElementById('anganwadiNumber').addEventListener('input', function () {
  517. // Keep only alphanumeric characters
  518. this.value = this.value.replace(/[^a-zA-Z0-9]/g, '');
  519. });
  520. document.getElementById('modalanganwadiNumber').addEventListener('input', function () {
  521. // Keep only alphanumeric characters
  522. this.value = this.value.replace(/[^a-zA-Z0-9]/g, '');
  523. });
  524. $(document).on('click', '#requestSubmitBtn', function () {
  525. let cmbfskitchenPresent = $('input[name="cmbfskitchenPresent"]:checked').val();
  526. let cmbfskitchenBuilding = null;
  527. if (cmbfskitchenPresent === '1') {
  528. cmbfskitchenBuilding = $('input[name="cmbfskitchenBuilding"]:checked').val();
  529. if (!cmbfskitchenBuilding) {
  530. Swal.fire({
  531. icon: 'warning',
  532. title: 'Validation Error!',
  533. text: 'Individual Building Present is required for CMBFS kitchen .',
  534. allowOutsideClick: false, // Disable clicking outside the modal to close it
  535. allowEscapeKey: false, // Disable escape key to close the modal
  536. allowEnterKey: false, // Disable enter key to close the modal
  537. showConfirmButton: true
  538. });
  539. return;
  540. }
  541. }
  542. let noonMealpresent = $('input[name="noonMealpresent"]:checked').val();
  543. let noonMealBuilding = null;
  544. let vegetableGarden = null;
  545. if (noonMealpresent === '1') {
  546. noonMealBuilding = $('input[name="noonMealBuilding"]:checked').val();
  547. if (!noonMealBuilding) {
  548. Swal.fire({
  549. icon: 'warning',
  550. title: 'Validation Error!',
  551. text: 'Individual Building Present is required for Noon Meal Center .',
  552. allowOutsideClick: false, // Disable clicking outside the modal to close it
  553. allowEscapeKey: false, // Disable escape key to close the modal
  554. allowEnterKey: false, // Disable enter key to close the modal
  555. showConfirmButton: true
  556. });
  557. return;
  558. }
  559. vegetableGarden = $('input[name="vegetableGarden"]:checked').val();
  560. if (!vegetableGarden) {
  561. Swal.fire({
  562. icon: 'warning',
  563. title: 'Validation Error!',
  564. text: 'Presence of Vegetable Garden is required .',
  565. allowOutsideClick: false, // Disable clicking outside the modal to close it
  566. allowEscapeKey: false, // Disable escape key to close the modal
  567. allowEnterKey: false, // Disable enter key to close the modal
  568. showConfirmButton: true
  569. });
  570. return;
  571. }
  572. }
  573. let anganwadiPresent = $('input[name="anganwadiPresent"]:checked').val();
  574. let anganwadiBuilding = null;
  575. let anganwadiNumber = null;
  576. if (anganwadiPresent === '1') {
  577. anganwadiNumber = $('#anganwadiNumber').val();
  578. anganwadiBuilding = $('input[name="anganwadiBuilding"]:checked').val();
  579. if (!anganwadiNumber) {
  580. Swal.fire({
  581. icon: 'warning',
  582. title: 'Validation Error!',
  583. text: 'AnganwadiNumber is required',
  584. allowOutsideClick: false, // Disable clicking outside the modal to close it
  585. allowEscapeKey: false, // Disable escape key to close the modal
  586. allowEnterKey: false, // Disable enter key to close the modal
  587. showConfirmButton: true
  588. });
  589. return;
  590. }
  591. if (!anganwadiBuilding) {
  592. Swal.fire({
  593. icon: 'warning',
  594. title: 'Validation Error!',
  595. text: 'Individual Building Present is required for Anganwadi.',
  596. allowOutsideClick: false, // Disable clicking outside the modal to close it
  597. allowEscapeKey: false, // Disable escape key to close the modal
  598. allowEnterKey: false, // Disable enter key to close the modal
  599. showConfirmButton: true
  600. });
  601. return;
  602. }
  603. }
  604. // let school_id = 1;
  605. console.log("cmbfskitchenPresent=", cmbfskitchenPresent);
  606. console.log("anganwadiBuilding=", anganwadiBuilding);
  607. console.log("noonMealpresent=", noonMealpresent);
  608. console.log("noonMealBuilding=", noonMealBuilding);
  609. console.log("vegetableGarden=", vegetableGarden);
  610. console.log("anganwadiPresent=", anganwadiPresent);
  611. console.log("anganwadiNumber=", anganwadiNumber);
  612. console.log("anganwadiBuilding=", anganwadiBuilding);
  613. console.log("school_id=", schoolId);
  614. // Validate inputs
  615. let fields = {
  616. "Is CMBFS-Kitchen Present": cmbfskitchenPresent,
  617. "Is noonMealpresent Present": noonMealpresent,
  618. "Is Anganwadi Present": anganwadiPresent,
  619. };
  620. for (let key in fields) {
  621. if (!fields[key] || isNaN(fields[key])) {
  622. Swal.fire({
  623. icon: 'info',
  624. title: 'Validation Error',
  625. text: `Please enter ${key}.`,
  626. allowOutsideClick: false, // Disable clicking outside the modal to close it
  627. allowEscapeKey: false, // Disable escape key to close the modal
  628. allowEnterKey: false, // Disable enter key to close the modal
  629. showConfirmButton: true
  630. });
  631. return; // Stop execution if validation fails
  632. }
  633. }
  634. // Prepare Data for AJAX
  635. let requestData = {
  636. is_cmbfs: cmbfskitchenPresent,
  637. is_cmbfsIndividual: cmbfskitchenBuilding,
  638. is_noonmeal: noonMealpresent,
  639. is_noonIndividual: noonMealBuilding,
  640. is_vegGarden: vegetableGarden,
  641. is_anganwadi: anganwadiPresent,
  642. anganwadi_unique: anganwadiNumber || null,
  643. is_anganwadiIndividual: anganwadiBuilding,
  644. school_id: schoolId
  645. };
  646. $('#requestSubmitBtn').prop('disabled', true).text('Processing...');
  647. $('#pageLoader').show();
  648. $.ajax({
  649. url: '/gcc/api/gccschool/schoolproperty/saveKitchen',
  650. type: 'POST',
  651. contentType: 'application/x-www-form-urlencoded',
  652. data: $.param(requestData),
  653. success: function (response) {
  654. $('#pageLoader').hide();
  655. $('#requestSubmitBtn').prop('disabled', false).text('Submit');
  656. Swal.fire({
  657. icon: 'success',
  658. title: 'Success',
  659. text: response,
  660. allowOutsideClick: false,
  661. allowEscapeKey: false,
  662. allowEnterKey: false,
  663. confirmButtonText: 'OK'
  664. }).then((result) => {
  665. if (result.isConfirmed) {
  666. $('#requestSubmitBtn').prop('disabled', false).text('Submit');
  667. location.reload();
  668. }
  669. });
  670. },
  671. error: function (xhr, status, error) {
  672. $('#pageLoader').hide();
  673. $('#requestSubmitBtn').prop('disabled', false).text('Submit');
  674. let errorMessage = xhr.responseText;
  675. Swal.fire({
  676. icon: 'error',
  677. title: 'Error',
  678. text: errorMessage,
  679. allowOutsideClick: false, // Disable clicking outside the modal to close it
  680. allowEscapeKey: false, // Disable escape key to close the modal
  681. allowEnterKey: false, // Disable enter key to close the modal
  682. showConfirmButton: true
  683. });
  684. console.error('Error:', xhr.responseText);
  685. }
  686. });
  687. });
  688. function resetFacilityFields() {
  689. console.log("Reset button clicked - Facilities");
  690. // Uncheck all radio buttons
  691. $('input[type="radio"]').prop('checked', false);
  692. // Clear input fields
  693. $('#anganwadiNumber').val('');
  694. // Hide dependent sections
  695. $('#CMBFSfield, #noonMealfield, #anganwadifield').hide();
  696. }
  697. // Event Listener for Reset Button
  698. $(document).on('click', '#resetButton', function (event) {
  699. event.preventDefault();
  700. resetFacilityFields();
  701. });
  702. $(document).on('click', '#updateSubmitBtn', function (e) {
  703. e.preventDefault();
  704. submitModalKitchenUpdate();
  705. });
  706. function submitModalKitchenUpdate() {
  707. let cmbfskitchenPresent = $('#editKitchenModal input[name="modalcmbfskitchenPresent"]:checked').val();
  708. let cmbfskitchenBuilding = cmbfskitchenPresent === '1' ? $('#editKitchenModal input[name="modalcmbfskitchenBuilding"]:checked').val() : null;
  709. /*if (cmbfskitchenPresent === '1' && !cmbfskitchenBuilding) {
  710. return Swal.fire('Validation Error!', 'Individual Building Present is required for CMBFS kitchen.', 'warning');
  711. }*/
  712. if (cmbfskitchenPresent === '1' && !cmbfskitchenBuilding) {
  713. return Swal.fire({
  714. title: 'Validation Error!',
  715. text: 'Individual Building Present is required for CMBFS kitchen.',
  716. icon: 'warning',
  717. allowOutsideClick: false,
  718. allowEscapeKey: false,
  719. allowEnterKey: false,
  720. showConfirmButton: true
  721. });
  722. }
  723. let noonMealpresent = $('#editKitchenModal input[name="modalnoonMealpresent"]:checked').val();
  724. let noonMealBuilding = noonMealpresent === '1' ? $('#editKitchenModal input[name="modalnoonMealBuilding"]:checked').val() : null;
  725. let vegetableGarden = noonMealpresent === '1' ? $('#editKitchenModal input[name="modalvegetableGarden"]:checked').val() : null;
  726. /*if (noonMealpresent === '1' && (!noonMealBuilding || !vegetableGarden)) {
  727. return Swal.fire('Validation Error!', 'Fields under Noon Meal Center are required.', 'warning');
  728. }*/
  729. if (noonMealpresent === '1' && (!noonMealBuilding || !vegetableGarden)) {
  730. return Swal.fire({
  731. title: 'Validation Error!',
  732. text: 'Fields under Noon Meal Center are required.',
  733. icon: 'warning',
  734. allowOutsideClick: false,
  735. allowEscapeKey: false,
  736. allowEnterKey: false,
  737. showConfirmButton: true
  738. });
  739. }
  740. let anganwadiPresent = $('#editKitchenModal input[name="modalanganwadiPresent"]:checked').val();
  741. let anganwadiBuilding = anganwadiPresent === '1' ? $('#editKitchenModal input[name="modalanganwadiBuilding"]:checked').val() : null;
  742. let anganwadiNumber = anganwadiPresent === '1' ? $('#editKitchenModal #modalanganwadiNumber').val() : null;
  743. /*if (anganwadiPresent === '1' && (!anganwadiBuilding || !anganwadiNumber)) {
  744. return Swal.fire('Validation Error!', 'All Anganwadi fields are required.', 'warning');
  745. }*/
  746. if (anganwadiPresent === '1' && (!anganwadiBuilding || !anganwadiNumber)) {
  747. return Swal.fire({
  748. title: 'Validation Error!',
  749. text: 'All Anganwadi fields are required.',
  750. icon: 'warning',
  751. allowOutsideClick: false,
  752. allowEscapeKey: false,
  753. allowEnterKey: false,
  754. showConfirmButton: true
  755. });
  756. }
  757. const requestData = {
  758. is_cmbfs: cmbfskitchenPresent,
  759. is_cmbfsIndividual: cmbfskitchenBuilding,
  760. is_noonmeal: noonMealpresent,
  761. is_noonIndividual: noonMealBuilding,
  762. is_vegGarden: vegetableGarden,
  763. is_anganwadi: anganwadiPresent,
  764. anganwadi_unique: anganwadiNumber || null,
  765. is_anganwadiIndividual: anganwadiBuilding,
  766. school_id: schoolId
  767. };
  768. $('#updateSubmitBtn').prop('disabled', true).text('Updating...');
  769. $('#pageLoader').show();
  770. $.ajax({
  771. url: '/gcc/api/gccschool/schoolproperty/updateKitchenDetails',
  772. type: 'POST',
  773. contentType: 'application/x-www-form-urlencoded',
  774. data: $.param(requestData),
  775. success: function (response) {
  776. $('#pageLoader').hide();
  777. $('#updateSubmitBtn').prop('disabled', false).text('Submit');
  778. //Swal.fire('Success', response, 'success').
  779. Swal.fire({
  780. title: 'Success',
  781. text: 'Kitchen details updated successfully!!',
  782. icon: 'success',
  783. allowOutsideClick: false,
  784. allowEscapeKey: false,
  785. allowEnterKey: false,
  786. showConfirmButton: true
  787. })
  788. .then(() => {
  789. $('#editKitchenModal').modal('hide');
  790. location.reload();
  791. });
  792. },
  793. error: function (xhr) {
  794. $('#pageLoader').hide();
  795. $('#updateSubmitBtn').prop('disabled', false).text('Submit');
  796. //Swal.fire('Error', xhr.responseText || 'Failed to update.', 'error');
  797. Swal.fire({
  798. title: 'Error',
  799. text: xhr.responseText || 'Failed to update.',
  800. icon: 'error',
  801. allowOutsideClick: false,
  802. allowEscapeKey: false,
  803. allowEnterKey: false,
  804. showConfirmButton: true
  805. });
  806. }
  807. });
  808. }
  809. });
  810. </script>
  811. </body>
  812. </html>