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.

789 lines
23 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr">
  3. <html xmlns:th="http://www.thymeleaf.org">
  4. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css">
  5. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  6. <style>
  7. body {
  8. background-color: #f8f9fa;
  9. /* font-family: Arial, sans-serif;*/
  10. }
  11. .header {
  12. font-size: 22px;
  13. font-weight: bold;
  14. margin-bottom: 20px;
  15. }
  16. .table {
  17. border: 1px solid #dee2e6;
  18. }
  19. .table th,
  20. .table td {
  21. border: 1px solid #dee2e6;
  22. padding: 10px;
  23. }
  24. .section-title {
  25. font-size: 18px;
  26. font-weight: bold;
  27. margin-top: 20px;
  28. border-bottom: 2px solid #007bff;
  29. padding-bottom: 5px;
  30. }
  31. .form-group {
  32. margin-top: 15px;
  33. }
  34. .radio-group {
  35. display: flex;
  36. gap: 20px;
  37. margin-top: 10px;
  38. }
  39. #assetModal .modal-body {
  40. max-height: 80vh;
  41. overflow-y: auto;
  42. }
  43. #floordetailsModal .modal-body {
  44. max-height: 80vh;
  45. overflow-y: auto;
  46. }
  47. #roomMappingModal .modal-body {
  48. max-height: 80vh;
  49. overflow-y: auto;
  50. min-height: 40vh;
  51. }
  52. </style>
  53. <body>
  54. <div class="wrapper">
  55. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  56. <div class="page-wrap">
  57. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  58. <div class="main-content" style="margin-top: 6px;">
  59. <div class="container">
  60. <div class="col-md-12">
  61. <div class="d-flex justify-content-between align-items-center">
  62. <h4 style="margin-left: -256px;">Rooms</h4>
  63. <button type="button" class="btn btn-primary mb-2" id="addRoomBtn"
  64. style="background-color: #0D587B; border: none; border-radius: 6px; padding: 6px 16px;"
  65. data-bs-toggle="modal" data-bs-target="#addRoomModal">
  66. <i class="bi bi-plus-lg"></i>Add Room
  67. </button>
  68. </div>
  69. <hr
  70. style="border: 1px solid #ccc; margin-top: 10px; margin-bottom: 20px; margin-left: -256px;">
  71. </div>
  72. <div class="row mt-4" style="margin-left: -281px;">
  73. <div class="col-md-12">
  74. <div class="card">
  75. <div class="card-block">
  76. <table id="CompletedCPSDatatable"
  77. class="table table-striped table-bordered table-hover dataTable" role="grid"
  78. style="width: 100%">
  79. <thead class="thead-dark">
  80. <tr>
  81. <th style="width: 5%;">S.NO</th>
  82. <th style="width: 10%;">Room Name</th>
  83. <th style="width: 15%;">Building Name</th>
  84. <th style="width: 10%;">Floor</th>
  85. <th style="width: 15%;">Room Type</th>
  86. <th style="width: 10%;">Action</th>
  87. </tr>
  88. </thead>
  89. <tbody>
  90. </tbody>
  91. </table>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. <!-- Card 2: Other Details -->
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <!-- Modal -->
  102. <!-- Floor Details Modal -->
  103. <div class="modal fade" id="floordetailsModal" tabindex="-1" role="dialog" aria-labelledby="floordetailsModalLabel"
  104. aria-hidden="true" data-backdrop="static" data-keyboard="false">
  105. <div class="modal-dialog modal-lg" role="document">
  106. <div class="modal-content">
  107. <div class="modal-header">
  108. <h5 class="modal-title" id="detailsModalLabel">Floor Details</h5>
  109. <button type="button" class="close" data-dismiss="modal"
  110. onclick="$('#floordetailsModal').modal('hide');" aria-label="Close">
  111. <span aria-hidden="true">&times;</span>
  112. </button>
  113. </div>
  114. <div class="modal-body">
  115. <table class="table table-striped table-bordered" id="floorDetailsTable">
  116. <thead class="thead-dark">
  117. <tr>
  118. <th class="text-center">S.No</th>
  119. <th class="text-center">Room Name</th>
  120. <th class="text-center">Building Name</th>
  121. <th class="text-center">Floor</th>
  122. <th class="text-center">Room Type</th>
  123. <th class="text-center">Action</th>
  124. </tr>
  125. </thead>
  126. <tbody>
  127. <!-- Data will be inserted here -->
  128. </tbody>
  129. </table>
  130. </div>
  131. <div class="modal-footer">
  132. <button type="button" class="btn btn-secondary" data-dismiss="modal"
  133. onclick="$('#floordetailsModal').modal('hide');">Close</button>
  134. </div>
  135. </div>
  136. </div>
  137. </div>
  138. <div class="modal fade" id="viewRoomModal" tabindex="-1" aria-labelledby="viewRoomModalLabel" data-bs-backdrop="static" data-bs-keyboard="false" aria-hidden="true">
  139. <div class="modal-dialog modal-md">
  140. <div class="modal-content">
  141. <div class="modal-header bg-primary text-white">
  142. <h5 class="modal-title">View Room Details</h5>
  143. <button type="button" class="close" data-bs-dismiss="modal"
  144. aria-label="Close"><span aria-hidden="true">&times;</span></button>
  145. </div>
  146. <div class="modal-body">
  147. <div class="row mb-3">
  148. <div class="col-md-6">
  149. <label class="form-label">Room Name</label> <input type="text" id="viewRoomName"
  150. class="form-control" readonly>
  151. </div>
  152. <div class="col-md-6">
  153. <label class="form-label">Building Name</label> <input type="text" id="viewBuildingName"
  154. class="form-control" readonly>
  155. </div>
  156. </div>
  157. <div class="row mb-3">
  158. <div class="col-md-6">
  159. <label class="form-label">Floor</label> <input type="text" id="viewFloor"
  160. class="form-control" readonly>
  161. </div>
  162. <div class="col-md-6">
  163. <label class="form-label">Room Type</label> <input type="text" id="viewRoomType"
  164. class="form-control" readonly>
  165. </div>
  166. </div>
  167. </div>
  168. <div class="modal-footer">
  169. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. <!-- Edit Room Modal -->
  175. <div class="modal fade" id="editRoomModal" tabindex="-1" aria-labelledby="editRoomModalLabel" data-bs-backdrop="static" data-bs-keyboard="false" aria-hidden="true">
  176. <div class="modal-dialog modal-md">
  177. <div class="modal-content">
  178. <div class="modal-header bg-success text-white">
  179. <h5 class="modal-title">Edit Room Details</h5>
  180. <button type="button" class="close" data-bs-dismiss="modal"
  181. aria-label="Close"><span aria-hidden="true">&times;</span></button>
  182. </div>
  183. <div class="modal-body">
  184. <div class="row mb-3">
  185. <div class="col-md-6">
  186. <label class="form-label">Room Name</label> <input type="text" id="editRoomName"
  187. class="form-control"> <input type="hidden" id="editRoomId">
  188. </div>
  189. <div class="col-md-6">
  190. <label class="form-label">Building</label> <select id="editBuildingId" class="form-control" disabled>
  191. <option value="">Select Building</option>
  192. </select>
  193. </div>
  194. </div>
  195. <div class="row mb-3">
  196. <div class="col-md-6">
  197. <label class="form-label">Floor</label> <select id="editFloorId" class="form-control">
  198. <option value="">Select Floor</option>
  199. </select>
  200. </div>
  201. <div class="col-md-6">
  202. <label class="form-label">Room Type</label> <select id="editRoomTypeId"
  203. class="form-control">
  204. <option value="">Select Room Type</option>
  205. </select>
  206. </div>
  207. </div>
  208. </div>
  209. <div class="modal-footer">
  210. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
  211. <button type="button" class="btn btn-success" id="saveEditRoom">Save
  212. Changes</button>
  213. <button type="button" class="btn btn-danger" id="roomDelete">Delete</button>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. <div class="modal fade" id="addRoomModal" tabindex="-1"
  219. data-bs-backdrop="static" data-bs-keyboard="false"
  220. aria-labelledby="addRoomModalLabel" aria-hidden="true">
  221. <div class="modal-dialog modal-lg">
  222. <div class="modal-content">
  223. <div class="modal-header bg-primary text-white">
  224. <h5 class="modal-title">Add New Room</h5>
  225. <button type="button" class="close" data-bs-dismiss="modal"
  226. aria-label="Close"><span aria-hidden="true">&times;</span></button>
  227. </div>
  228. <div class="modal-body">
  229. <div class="row mb-3">
  230. <div class="col-md-6">
  231. <label class="form-label">Building<span style="color: red;">*</span></label> <select id="addBuildingId" class="form-control">
  232. <option value="">Select Building</option>
  233. </select>
  234. </div>
  235. <div class="col-md-6">
  236. <label class="form-label">Floor<span style="color: red;">*</span></label> <select id="addFloorId" class="form-control">
  237. <option value="">Select Floor</option>
  238. </select>
  239. </div>
  240. </div>
  241. <div class="row mb-3">
  242. <div class="col-md-6">
  243. <label class="form-label">Room Type<span style="color: red;">*</span></label> <select id="addRoomTypeId" class="form-control">
  244. <option value="">Select Room Type</option>
  245. </select>
  246. </div>
  247. <div class="col-md-6">
  248. <label class="form-label">Room Name<span style="color: red;">*</span></label> <input type="text" id="addRoomName"
  249. class="form-control">
  250. </div>
  251. </div>
  252. </div>
  253. <div class="modal-footer">
  254. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
  255. <button type="button" class="btn btn-primary" id="saveAddRoom">Save Room</button>
  256. </div>
  257. </div>
  258. </div>
  259. </div>
  260. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  261. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  262. </body>
  263. <script>
  264. window.schoolId = window.schoolId || new URLSearchParams(window.location.search).get('schoolId');
  265. if (!window.schoolId) {
  266. Swal.fire("Missing School ID", "No schoolId found in the URL", "warning");
  267. throw new Error("Missing schoolId");
  268. }
  269. function loadSavedRoomDetails(school_id) {
  270. $.ajax({
  271. url: '/gcc/api/gccschool/buildingasset/getRoomDetails',
  272. type: 'GET',
  273. contentType: 'application/json',
  274. data: { school_id },
  275. success: function (response) {
  276. if (response.status === "OK") {
  277. $('#CompletedCPSDatatable').DataTable({
  278. destroy: true,
  279. searching: true,
  280. select: false,
  281. autoWidth: true,
  282. scrollY: '60vh',
  283. scrollCollapse: true,
  284. processsing: false,
  285. responsive: true,
  286. paging: true,
  287. info: true,
  288. data: response.data,
  289. columns: [
  290. { data: null, render: (data, type, row, meta) => meta.row + 1, className: 'text-center' },
  291. { data: 'room_name', defaultContent: '-', className: 'text-center' },
  292. { data: 'building_name', defaultContent: '-', className: 'text-center' },
  293. { data: 'floor', defaultContent: '-', className: 'text-center' },
  294. { data: 'room_type', defaultContent: '-', className: 'text-center' },
  295. {
  296. data: 'room_id',
  297. render: function (data, type, row) {
  298. return `
  299. <div class="text-center">
  300. <button class="btn btn-sm btn-primary me-1 view-btn2" data-room-id="${data}" title="View">
  301. <i class="bi bi-eye"></i>
  302. </button>
  303. <button class="btn btn-sm btn-success edit-btn2" data-room-id="${data}" data-building-id="${row.building_id}" title="Edit">
  304. <i class="bi bi-pencil"></i>
  305. </button>
  306. </div>`;
  307. },
  308. className: 'text-center'
  309. }
  310. ]
  311. });
  312. } else {
  313. $('#CompletedCPSDatatable tbody').html(`<tr><td colspan="6" class="text-center text-danger">${response.data}</td></tr>`);
  314. }
  315. },
  316. error: function () {
  317. Swal.fire("Error", "Something went wrong while fetching room details.", "error");
  318. }
  319. });
  320. }
  321. function loadBuildingsDropdown(schoolId, selectedBuildingId = null) {
  322. $.ajax({
  323. url: '/gcc/api/gccschool/dropdown/getBuildingsBySchoolId',
  324. type: 'GET',
  325. data: { school_id: schoolId },
  326. success: function (response) {
  327. const dropdown = $('#editBuildingId');
  328. dropdown.empty().append('<option value="">Select Building</option>');
  329. if (response.status === "OK") {
  330. response.data.forEach(building => {
  331. const selected = building.buildng_id == selectedBuildingId ? 'selected' : '';
  332. dropdown.append(`<option value="${building.buildng_id}" ${selected}>${building.building_name}</option>`);
  333. });
  334. }
  335. },
  336. error: function () {
  337. Swal.fire("Error", "Unable to load buildings", "error");
  338. }
  339. });
  340. }
  341. function loadRoomTypesDropdown() {
  342. $.ajax({
  343. url: '/gcc/api/gccschool/dropdown/getRooms',
  344. type: 'GET',
  345. success: function (response) {
  346. const dropdown = $('#editRoomTypeId');
  347. dropdown.empty().append('<option value="">Select Room Type</option>');
  348. if (response.status === 'OK') {
  349. response.data.forEach(room => {
  350. dropdown.append(`<option value="${room.room_master_id}">${room.room_type}</option>`);
  351. });
  352. }
  353. }
  354. });
  355. }
  356. function loadBuildingsDropdownForAdd(schoolId) {
  357. $.get('/gcc/api/gccschool/dropdown/getBuildingsBySchoolId', { school_id: schoolId }, function (response) {
  358. const dropdown = $('#addBuildingId');
  359. dropdown.empty().append('<option value="">Select Building</option>');
  360. if (response.status === 'OK') {
  361. response.data.forEach(building => {
  362. dropdown.append(`<option value="${building.buildng_id}">${building.building_name}</option>`);
  363. });
  364. }
  365. });
  366. }
  367. function loadRoomTypesDropdownForAdd() {
  368. $.get('/gcc/api/gccschool/dropdown/getRooms', function (response) {
  369. const dropdown = $('#addRoomTypeId');
  370. dropdown.empty().append('<option value="">Select Room Type</option>');
  371. if (response.status === 'OK') {
  372. response.data.forEach(room => {
  373. dropdown.append(`<option value="${room.room_master_id}">${room.room_type}</option>`);
  374. });
  375. }
  376. });
  377. }
  378. $('#addRoomModal').on('show.bs.modal', function () {
  379. $('#addBuildingId').val('');
  380. $('#addFloorId').val('');
  381. $('#addRoomTypeId').val('');
  382. $('#addRoomName').val('');
  383. });
  384. $(document).ready(function () {
  385. loadRoomTypesDropdown();
  386. loadRoomTypesDropdownForAdd();
  387. loadBuildingsDropdownForAdd(schoolId);
  388. loadSavedRoomDetails(schoolId);
  389. });
  390. $(document).on('click', '.view-btn2', function () {
  391. const roomId = $(this).data('room-id');
  392. $.ajax({
  393. url: `/gcc/api/gccschool/buildingasset/getRoomById`,
  394. method: 'GET',
  395. data: { room_id: roomId },
  396. success: function (response) {
  397. if (response.status === 'OK' && response.data) {
  398. const room = response.data;
  399. $('#viewRoomName').val(room.room_name || '');
  400. $('#viewBuildingName').val(room.building_name || '');
  401. $('#viewFloor').val(room.floor || '');
  402. $('#viewRoomType').val(room.room_type || '');
  403. $('#viewRoomModal').modal('show');
  404. } else {
  405. Swal.fire("Error", response.data || "Room data not found", "error");
  406. }
  407. },
  408. error: function () {
  409. Swal.fire("Error", "Failed to load room details", "error");
  410. }
  411. });
  412. });
  413. $(document).on('click', '.edit-btn2', function () {
  414. const roomId = $(this).data('room-id');
  415. const buildingIdFromAttr = $(this).data('building-id');
  416. $.ajax({
  417. url: '/gcc/api/gccschool/buildingasset/getRoomById',
  418. method: 'GET',
  419. data: { room_id: roomId },
  420. success: function (response) {
  421. if (response.status === 'OK') {
  422. const room = response.data;
  423. $('#editRoomId').val(room.room_id);
  424. $('#editRoomName').val(room.room_name);
  425. loadBuildingsDropdown(room.school_id, buildingIdFromAttr);
  426. loadFloorDropdown(buildingIdFromAttr, room.floors_id);
  427. $('#editRoomTypeId').val(room.room_master_id);
  428. $('#editRoomModal').modal('show');
  429. } else {
  430. Swal.fire("Error", response.data || "Room not found", "error");
  431. }
  432. },
  433. error: function () {
  434. Swal.fire("Error", "Failed to load room details", "error");
  435. }
  436. });
  437. });
  438. $('#saveEditRoom').on('click', function () {
  439. const updatedRoom = {
  440. room_id: $('#editRoomId').val(),
  441. room_num: $('#editRoomName').val(),
  442. building_id: $('#editBuildingId').val(),
  443. floors_id: $('#editFloorId').val() || null,
  444. room_type: $('#editRoomTypeId').val(),
  445. school_id: schoolId
  446. };
  447. $.ajax({
  448. url: '/gcc/api/gccschool/buildingasset/editRoom',
  449. method: 'POST',
  450. contentType: 'application/json',
  451. data: JSON.stringify(updatedRoom),
  452. success: function (response) {
  453. if (response === 'Rooms Edited Sucessfully') {
  454. $('#editRoomModal').modal('hide');
  455. Swal.fire({
  456. icon: 'success',
  457. title: 'Success',
  458. text: 'Room updated successfully',
  459. allowOutsideClick: false,
  460. allowEscapeKey: false,
  461. allowEnterKey: false,
  462. showConfirmButton: true
  463. }).then(() => {
  464. loadSavedRoomDetails(schoolId);
  465. });
  466. } else {
  467. Swal.fire({
  468. icon: 'error',
  469. title: 'Error',
  470. text: response || "Update failed",
  471. allowOutsideClick: false,
  472. allowEscapeKey: false,
  473. allowEnterKey: false,
  474. showConfirmButton: true
  475. });
  476. }
  477. },
  478. error: function () {
  479. Swal.fire({
  480. icon: 'error',
  481. title: 'Error',
  482. text: "Something went wrong while saving changes",
  483. allowOutsideClick: false,
  484. allowEscapeKey: false,
  485. allowEnterKey: false,
  486. showConfirmButton: true
  487. });
  488. }
  489. });
  490. });
  491. $('#saveAddRoom').on('click', function () {
  492. const buildingId = $('#addBuildingId').val();
  493. const floorId = $('#addFloorId').val();
  494. const roomType = $('#addRoomTypeId').val();
  495. const roomName = $('#addRoomName').val().trim();
  496. if (!buildingId) {
  497. Swal.fire({
  498. icon: 'warning',
  499. title: 'Building Required',
  500. text: 'Please select a building .',
  501. allowOutsideClick: false,
  502. allowEscapeKey: false,
  503. allowEnterKey: false,
  504. showConfirmButton: true
  505. });
  506. return;
  507. }
  508. if (!floorId) {
  509. Swal.fire({
  510. icon: 'warning',
  511. title: 'Floor Required',
  512. text: 'Please select a floor .',
  513. allowOutsideClick: false,
  514. allowEscapeKey: false,
  515. allowEnterKey: false,
  516. showConfirmButton: true
  517. });
  518. return;
  519. }
  520. if (!roomType) {
  521. Swal.fire({
  522. icon: 'warning',
  523. title: 'Room Type Required',
  524. text: 'Please select a room type.',
  525. allowOutsideClick: false,
  526. allowEscapeKey: false,
  527. allowEnterKey: false,
  528. showConfirmButton: true
  529. });
  530. return;
  531. }
  532. if (!roomName) {
  533. Swal.fire({
  534. icon: 'warning',
  535. title: 'Room Name Required',
  536. text: 'Please enter a room name .',
  537. allowOutsideClick: false,
  538. allowEscapeKey: false,
  539. allowEnterKey: false,
  540. showConfirmButton: true
  541. });
  542. return;
  543. }
  544. const payload = {
  545. room_num: $('#addRoomName').val(),
  546. building_id: $('#addBuildingId').val(),
  547. floors_id: $('#addFloorId').val(),
  548. room_type: $('#addRoomTypeId').val(),
  549. school_id: schoolId
  550. };
  551. $.ajax({
  552. url: '/gcc/api/gccschool/buildingasset/saveRoom',
  553. type: 'POST',
  554. contentType: 'application/json',
  555. data: JSON.stringify(payload),
  556. success: function (response) {
  557. if (response === 'Rooms Mapped Sucessfully') {
  558. $('#addRoomModal').modal('hide');
  559. Swal.fire({
  560. title: "Success",
  561. text: "Room added successfully",
  562. icon: "success",
  563. allowOutsideClick: false, // Disable clicking outside the modal to close it
  564. allowEscapeKey: false, // Disable escape key to close the modal
  565. allowEnterKey: false, // Disable enter key to close the modal
  566. showConfirmButton: true
  567. }).then(() => {
  568. location.reload(); // 🔁 This reloads the page after user confirms the success alert
  569. });}
  570. else {
  571. Swal.fire({
  572. icon: 'error',
  573. title: 'Error',
  574. text: response || 'Save failed',
  575. allowOutsideClick: false,
  576. allowEscapeKey: false,
  577. allowEnterKey: false,
  578. showConfirmButton: true
  579. });
  580. }
  581. },
  582. error: function () {
  583. Swal.fire({
  584. icon: 'error',
  585. title: 'Error',
  586. text: 'Something went wrong while saving',
  587. allowOutsideClick: false,
  588. allowEscapeKey: false,
  589. allowEnterKey: false,
  590. showConfirmButton: true
  591. });
  592. }
  593. });
  594. });
  595. function loadFloorDropdown(buildingId, selectedFloorId = null) {
  596. $.ajax({
  597. url: '/gcc/api/gccschool/dropdown/getFloorsByBuilding',
  598. type: 'GET',
  599. data: { building_id: buildingId },
  600. success: function (response) {
  601. const dropdown = $('#editFloorId');
  602. dropdown.empty().append('<option value="">Select Floor</option>');
  603. if (response.status === 'OK') {
  604. response.data.forEach(floor => {
  605. const selected = floor.floors_id == selectedFloorId ? 'selected' : '';
  606. dropdown.append(`<option value="${floor.floors_id}" ${selected}>${floor.floor_name}</option>`);
  607. });
  608. }
  609. },
  610. error: function () {
  611. Swal.fire("Error", "Failed to load floors", "error");
  612. }
  613. });
  614. }
  615. $('#addBuildingId').on('change', function () {
  616. const buildingId = $(this).val();
  617. $.get('/gcc/api/gccschool/dropdown/getFloorsByBuilding', { building_id: buildingId }, function (response) {
  618. const dropdown = $('#addFloorId');
  619. dropdown.empty().append('<option value="">Select Floor</option>');
  620. if (response.status === 'OK') {
  621. response.data.forEach(floor => {
  622. dropdown.append(`<option value="${floor.floors_id}">${floor.floor_name}</option>`);
  623. });
  624. }
  625. });
  626. });
  627. $('#roomDelete').on('click', function () {
  628. const roomId = $('#editRoomId').val();
  629. const isDelete = true;
  630. Swal.fire({
  631. title: 'Are you sure?',
  632. text: "Do you really want to delete this room?",
  633. icon: 'warning',
  634. showCancelButton: true,
  635. confirmButtonColor: '#d33',
  636. cancelButtonColor: '#3085d6',
  637. confirmButtonText: 'Yes, delete it!',
  638. cancelButtonText: 'No, cancel',
  639. allowOutsideClick: false,
  640. allowEscapeKey: false,
  641. allowEnterKey: false,
  642. showConfirmButton: true
  643. }).then((result) => {
  644. if (result.isConfirmed) {
  645. // Call AJAX only if user confirms
  646. $.ajax({
  647. url: '/gcc/api/gccschool/buildingasset/deleteRoom',
  648. method: 'POST',
  649. data: {
  650. room_id: roomId,
  651. is_delete: isDelete
  652. },
  653. success: function (response) {
  654. Swal.fire({
  655. icon: 'success',
  656. title: 'Success',
  657. text: response,
  658. allowOutsideClick: false,
  659. allowEscapeKey: false,
  660. allowEnterKey: false,
  661. confirmButtonText: 'OK'
  662. }).then(() => {
  663. location.reload();
  664. });
  665. },
  666. error: function () {
  667. Swal.fire({
  668. icon: 'error',
  669. title: 'Error',
  670. text: 'Failed to delete the room.',
  671. allowOutsideClick: false,
  672. allowEscapeKey: false,
  673. allowEnterKey: false,
  674. showConfirmButton: true
  675. });
  676. }
  677. });
  678. } else if (result.dismiss === Swal.DismissReason.cancel) {
  679. // Show info alert when cancelled
  680. Swal.fire({
  681. icon: 'info',
  682. title: 'Cancelled',
  683. text: 'No changes were made.',
  684. allowOutsideClick: false,
  685. allowEscapeKey: false,
  686. allowEnterKey: false,
  687. showConfirmButton: true
  688. });
  689. }
  690. });
  691. });
  692. </script>
  693. </html>