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.

467 lines
16 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <script src="node_modules/datatable/jQuery-3.7.0/jquery-3.7.0.min.js"></script>
  2. <script src="node_modules/jquery/dist/jquery.min.js"></script>
  3. <script src="node_modules/popper.js/dist/umd/popper.min.js"></script>
  4. <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  5. <script src="node_modules/perfect-scrollbar/dist/perfect-scrollbar.min.js"></script>
  6. <script src="node_modules/select2/dist/js/select2.min.js"></script>
  7. <script src="node_modules/screenfull/dist/screenfull.js"></script>
  8. <script src="node_modules/moment/moment.js"></script>
  9. <script src="node_modules/sweetalert2/sweetalert2.min.js"></script>
  10. <script src="node_modules/datatable/JSZip-3.10.1/jszip.min.js"></script>
  11. <script src="node_modules/datatable/pdfmake-0.2.7/pdfmake.min.js"></script>
  12. <script src="node_modules/datatable/pdfmake-0.2.7/vfs_fonts.js"></script>
  13. <script src="node_modules/datatable/DataTables-1.13.6/js/jquery.dataTables.min.js"></script>
  14. <script src="node_modules/datatable/AutoFill-2.6.0/js/dataTables.autoFill.min.js"></script>
  15. <script src="node_modules/datatable/Buttons-2.4.1/js/dataTables.buttons.min.js"></script>
  16. <script src="node_modules/datatable/Buttons-2.4.1/js/buttons.bootstrap4.min.js"></script>
  17. <script src="node_modules/datatable/Buttons-2.4.1/js/buttons.colVis.min.js"></script>
  18. <script src="node_modules/datatable/Buttons-2.4.1/js/buttons.html5.min.js"></script>
  19. <script src="node_modules/datatable/Buttons-2.4.1/js/buttons.print.min.js"></script>
  20. <script src="node_modules/datatable/ColReorder-1.7.0/js/dataTables.colReorder.min.js"></script>
  21. <script src="node_modules/datatable/DateTime-1.5.1/js/dataTables.dateTime.min.js"></script>
  22. <script src="node_modules/datatable/FixedColumns-4.3.0/js/dataTables.fixedColumns.min.js"></script>
  23. <script src="node_modules/datatable/FixedHeader-3.4.0/js/dataTables.fixedHeader.min.js"></script>
  24. <script src="node_modules/datatable/KeyTable-2.10.0/js/dataTables.keyTable.min.js"></script>
  25. <script src="node_modules/datatable/Responsive-2.5.0/js/dataTables.responsive.min.js"></script>
  26. <script src="node_modules/datatable/RowGroup-1.4.0/js/dataTables.rowGroup.min.js"></script>
  27. <script src="node_modules/datatable/RowReorder-1.4.1/js/dataTables.rowReorder.min.js"></script>
  28. <script src="node_modules/datatable/Scroller-2.2.0/js/dataTables.scroller.min.js"></script>
  29. <script src="node_modules/datatable/SearchBuilder-1.5.0/js/dataTables.searchBuilder.min.js"></script>
  30. <script src="node_modules/datatable/SearchPanes-2.2.0/js/dataTables.searchPanes.min.js"></script>
  31. <script src="node_modules/datatable/Select-1.7.0/js/dataTables.select.min.js"></script>
  32. <script src="node_modules/datatable/StateRestore-1.3.0/js/dataTables.stateRestore.min.js"></script>
  33. <script src="dist/js/theme.js"></script>
  34. <script th:inline="javascript">
  35. // Get the current page URL path
  36. var currentPagePath = window.location.pathname;
  37. // Remove the leading slash from the current page URL path
  38. currentPagePath = currentPagePath.substr(1);
  39. //alert(currentPagePath);
  40. // Get the parent menu item and the sub-menu item based on the current page URL path
  41. var parentMenuItem = document.querySelector('.nav-item.has-sub');
  42. var subMenuItem = document.querySelector('.submenu-content .menu-item[href="' + currentPagePath + '"]');
  43. // Add the "active" class to the parent menu item and its associated sub-menu item
  44. if (parentMenuItem && subMenuItem) {
  45. parentMenuItem.classList.add('active', 'open');
  46. subMenuItem.classList.add('active');
  47. }
  48. </script>
  49. <script th:inline="javascript">
  50. $(document).ready(function() {
  51. /*
  52. // Get the current URL
  53. var currentUrl = window.location.href;
  54. // Remove the query parameter from the URL
  55. var newUrl = currentUrl.split("?")[0];
  56. // Replace the current URL with the modified URL without the query parameter
  57. window.history.replaceState({}, document.title, newUrl);
  58. */
  59. //////////////////////////////////////////////////////////////////////////////////////////////////////
  60. var currentPagePath = window.location.pathname;
  61. //console.error(currentPagePath);
  62. currentPagePath = "/"+currentPagePath.substr(1);
  63. //console.error(currentPagePath);
  64. // Set active class for parent menu items
  65. $('.nav-item').each(function() {
  66. var link = $(this).find('a').attr('href');
  67. //console.log("Main: "+link +" == "+ currentPagePath);
  68. if (link === currentPagePath || link === currentPagePath) {
  69. $(this).addClass('active');
  70. $(this).parents('.has-sub').addClass('active open');
  71. }
  72. });
  73. // Set active class for submenu items
  74. $('.submenu-content .menu-item').each(function() {
  75. var link = $(this).attr('href');
  76. //console.log("Sub: "+link +" == "+ currentPagePath);
  77. if (link === currentPagePath || link === currentPagePath) {
  78. //console.error("Sub: "+link +" == "+ currentPagePath);
  79. $(this).addClass('active');
  80. $(this).parents('.has-sub').addClass('active open');
  81. }
  82. });
  83. $(document).ready(function(){
  84. $('[data-toggle="popover"]').popover();
  85. });
  86. $(".select2").select2();
  87. });
  88. function call_loading(div,action){
  89. var divID="#"+div;
  90. var loadingimage= `<center><img src="images/loading.svg" style="opacity: 1; visibility: visible; height:40px;"></center>`;
  91. if(action=='start'){
  92. $(divID).html(loadingimage)
  93. }
  94. }
  95. // Date format
  96. function convertdate(date_txt){
  97. var datetxt = date_txt;
  98. var date = new Date(datetxt);
  99. // Extract the date components
  100. var day = date.getDate();
  101. var month = date.getMonth() + 1; // Month starts from 0, so add 1
  102. var year = date.getFullYear();
  103. // Extract the time components
  104. var hours = date.getHours();
  105. var minutes = date.getMinutes();
  106. // Determine if it's AM or PM
  107. var period = hours >= 12 ? 'PM' : 'AM';
  108. // Adjust the hours to 12-hour format
  109. hours = hours % 12;
  110. hours = hours ? hours : 12; // Handle the case when hours is 0
  111. // Format the date and time string
  112. //var formattedDate = `${day}/${month}/${year}`;
  113. //var formattedTime = `${hours}:${minutes.toString().padStart(2, '0')} ${period}`;
  114. // Format the date and time strings
  115. var formattedDate = `${day.toString().padStart(2, '0')}-${month.toString().padStart(2, '0')}-${year}`;
  116. var formattedTime = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')} ${period}`;
  117. // Concatenate the formatted date and time
  118. var formattedDateTime = `${formattedDate} ${formattedTime}`;
  119. return formattedDateTime;
  120. }
  121. //Date format
  122. function convertdate_2(date_txt){
  123. var datetxt = date_txt;
  124. var date = new Date(datetxt);
  125. // Extract the date components
  126. var day = date.getDate();
  127. var month = date.getMonth() + 1; // Month starts from 0, so add 1
  128. var year = date.getFullYear();
  129. // Format the date and time strings
  130. var formattedDate = `${day.toString().padStart(2, '0')}-${month.toString().padStart(2, '0')}-${year}`;
  131. // Concatenate the formatted date and time
  132. var formattedDateTime = `${formattedDate}`;
  133. return formattedDateTime;
  134. }
  135. function date_difference(fromdate,todate,type='datetime'){
  136. // Parse the date strings into moment objects with the specified format
  137. var startDate = moment(fromdate, 'DD-MM-YYYY hh:mm A');
  138. var endDate = moment(todate, 'DD-MM-YYYY hh:mm A');
  139. // Calculate the difference in days
  140. var daysDifference = endDate.diff(startDate, 'days');
  141. // Calculate the remaining time components (hours, minutes)
  142. var duration = moment.duration(endDate - startDate);
  143. var hoursDifference = duration.hours();
  144. var minutesDifference = duration.minutes();
  145. var date_diff_txt ="";
  146. var day_txt = "day";
  147. var hour_txt = "hour";
  148. var days_txt ="";
  149. if(daysDifference>1){
  150. day_txt = "days";
  151. }
  152. if(hoursDifference>1){
  153. hour_txt = "hours";
  154. }
  155. // Display the result
  156. //1 day, 1 hour and 34 minutes.
  157. if(type=='days'){
  158. date_diff_txt = daysDifference + ' '+day_txt;
  159. }else if(type=='time'){
  160. date_diff_txt = hoursDifference + ' '+ hour_txt +' and ' + minutesDifference + ' minutes';
  161. }
  162. else{
  163. if(daysDifference>0){
  164. days_txt = daysDifference + ' '+day_txt+', ';
  165. }
  166. date_diff_txt = days_txt + hoursDifference + ' '+ hour_txt +' and ' + minutesDifference + ' minutes';
  167. }
  168. return date_diff_txt;
  169. }
  170. function nodata(message="Data are not availble at this moment please check later"){
  171. var nodata = `<center><img src="images/nodata_ani.gif" width="40%"><br><p class="text-warning">`+message+`</p></center>`;
  172. return nodata;
  173. }
  174. function searchinfo(message="Data are not availble at this moment please check later"){
  175. var nodata = `<center><img src="images/hi_robo.gif" width="20%"><br><p class="text-warning">`+message+`</p></center>`;
  176. return nodata;
  177. }
  178. //Function to display random messages while waiting
  179. function getLoadingMessage() {
  180. var messages = [
  181. "Please wait as we fetch the data. It will take less than 30 seconds.",
  182. "Loading data... This won't take long.",
  183. "Fetching information. Thank you for your patience.",
  184. "Just a moment while we gather the data.",
  185. "Loading... Sit tight!",
  186. "Hold on tight! We're almost there.",
  187. "Data is on its way. Thanks for waiting.",
  188. "Patience is a virtue! We're working on it.",
  189. "Just a few more seconds...",
  190. "Almost done! Thanks for your patience.",
  191. "We appreciate your patience. Data is coming shortly.",
  192. "Stay tuned! Data is loading."
  193. ];
  194. // Select a random message from the array
  195. var randomMessage = messages[Math.floor(Math.random() * messages.length)];
  196. // Display the random message
  197. return randomMessage;
  198. }
  199. //To convert the file size from bytes
  200. function formatFileSize(bytes) {
  201. if (bytes === 0) return '0 Bytes';
  202. const k = 1024;
  203. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  204. const i = Math.floor(Math.log(bytes) / Math.log(k));
  205. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  206. }
  207. /* Check file Exits */
  208. function checkFileExists(url) {
  209. return fetch(url)
  210. .then(response => {
  211. if (!response.ok) {
  212. throw new Error('File not found');
  213. }
  214. return true;
  215. })
  216. .catch(error => {
  217. console.error('Error checking file existence:', error);
  218. return false;
  219. });
  220. }
  221. /* File Doanload script
  222. * Send fileUrl - Full Path
  223. * var fileUrl = "/gcc/files/m_petition/m_action_file/filename.jpg";
  224. */
  225. function callDownload(fileUrl,fileName){
  226. checkFileExists(fileUrl).then(exists => {
  227. if (exists) {
  228. //download file - fileUrl
  229. // Create a temporary anchor element
  230. var link = document.createElement("a");
  231. link.href = fileUrl;
  232. link.download = fileName; // Set the download attribute to the file name
  233. link.click(); // Simulate a click on the anchor element to trigger the download
  234. } else {
  235. console.log('File does not exist');
  236. }
  237. });
  238. }
  239. /* encode a string to Base64 */
  240. function encodeBase64(value) {
  241. if (value && value.trim() !== '') {
  242. // Encode the string to Base64
  243. var encodedString = btoa(value);
  244. return encodedString;
  245. } else {
  246. return '';
  247. }
  248. }
  249. function passwordReset(){
  250. var loginid = /*[[${LoginUserId}]]*/'';
  251. if(loginid!="" && loginid>0){
  252. $("#passwordreset").modal({
  253. backdrop: 'static',
  254. keyboard: false
  255. }); // Show Modal Box
  256. $("#resetuserid").val(loginid);
  257. $("#oldpassword").val('');
  258. $("#password").val('');
  259. $("#newpassword").val('');
  260. }
  261. }
  262. function savePassword() {
  263. var userid = $("#resetuserid").val();
  264. var oldpassword = $("#oldpassword").val();
  265. var password = $("#password").val();
  266. var confirmpassword = $("#newpassword").val();
  267. // Required field validation
  268. if (!userid || !oldpassword || !password || !confirmpassword) {
  269. Swal.fire({
  270. icon: "warning",
  271. title: "Validation Error",
  272. text: "All fields are required.",
  273. });
  274. return;
  275. }
  276. // ✅ Password length validation (above 4 characters)
  277. if (password.length < 4 || confirmpassword.length < 4) {
  278. Swal.fire({
  279. icon: "warning",
  280. title: "Weak Password",
  281. text: "Please enter a password with more than 4 characters.",
  282. confirmButtonText: "OK"
  283. });
  284. return;
  285. }
  286. // Password match validation
  287. if (password !== confirmpassword) {
  288. Swal.fire({
  289. icon: "error",
  290. title: "Mismatch",
  291. text: "New password and confirmation password do not match.",
  292. });
  293. return;
  294. }
  295. var formData = new FormData();
  296. formData.append('userid', userid);
  297. formData.append('oldpassword', oldpassword);
  298. formData.append('newpassword', password);
  299. // AJAX call
  300. $.ajax({
  301. url: '/election/api/resetPassword',
  302. type: 'POST',
  303. data: formData,
  304. contentType: false,
  305. processData: false,
  306. success: function (response) {
  307. if (response === 'success') {
  308. Swal.fire({
  309. allowOutsideClick: false,
  310. allowEscapeKey: false,
  311. allowEnterKey: false,
  312. icon: "success",
  313. title: "Success",
  314. text: "Password reset successfully!",
  315. confirmButtonText: "OK"
  316. }).then(function () {
  317. document.getElementById('logout-form').submit();
  318. });
  319. } else {
  320. Swal.fire({
  321. icon: "error",
  322. title: "Failed",
  323. text: response.message || "Failed to reset password."
  324. });
  325. }
  326. },
  327. error: function (xhr) {
  328. Swal.fire({
  329. icon: "error",
  330. title: "Error",
  331. text: "An error occurred. Please try again later."
  332. });
  333. }
  334. });
  335. }
  336. /* function savePassword() {
  337. var userid = $("#resetuserid").val();
  338. var oldpassword = $("#oldpassword").val();
  339. var password = $("#password").val();
  340. var confirmpassword = $("#newpassword").val();
  341. // Input validation
  342. if (!userid || !oldpassword || !password || !confirmpassword) {
  343. alert("All fields are required.");
  344. return;
  345. }
  346. if (password !== confirmpassword) {
  347. alert("New password and confirmation password do not match.");
  348. return;
  349. }
  350. var formData = new FormData();
  351. formData.append('userid', userid);
  352. formData.append('oldpassword', oldpassword);
  353. formData.append('newpassword', password);
  354. // Send AJAX request to reset password
  355. $.ajax({
  356. url: '/election/api/resetPassword', // Update with the actual endpoint URL
  357. type: 'POST',
  358. data: formData,
  359. contentType: false, // Required for FormData
  360. processData: false, // Required for FormData
  361. success: function(response) {
  362. // Handle success response
  363. if (response === 'success') {
  364. //alert("Password reset successfully.");
  365. Swal.fire({
  366. allowOutsideClick: false,
  367. allowEscapeKey: false,
  368. allowEnterKey: false,
  369. title: "Success",
  370. text: "Password reset successfully!",
  371. icon: "success",
  372. confirmButtonText: "OK"
  373. }).then(function () {
  374. // Optionally, redirect the user or reset the form
  375. document.getElementById('logout-form').submit();
  376. });
  377. } else {
  378. alert(response.message || "Failed to reset password.");
  379. }
  380. },
  381. error: function(xhr, status, error) {
  382. // Handle error response
  383. var errorMessage = "An error occurred. Please try again later.";
  384. if (xhr.responseJSON && xhr.responseJSON.message) {
  385. errorMessage = xhr.responseJSON.message;
  386. }
  387. alert(errorMessage);
  388. }
  389. });
  390. } */
  391. </script>
  392. <!--
  393. <script th:inline="javascript">
  394. function logout() {
  395. fetch(/*[[ @{/logout} ]]*/"", { method: 'POST' })
  396. .then(() => window.location.href = /*[[ @{/login} ]]*/"")
  397. .catch(error => console.error('Error logging out:', error));
  398. }
  399. </script>
  400. -->