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.

575 lines
14 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
  3. <head th:replace="~{fragments/modules/base/head :: head}"></head>
  4. <style>
  5. </style>
  6. <body>
  7. <div class="wrapper">
  8. <!-- header top menu Start -->
  9. <header th:replace="~{fragments/modules/base/header :: header}"></header>
  10. <!-- header top menu end -->
  11. <div class="page-wrap">
  12. <!--=============== Left Menu side Start ================-->
  13. <div th:replace="~{fragments/modules/base/menu :: menu}"></div>
  14. <!--=============== Left side End ================-->
  15. <div class="main-content">
  16. <div class="container-fluid">
  17. <div class="page-header mb-2">
  18. <div class="row align-items-end">
  19. <div class="col-lg-12">
  20. <div class="page-header-title d-flex justify-content-between align-items-center ">
  21. <!-- <i class="far fa-calendar-plus bg-blue"></i> -->
  22. <div class="">
  23. <h5 >Training Management</h5>
  24. <span>Manage training centres, halls, and sessions</span>
  25. </div>
  26. <div class="form-group ">
  27. <button type="submit" class="btn btn-primary " id="createBtn">Create New Training</button>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <!-- searching card -->
  34. <div class="row">
  35. <div class="col-md-12">
  36. <div class="card" style="margin-top: 15px;">
  37. <div class="card-body">
  38. <input type="hidden" id="loginUserId" th:value="${loginUserId}">
  39. <div class="form-group">
  40. <div class="row">
  41. <!-- Training Centre -->
  42. <div class="col-sm-12 col-md-4">
  43. <label class="form-label" for="trainingCentre">Training Centre</label>
  44. <select class="form-control" id="trainingCentre" >
  45. <option value=""> Select Centre </option>
  46. </select>
  47. </div>
  48. <div class="col-sm-12 col-md-4 mt-4 d-flex align-items-end">
  49. <button type="submit" class="btn btn-primary " id="searchBtn">Search</button>
  50. <button type="reset" class="btn btn-secondary ml-2" id="resetBtn">Reset</button>
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. <div class="row">
  59. <div class="col-12">
  60. <div class="card">
  61. <div class="card-header">
  62. <h3><b>All Training Centre</b></h3>
  63. </div>
  64. <div class="card-body">
  65. <table id="trainingDatatable" class="table table-striped table-bordered table-hover dataTable" role="grid" >
  66. <thead class="thead-dark" >
  67. <tr role="row">
  68. <th class="text-center">S.No</th>
  69. <th class="text-center">Training Centre</th>
  70. <th class="text-center">Address</th>
  71. <th class="text-center">Capacity</th>
  72. </tr>
  73. </thead>
  74. <tbody style="text-align:center;">
  75. </tbody>
  76. </table>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. <!-- create training modal box -->
  84. <div class="modal fade" id="createTrainingModal" tabindex="-1">
  85. <div class="modal-dialog modal-xl">
  86. <div class="modal-content">
  87. <div class="modal-header">
  88. <h5 class="modal-title">Create Training Hall</h5>
  89. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  90. <span aria-hidden="true">&times;</span>
  91. </button>
  92. </div>
  93. <div class="modal-body">
  94. <div class="row ">
  95. <!--<div class="col-sm-12 col-md-4 mt-2">
  96. <label class="form-label" for="selectConstituency">Select Constituency <span class="text-danger">*</span></label>
  97. <select class="form-control" id="selectConstituency" required>
  98. </select>
  99. </div>-->
  100. <div class="col-sm-12 col-md-4 mt-2">
  101. <label class="form-label" for="tCentre">Training Centre <span class="text-danger">*</span></label>
  102. <select class="form-control" id="tCentre" required>
  103. </select>
  104. </div>
  105. <div class="col-sm-12 col-md-4 mt-2">
  106. <label class="form-label" for="hall">No of Hall <span class="text-danger">*</span></label>
  107. <input type="text" class="form-control" id="hall" oninput="this.value=this.value.replace(/[^0-9]/g,'')"/>
  108. </div>
  109. <div class="col-sm-12 col-md-4 mt-2">
  110. <label class="form-label " for="capacity">Capacity Per Hall <span class="text-danger">*</span></label>
  111. <input type="text" class="form-control" id="capacity" oninput="this.value=this.value.replace(/[^0-9]/g,'')"/>
  112. </div>
  113. <div class="col-sm-12 col-md-4 mt-2">
  114. <label class="form-label " for="totalcapacity">Total Capacity <span class="text-danger">*</span></label>
  115. <input type="text" class="form-control" id="totalcapacity" readonly>
  116. </div>
  117. <div class="col-sm-12 col-md-8 mt-2">
  118. <label class="form-label" for="centreAddress">Centre Address <span class="text-danger">*</span></label>
  119. <input type="text" class="form-control" id="centreAddress" readonly>
  120. </div>
  121. <!--<div class="col-sm-12 col-md-4 mt-2">
  122. <label class="form-label" for="sessionDate">Session Date <span class="text-danger">*</span></label>
  123. <input type="date" class="form-control" id="sessionDate" required>
  124. </div>
  125. &lt;!&ndash; FROM TIME &ndash;&gt;
  126. <div class="col-sm-12 col-md-4 mt-2">
  127. <label class="form-label">From Time <span class="text-danger">*</span></label>
  128. <select class="form-control" id="fromTime" required>
  129. <option value="">&#45;&#45;:&#45;&#45; &#45;&#45;</option>
  130. </select>
  131. </div>
  132. &lt;!&ndash; TO TIME &ndash;&gt;
  133. <div class="col-sm-12 col-md-4 mt-2">
  134. <label class="form-label">To Time <span class="text-danger">*</span></label>
  135. <select class="form-control" id="toTime" required>
  136. <option value="">&#45;&#45;:&#45;&#45; &#45;&#45;</option>
  137. </select>
  138. </div>
  139. <div class="col-sm-12 col-md-4 mt-2">
  140. <label class="form-label" for="category">Category<span class="text-danger">*</span></label>
  141. <select class="form-control" id="category" required>
  142. </select>
  143. </div>-->
  144. </div>
  145. </div>
  146. <div class="form-group text-center">
  147. <button type="submit" class="btn btn-primary " id="createdBtn">Create Hall</button>
  148. <button type="reset" class="btn btn-secondary ml-2" id="modalresetbtn">Reset</button>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <div id="pageLoader" 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;">
  154. <div style="position: relative; top: 50%; transform: translateY(-50%);">
  155. <div class="spinner-border text-primary" role="status" style="width: 3rem; height: 3rem;">
  156. <span class="sr-only">Loading...</span>
  157. </div>
  158. <!-- Add the 'Please wait' text below the spinner -->
  159. <p style="margin-top: 1rem; font-size: 1.2rem; color: #007bff;">Please wait...</p>
  160. </div>
  161. </div>
  162. <footer th:replace="~{fragments/modules/base/footer :: footer}"></footer>
  163. </div>
  164. </div>
  165. <script th:replace="~{fragments/modules/base/script :: script}"></script>
  166. <script type="text/javascript">
  167. // Reset Button
  168. document.getElementById('resetBtn').addEventListener('click', function (e) {
  169. e.preventDefault();
  170. location.reload();
  171. });
  172. // Load training Modal
  173. document.getElementById("createBtn").addEventListener("click", function () {
  174. $("#createTrainingModal").modal("show");
  175. });
  176. // datatable initially loaded
  177. $(document).ready(function() {
  178. var table = $('#trainingDatatable').DataTable({
  179. dom: 'Bftip',
  180. columnDefs: [
  181. { targets: 'no-sort', orderable: false }
  182. ],
  183. lengthMenu: [
  184. [50, 100, 200, 500, -1],
  185. ['50 rows', '100 rows', '200 rows', 'Show all']
  186. ],
  187. scrollY: '80vh',
  188. scrollX: true,
  189. buttons: [
  190. {
  191. extend: 'pageLength',
  192. className: 'btn btn-warning'
  193. },
  194. {
  195. title: 'Data export',
  196. extend: 'copyHtml5',
  197. text: 'Copy',
  198. className: 'btn btn-secondary',
  199. id: 'copyBtn'
  200. },
  201. {
  202. extend: 'excelHtml5',
  203. text: 'Excel',
  204. className: 'btn btn-secondary',
  205. id: 'excelBtn'
  206. },
  207. {
  208. extend: 'csvHtml5',
  209. text: 'CSV',
  210. className: 'btn btn-secondary',
  211. id: 'csvBtn'
  212. },
  213. {
  214. extend: 'pdfHtml5',
  215. text: 'PDF',
  216. className: 'btn btn-secondary',
  217. id: 'pdfBtn'
  218. }
  219. ],
  220. fixedHeader: false,
  221. autoWidth: false,
  222. responsive: false,
  223. searching: true,
  224. select: false,
  225. processing: false,
  226. columns: [
  227. {
  228. data: null,
  229. render: function (data, type, row, meta) {
  230. return meta.row + 1; // Auto S.No
  231. }
  232. },
  233. { data: "C_NAME" },
  234. { data: "C_ADDRESS" },
  235. { data: "TOT_CAPT" }
  236. ]
  237. });
  238. // ✅ Load data on page load
  239. loadTrainingDetails();
  240. // dropdown for training centre and address
  241. $.ajax({
  242. url: "/election/api/trainingadmin/getAllCentre",
  243. type: "GET",
  244. success: function (data) {
  245. console.log("data",data)
  246. let centreDropdown = $("#tCentre");
  247. console.log("centreDropdown",centreDropdown)
  248. centreDropdown.empty().append('<option value="">-- Select Training Centre --</option>');
  249. data.forEach(function (obj) {
  250. centreDropdown.append(
  251. `<option value="${obj.c_code}">${obj.c_name}</option>`
  252. );
  253. });
  254. },
  255. error: function () {
  256. Swal.fire("Error", "Failed to load training centres", "error");
  257. }
  258. });
  259. loadConstituency();
  260. loadCategory();
  261. $.ajax({
  262. url: "/election/api/trainingadmin/getAllCentre",
  263. type: "GET",
  264. success: function (data) {
  265. let searchDropdown = $("#trainingCentre");
  266. searchDropdown.empty().append('<option value="">-- Select Centre --</option>');
  267. data.forEach(obj => {
  268. searchDropdown.append(
  269. `<option value="${obj.c_name}">${obj.c_name}</option>`
  270. );
  271. });
  272. }
  273. });
  274. });
  275. $("#tCentre").on("change", function () {
  276. let centreCode = $(this).val();
  277. // Clear address if nothing selected
  278. if (!centreCode) {
  279. $("#centreAddress").val("");
  280. return;
  281. }
  282. $.ajax({
  283. url: "/election/api/trainingadmin/getAddressByCode",
  284. type: "GET",
  285. data: { code: centreCode },
  286. success: function (data) {
  287. if (data.length > 0) {
  288. $("#centreAddress").val(data[0].c_address);
  289. } else {
  290. $("#centreAddress").val("Address not found");
  291. }
  292. },
  293. error: function () {
  294. Swal.fire("Error", "Failed to load centre address", "error");
  295. }
  296. });
  297. });
  298. // constituency function
  299. function loadConstituency() {
  300. $("#selectConstituency")
  301. .empty()
  302. .append('<option value="">-- Select Constituency --</option>');
  303. $.ajax({
  304. url: "/election/api/trainingadmin/getAllConstituency", // ✅ NO PARAMS
  305. type: "GET",
  306. success: function (data) {
  307. console.log("Constituency List:", data);
  308. data.forEach(function (obj) {
  309. $("#selectConstituency").append(
  310. `<option value="${obj.ac_no}">${obj.ac_name}</option>`
  311. );
  312. });
  313. },
  314. error: function () {
  315. Swal.fire({
  316. icon: 'error',
  317. title: 'Error',
  318. text: 'Failed to load constituency list',
  319. confirmButtonText: 'OK'
  320. });
  321. }
  322. });
  323. }
  324. // loaded categories
  325. function loadCategory() {
  326. $("#category")
  327. .empty()
  328. .append('<option value="">-- Select Category --</option>');
  329. $.ajax({
  330. url: "/election/api/trainingadmin/getAllCategory", // ✅ NO PARAMS
  331. type: "GET",
  332. success: function (data) {
  333. console.log("Category List:", data);
  334. data.forEach(function (obj) {
  335. $("#category").append(
  336. `<option value="${obj.category}">${obj.category}</option>`
  337. );
  338. });
  339. },
  340. error: function () {
  341. Swal.fire({
  342. icon: 'error',
  343. title: 'Error',
  344. text: 'Failed to load constituency list',
  345. confirmButtonText: 'OK'
  346. });
  347. }
  348. });
  349. }
  350. $("#hall, #capacity").on("input", function () {
  351. let hall = parseInt($("#hall").val()) || 0;
  352. let cap = parseInt($("#capacity").val()) || 0;
  353. $("#totalcapacity").val(hall * cap);
  354. });
  355. $(document).on("click", "#createdBtn", function () {
  356. let centerId = $("#tCentre").val();
  357. let centerName = $("#tCentre option:selected").text();
  358. let noOfHall = $("#hall").val();
  359. let hallCapacity = $("#capacity").val();
  360. let totalCapacity = $("#totalcapacity").val();
  361. if (!centerName || !noOfHall || !hallCapacity || !totalCapacity) {
  362. Swal.fire("Warning", "All fields are required", "warning");
  363. return;
  364. }
  365. $.ajax({
  366. url: "/election/api/trainingadmin/saveTrainingCenter",
  367. type: "POST",
  368. data: {
  369. center_id: centerId,
  370. center_name: centerName,
  371. noofHall: noOfHall,
  372. hallCapacity: hallCapacity,
  373. totalCapacity: totalCapacity
  374. },
  375. success: function (response) {
  376. if (response.Data === "Success") {
  377. Swal.fire({
  378. icon: "success",
  379. title: "Success",
  380. text: "Training Hall Created Successfully!",
  381. confirmButtonText: "OK"
  382. }).then(() => {
  383. $("#createTrainingModal").modal("hide");
  384. location.reload();
  385. });
  386. } else {
  387. Swal.fire("Error", "Something went wrong!", "error");
  388. }
  389. },
  390. error: function () {
  391. Swal.fire("Error", "Server Error", "error");
  392. }
  393. });
  394. });
  395. // data table
  396. function loadTrainingDetails() {
  397. var table = $('#trainingDatatable').DataTable();
  398. table.clear().draw();
  399. $.ajax({
  400. url: "/election/api/trainingadmin/getTrainingDetails",
  401. type: "GET",
  402. success: function (data) {
  403. console.log("Training Data:", data);
  404. data.forEach(function (obj) {
  405. table.row.add(obj).draw();
  406. });
  407. },
  408. error: function () {
  409. Swal.fire("Error", "Failed to load training data", "error");
  410. }
  411. });
  412. }
  413. $("#searchBtn").on("click", function () {
  414. let centreName = $("#trainingCentre").val();
  415. let table = $('#trainingDatatable').DataTable();
  416. if (!centreName) {
  417. Swal.fire("Warning", "Please select a training centre", "warning");
  418. return;
  419. }
  420. // 🔍 Filter Training Centre column
  421. table.column(1).search(centreName).draw();
  422. });
  423. $("#modalresetbtn").on("click", function () {
  424. // Clear text & number inputs
  425. $("#createTrainingModal input[type='text']").val("");
  426. // Clear dropdowns
  427. $("#createTrainingModal select").val("");
  428. // Explicitly clear calculated / readonly fields
  429. $("#totalcapacity").val("");
  430. $("#centreAddress").val("");
  431. });
  432. </script>
  433. </body>
  434. </html>