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.

344 lines
12 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head th:replace="~{fragments/head-admin :: head}">
  4. <meta charset="ISO-8859-1">
  5. <!-- Include DataTables CSS -->
  6. </head>
  7. <style>
  8. .block-content {
  9. padding-bottom: 10px;
  10. }
  11. .small-input {
  12. width: 150px;
  13. /* Adjust the width as needed */
  14. }
  15. .small-table th,
  16. .small-table td {
  17. font-size: 14px;
  18. /* Adjust font size as needed */
  19. }
  20. /* Reduce padding for table cells */
  21. .small-table td,
  22. .small-table th {
  23. padding: 5px;
  24. /* Adjust padding as needed */
  25. }
  26. </style>
  27. <body>
  28. <!-- Page Container -->
  29. <div id="page-container"
  30. class="sidebar-o sidebar-dark enable-page-overlay side-scroll page-header-fixed page-header-dark">
  31. <!-- Side Overlay aside (right)-->
  32. <aside th:replace="~{fragments/aside-right :: aside}"></aside>
  33. <!-- END Side Overlay (right)-->
  34. <!-- Sidebar Nav-->
  35. <nav th:replace="~{fragments/nav-admin :: nav}"></nav>
  36. <!-- END Sidebar -->
  37. <!-- Header -->
  38. <header th:replace="~{fragments/header-admin :: header}"></header>
  39. <!-- END Header -->
  40. <!-- Main Container -->
  41. <main id="main-container">
  42. <!-- Page Content -->
  43. <div class="content">
  44. <div class="block block-rounded">
  45. <form id="userdetailsform">
  46. <div class="block-header bg-primary text-white">
  47. <h3 class="block-title">User Details</h3>
  48. </div>
  49. <div class="block-content">
  50. <div class="row">
  51. <div class="col-sm-3">
  52. <label class="form-label" for="mobileNO">Mobile NO:<span
  53. class="text-danger">*</span></label>
  54. <input type="text" class="form-control" name="mobileNO" id="mobileNO"
  55. placeholder="Mobile Number" required="required" minlength="10" maxlength="10"
  56. oninput="this.value = this.value.replace(/[^0-9]/g, '').slice(0, 10);" />
  57. </div>
  58. <div class="col-sm-3">
  59. <br>
  60. <button type="submit" class="btn btn-sm btn-primary" name="submit"
  61. id="submit">Submit</button>
  62. <button class="btn btn-danger" onclick="resetDate()" name="reset"
  63. type="reset">Reset</button>
  64. </div>
  65. </div>
  66. </div>
  67. </form>
  68. </div>
  69. <!-- User Details Card Container -->
  70. <!-- User Details Card Container -->
  71. <div id="userDetailsCardContainer" style="display: none;">
  72. <div class="card">
  73. <div class="block-header bg-primary text-white">
  74. <h3 class="block-title">User Details</h3>
  75. </div>
  76. <div class="card-body">
  77. <div class="block-content row">
  78. <input type="hidden" class="form-control text-center" name="userId" id="userId"
  79. disabled />
  80. <div class="col-sm-4">
  81. <label class="form-label">Name:<span class="text-danger"></span></label>
  82. <input type="text" class="form-control text-center" name="name" id="userName"
  83. disabled />
  84. </div>
  85. <div class="col-sm-4">
  86. <label class="form-label">Mobile No:<span class="text-danger"></span></label>
  87. <input type="text" class="form-control text-center" name="mobile" id="userMobile"
  88. disabled />
  89. </div>
  90. <div class="col-sm-4">
  91. <label class="form-label">E-Mail ID:<span class="text-danger"></span></label>
  92. <input type="text" class="form-control text-center" name="email" id="userEmail"
  93. disabled />
  94. </div>
  95. <div class="col-sm-4">
  96. <label class="form-label">Street:<span class="text-danger"></span></label>
  97. <input type="text" class="form-control text-center" name="street" id="userStreet"
  98. disabled />
  99. </div>
  100. <div class="col-sm-4">
  101. <label class="form-label">Area:<span class="text-danger"></span></label>
  102. <input type="text" class="form-control text-center" name="area" id="userArea"
  103. disabled />
  104. </div>
  105. <div class="col-sm-4">
  106. <label class="form-label">Location:<span class="text-danger"></span></label>
  107. <input type="text" class="form-control text-center" name="location"
  108. id="userLocation" disabled />
  109. </div>
  110. <div class="col-sm-4">
  111. <label class="form-label">Pincode:<span class="text-danger"></span></label>
  112. <input type="text" class="form-control text-center" name="pincode" id="userPincode"
  113. disabled />
  114. </div>
  115. <div class="col-sm-4">
  116. <label class="form-label">UserType:<span class="text-danger"></span></label>
  117. <input type="text" class="form-control text-center" name="usertype"
  118. id="userUsertype" disabled />
  119. </div>
  120. <div class="col-sm-4">
  121. <label class="form-label">User Status:<span class="text-danger"></span></label>
  122. <input type="text" class="form-control text-center" name="userstatus"
  123. id="userUserstatus" disabled />
  124. </div>
  125. <div class="col-12 d-flex justify-content-center mt-3">
  126. <button id="viewAllBookingBtn" class="btn btn-primary mx-2">View All
  127. Booking</button>
  128. <button id="activateDeactivateBtn" class="btn mx-2">Activate/Deactivate</button>
  129. </div>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. <!-- Booking Table Card Container -->
  135. <div id="bookingTableCardContainer" class="card" style="display: none;">
  136. <div class="block-header bg-primary text-white">
  137. <h3 class="block-title">Booking Table</h3>
  138. </div>
  139. <div class="card-body">
  140. <div class="table-responsive">
  141. <table id="requestTable1" class="table table-striped table-bordered table-hover dataTable"
  142. role="grid" width="99.5%">
  143. <thead class="thead-dark">
  144. <tr role="row">
  145. <th>S.No</th>
  146. <th>Hall Name</th>
  147. <th>Booking Date</th>
  148. <th>Starting Date</th>
  149. <th>Ending Date</th>
  150. <th>Starting Slot</th>
  151. <th>Ending Slot</th>
  152. <th>No of Days</th>
  153. <th>Reason for Booking</th>
  154. <th>BookingStatus</th>
  155. </tr>
  156. </thead>
  157. <tbody id="bookingTableBody">
  158. <!-- Table rows will be populated dynamically -->
  159. </tbody>
  160. </table>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </main>
  166. <footer th:replace="~{fragments/footer2 :: footer}"></footer>
  167. </div>
  168. <div th:replace="~{fragments/resetpassword :: div}"></div>
  169. <script th:replace="~{fragments/loginscript :: script}"></script>
  170. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  171. <script>
  172. function activateDeactivateUser(userId, isActive) {
  173. $.ajax({
  174. type: "POST",
  175. url: "/communityhall/api/officer/toggleStatus",
  176. data: {
  177. userId: userId,
  178. active: isActive
  179. },
  180. success: function (response) {
  181. //console.log(response);
  182. // Refresh user details after activation/deactivation
  183. var mobileNo = $('#userMobile').val();
  184. fetchUserDetails(mobileNo);
  185. location.reload();
  186. },
  187. error: function (error) {
  188. //console.error('Error activating/deactivating user:', error);
  189. }
  190. });
  191. }
  192. var userId = ''; // Global variable to store userId
  193. function fetchUserDetails(mobileNo) {
  194. var userType = $('#usertype').val(); // Assuming this retrieves the current user's usertype
  195. // Validate if mobileNo is provided and is exactly 10 digits
  196. if (!mobileNo || mobileNo.length !== 10 || !/^\d{10}$/.test(mobileNo)) {
  197. Swal.fire({
  198. icon: 'error',
  199. title: 'Invalid Mobile Number',
  200. text: 'Please enter a valid 10-digit mobile number.',
  201. }).then(() => {
  202. location.reload(); // Reload the page after the alert is closed
  203. });
  204. return; // Exit function if mobile number is invalid
  205. }
  206. $.ajax({
  207. type: "GET",
  208. url: "/communityhall/user/api/getuserDetailsbymobileno",
  209. data: {
  210. 'mobileNo': mobileNo
  211. },
  212. success: function (data) {
  213. // Check if data is empty or null
  214. if (!data || Object.keys(data).length === 0) {
  215. Swal.fire({
  216. icon: 'error',
  217. title: 'Mobile Number Not Found',
  218. text: 'The provided mobile number does not exist in the database.',
  219. }).then(() => {
  220. location.reload(); // Reload the page after the alert is closed
  221. });
  222. return; // Exit function if mobile number is not found
  223. }
  224. // Set global userId variable
  225. userId = data.userId;
  226. // Update UI with user details
  227. $('#userId').val(data.id);
  228. $('#userName').val(data.name);
  229. $('#userMobile').val(data.mobileNo);
  230. $('#userEmail').val(data.email);
  231. $('#userStreet').val(data.street);
  232. $('#userArea').val(data.area);
  233. $('#userLocation').val(data.location);
  234. $('#userPincode').val(data.pinCode);
  235. $('#userUsertype').val(data.usertype);
  236. $('#userUserstatus').val(data.userstatus);
  237. // Determine button text and class based on user's active status
  238. var isActive = data.active;
  239. var buttonText = isActive ? 'Deactivate User' : 'Activate User';
  240. var buttonClass = isActive ? 'btn-danger' : 'btn-success';
  241. // Update button text and class
  242. $('#activateDeactivateBtn')
  243. .text(buttonText)
  244. .removeClass('btn-success btn-danger')
  245. .addClass(buttonClass)
  246. .show();
  247. $('#userDetailsCardContainer').show(); // Show user details container
  248. },
  249. error: function (error) {
  250. console.error('Error fetching user details:', error);
  251. // Handle error (optional): display a message or take appropriate action
  252. Swal.fire({
  253. icon: 'error',
  254. title: 'Error Fetching User Details',
  255. text: 'An error occurred while fetching user details. Please try again later.',
  256. }).then(() => {
  257. location.reload(); // Reload the page after the alert is closed
  258. });
  259. }
  260. });
  261. }
  262. $(document).ready(function () {
  263. $('#userdetailsform').submit(function (event) {
  264. event.preventDefault();
  265. var mobileNo = $('#mobileNO').val();
  266. fetchUserDetails(mobileNo);
  267. $('#bookingTableCardContainer').hide();
  268. });
  269. // Click event for activate/deactivate button
  270. $('#activateDeactivateBtn').click(function () {
  271. // Use the global userId variable
  272. var action = $(this).text().includes('Deactivate') ? false : true; // Corrected logic
  273. activateDeactivateUser(userId, action);
  274. });
  275. $('#viewAllBookingBtn').click(function () {
  276. showBookingDetailsByUserId(userId);
  277. });
  278. });
  279. function showBookingDetailsByUserId(userId) {
  280. $.ajax({
  281. type: "GET",
  282. url: "/communityhall/admin/api/bookingdetailsByuserId",
  283. data: {
  284. userId: userId
  285. },
  286. success: function (response) {
  287. //console.log('Data retrieved successfully', response);
  288. // Clear existing table rows
  289. $('#requestTable1 tbody').empty();
  290. // Populate the table with new data
  291. $.each(response, function (index, booking) {
  292. var row = `
  293. <tr>
  294. <td>${index + 1}</td>
  295. <td>${booking.hallDetails.hallName}</td>
  296. <td>${booking.bookingDate}</td>
  297. <td>${booking.startDate}</td>
  298. <td>${booking.endDate}</td>
  299. <td>${booking.startingSlot}</td>
  300. <td>${booking.endingSlot}</td>
  301. <td>${booking.noOfDays}</td>
  302. <td>${booking.reason}</td>
  303. <td>${booking.bookingStatus}</td>
  304. </tr>`;
  305. $('#requestTable1 tbody').append(row);
  306. });
  307. // Show the booking details container
  308. $('#bookingTableCardContainer').show();
  309. },
  310. error: function (error) {
  311. //console.error('Error retrieving booking details:', error);
  312. }
  313. });
  314. }
  315. function resetDate() {
  316. $('#bookingTableCardContainer').hide();
  317. $('#userDetailsCardContainer').hide();
  318. }
  319. </script>
  320. </body>
  321. </html>