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.

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