This portal only for GCC Officers. Based on there roles and Group ID they can view there module`s Like PGR, QR Public Asset Feedback, Makkalai Thedi Mayor,etc...
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.

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