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.

388 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}"></head>
  4. <meta charset="ISO-8859-1">
  5. </head>
  6. <body>
  7. <style>
  8. .small-input {
  9. width: 150px;
  10. /* Adjust the width as needed */
  11. }
  12. .small-table th,
  13. .small-table td {
  14. font-size: 14px;
  15. /* Adjust font size as needed */
  16. }
  17. /* Reduce padding for table cells */
  18. .small-table td,
  19. .small-table th {
  20. padding: 5px;
  21. /* Adjust padding as needed */
  22. }
  23. </style>
  24. <body>
  25. <!-- Page Container -->
  26. <div id="page-container"
  27. class="sidebar-o sidebar-dark enable-page-overlay side-scroll page-header-fixed page-header-dark">
  28. <!-- Side Overlay aside (right)-->
  29. <aside th:replace="~{fragments/aside-right :: aside}"></aside>
  30. <!-- END Side Overlay (right)-->
  31. <!-- Sidebar Nav-->
  32. <nav th:replace="~{fragments/nav-admin :: nav}"></nav>
  33. <!-- END Sidebar -->
  34. <!-- Header -->
  35. <header th:replace="~{fragments/header-admin :: header}"></header>
  36. <!-- END Header -->
  37. <!-- Main Container -->
  38. <main id="main-container">
  39. <div class="content">
  40. <div class="block block-rounded">
  41. <div class="block-header block-header-default">
  42. <h3 class="block-title"> Notification</h3>
  43. <div class="block-options">
  44. <button type="button" class="btn-block-option" id="addButton" onclick="adddnewnotification()"><i
  45. class="far fa-plus-square"></i> Add New Notification</button>
  46. </div>
  47. </div>
  48. <!-- Page Content -->
  49. <div class="content">
  50. <div class="block block-rounded">
  51. <div class="block-content p-0">
  52. <div class="p-sm-4 p-0">
  53. <div class="table-responsive">
  54. <table id="discountrangetable"
  55. class="table table-bordered table-striped table-vcenter js-dataTable-responsive">
  56. <thead class="thead-light">
  57. <tr class="table-bordered">
  58. <th class="text-center no-sort">S.No</th>
  59. <th class="text-center text-wrap" width="20%">Notification Message</th>
  60. <th class="text-center">Created date</th>
  61. <th class="text-center">created BY</th>
  62. <th class="text-center">Action</th>
  63. </tr>
  64. </thead>
  65. <tbody>
  66. <tr th:each="newnotifications, rowStat : ${newnotifications}">
  67. <td class="text-center" th:text="${rowStat.index + 1}"></td>
  68. <td class="text-center" th:text="${newnotifications.notification_description}"></td>
  69. <td class="text-center" th:text="${newnotifications.cdate}"></td>
  70. <td class="text-center" th:text="${newnotifications.createdBY}"></td>
  71. <td class="text-center">
  72. <a href="javascript:void(0);"
  73. th:onclick="return callDelete( [[${newnotifications.id}]] );"
  74. data-bs-toggle="tooltip" data-bs-animation="true"
  75. data-bs-placement="top" title="Delete"><i
  76. class="far fa-trash-can"
  77. style="font-size: 18px;"></i></a>
  78. </a>
  79. </td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <!-- new Discount -->
  89. <div class="modal fade" id="saveModal" tabindex="-1" role="dialog"
  90. aria-labelledby="saveModalLabel" aria-hidden="true">
  91. <div class="modal-dialog" role="document">
  92. <div class="modal-content">
  93. <div class="modal-header">
  94. <h5 class="modal-title" id="saveModalLabel">Save New Notification</h5>
  95. <button type="button" class="btn-block-option" data-bs-dismiss="modal">
  96. <i class="fa fa-fw fa-times"></i>
  97. </button>
  98. </div>
  99. <div class="modal-body">
  100. <form id="saveForm">
  101. <div class="form-group">
  102. <label for="userType">Notification Message</label>
  103. <textarea class="form-control " name="notification" id="notification" required style="height: 9px;"></textarea>
  104. </div>
  105. </form>
  106. </div>
  107. <div class="modal-footer">
  108. <button type="button" class="btn btn-secondary"
  109. data-bs-dismiss="modal">Close</button>
  110. <button type="button" class="btn btn-primary" id="savenotification">Save</button>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. <!-- Edit Form -->
  116. <div class="modal fade" id="editModal" tabindex="-1" role="dialog"
  117. aria-labelledby="editModalLabel" aria-hidden="true">
  118. <div class="modal-dialog" role="document">
  119. <div class="modal-content">
  120. <div class="modal-header">
  121. <h5 class="modal-title" id="editModalLabel">Edit Discount Range</h5>
  122. <button type="button" class="btn-block-option" data-bs-dismiss="modal">
  123. <i class="fa fa-fw fa-times"></i>
  124. </button>
  125. </div>
  126. <div class="modal-body">
  127. <form id="editForm">
  128. <input type="hidden" id="editId">
  129. <div class="form-group">
  130. <label for="editUsertype">User Type</label>
  131. <input type="text" class="form-control" id="editUsertype" readonly>
  132. </div>
  133. <div class="form-group">
  134. <label for="editDiscountRange">Discount Range in Percentage</label>
  135. <input type="text" class="form-control" id="editDiscountRange"
  136. placeholder="Discount Range in %" required>
  137. </div>
  138. <div class="form-group">
  139. <label for="editCDate">Creation Date</label>
  140. <input type="date" class="form-control" id="editCDate" readonly>
  141. </div>
  142. <div class="form-group">
  143. <label for="editUpdatedBy">Updated By</label>
  144. <input type="text" class="form-control" id="editUpdatedBy" readonly>
  145. </div>
  146. </form>
  147. </div>
  148. <div class="modal-footer">
  149. <button type="button" class="btn btn-secondary"
  150. data-bs-dismiss="modal">Close</button>
  151. <button type="button" class="btn btn-primary" id="saveChanges">Save
  152. changes</button>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </main>
  158. <div th:replace="~{fragments/resetpassword :: div}"></div>
  159. <footer th:replace="~{fragments/footer2 :: footer}"></footer>
  160. <script th:replace="~{fragments/loginscript :: script}"></script>
  161. <script>
  162. $(document).ready(
  163. function () {
  164. var buttons = [{
  165. extend: 'pageLength',
  166. className: 'btn btn-primary'
  167. }, {
  168. title: 'Data export',
  169. extend: 'copyHtml5',
  170. text: 'Copy',
  171. className: 'btn btn-primary',
  172. id: 'copyBtn'
  173. }, {
  174. extend: 'excelHtml5',
  175. text: 'Excel',
  176. className: 'btn btn-primary',
  177. id: 'excelBtn'
  178. }, {
  179. extend: 'csvHtml5',
  180. text: 'CSV',
  181. className: 'btn btn-primary',
  182. id: 'csvBtn'
  183. }, {
  184. extend: 'pdfHtml5',
  185. text: 'PDF',
  186. className: 'btn btn-primary',
  187. id: 'pdfBtn'
  188. },
  189. ];
  190. $('#discountrangetable').DataTable(
  191. {
  192. dom: 'Bftip',
  193. columnDefs: [{
  194. targets: 'no-sort',
  195. orderable: false
  196. }],
  197. lengthMenu: [
  198. [50, 100, 200, 500, -1],
  199. ['50 rows', '100 rows', '200 rows',
  200. '500 rows', 'Show all']],
  201. scrollY: '50vh',
  202. fixedColumns: {
  203. left: 1,
  204. right: 1
  205. },
  206. buttons: [buttons],
  207. responsive: true,
  208. searching: true, // Enable search
  209. select: false,
  210. processing: false,
  211. });
  212. // Link the search input to DataTable
  213. $('#searchInput').on('keyup', function () {
  214. dataTable.search(this.value).draw();
  215. });
  216. });
  217. function openEditModal(id) {
  218. $.ajax({
  219. type: "GET",
  220. url: '/communityhall/admin/api/getDiscountDetails',
  221. data: {
  222. 'id': id
  223. },
  224. success: function (response) {
  225. $('#editId').val(response.id);
  226. $('#editUsertype').val(response.usertype);
  227. $('#editDiscountRange').val(response.discountRange);
  228. $('#editCDate').val(response.cDate);
  229. $('#editUpdatedBy').val(response.updtedBy);
  230. $('#editModal').modal('show');
  231. }
  232. });
  233. }
  234. function adddnewnotification() {
  235. $('#saveModal').modal('show');
  236. }
  237. $('#savenotification').click(function () {
  238. var notification = $('#notification').val();
  239. if (notification=='') {
  240. Swal.fire(
  241. 'Error!',
  242. 'Please Enter the Notification.',
  243. 'error'
  244. );
  245. return false;
  246. }
  247. $.ajax({
  248. type: "POST",
  249. url: "/communityhall/admin/api/savenotification",
  250. data: {
  251. notification: notification
  252. },
  253. success: function (response) {
  254. if (response === 'success') {
  255. Swal.fire(
  256. 'Saved!',
  257. 'Details saved successfully.',
  258. 'success'
  259. ).then(() => {
  260. location.reload();
  261. });
  262. }
  263. },
  264. error: function (xhr, status, error) {
  265. Swal.fire(
  266. 'Error!',
  267. 'Failed to update the discount range.',
  268. 'error'
  269. );
  270. }
  271. });
  272. });
  273. $('#saveChanges').click(function () {
  274. var id = $('#editId').val();
  275. var discountRange = $('#editDiscountRange').val();
  276. // Log the data to the console for debugging
  277. $.ajax({
  278. type: "PUT",
  279. url: "/communityhall/admin/api/updateById/" + id,
  280. data: {
  281. 'id': id,
  282. 'discountRange': discountRange,
  283. },
  284. success: function (data) {
  285. Swal.fire(
  286. 'Updated!',
  287. 'Discount range ' + id + ' has been updated.',
  288. 'success'
  289. ).then(() => {
  290. location.reload();
  291. });
  292. },
  293. error: function (xhr, status, error) {
  294. console.error('Error occurred during the PUT request:', xhr.responseText);
  295. Swal.fire(
  296. 'Error!',
  297. 'Failed to update the discount range ' + id + ': ' + xhr.responseText,
  298. 'error'
  299. );
  300. }
  301. });
  302. });
  303. function callDelete(id) {
  304. Swal.fire({
  305. title: 'Are you sure you want to delete this?',
  306. text: "You won't be able to revert this!",
  307. icon: 'warning',
  308. showCancelButton: true,
  309. confirmButtonColor: '#3085d6',
  310. cancelButtonColor: '#d33',
  311. confirmButtonText: 'Yes, delete it!'
  312. }).then(function (result) {
  313. if (result.isConfirmed) {
  314. $.ajax({
  315. type: "POST",
  316. url: "/communityhall/admin/api/deletenotificationById/" + id,
  317. success: function (data) {
  318. Swal.fire(
  319. 'Deleted!',
  320. 'Entry ' + id + ' has been deleted.',
  321. 'success'
  322. ).then(() => {
  323. location.reload();
  324. });
  325. },
  326. error: function (xhr, status, error) {
  327. Swal.fire(
  328. 'Error!',
  329. 'Failed to delete entry ' + id + ': ' + xhr.responseText,
  330. 'error'
  331. );
  332. }
  333. });
  334. }
  335. });
  336. }
  337. document.addEventListener('DOMContentLoaded', function () {
  338. function clearModalFields(modalId) {
  339. const modal = document.getElementById(modalId);
  340. if (modal) {
  341. // Clear text inputs and select elements
  342. modal.querySelectorAll('input[type="text"], input[type="date"], select').forEach(input => {
  343. if (input.tagName === 'SELECT') {
  344. input.selectedIndex = 0; // Reset to default option
  345. } else {
  346. input.value = ''; // Clear text inputs
  347. }
  348. });
  349. }
  350. }
  351. // Clear fields when the saveModal is hidden
  352. document.getElementById('saveModal').addEventListener('hidden.bs.modal', function () {
  353. clearModalFields('saveModal');
  354. });
  355. });
  356. </script>
  357. </body>
  358. </html>