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.

1220 lines
50 KiB

1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <script>
  2. var mobileNumberForCancel = 0;
  3. var cancelBookingId = 0;
  4. var cancelBookingLogin = false;
  5. var isLogin = false;
  6. var disableBooking = false;
  7. var isvalidUser = false;
  8. var checkvalidation = true
  9. var username = [[${userName != null}]];
  10. if (username) {
  11. isLogin = true;
  12. document.getElementById("pds1").style.display = 'block';
  13. document.getElementById("pds").style.display = 'none';
  14. } else {
  15. document.getElementById("pds1").style.display = 'none';
  16. document.getElementById("pds").style.display = 'block';
  17. }
  18. function checkLoginedIn(url, hallId) { // Should print the actual hall ID value
  19. if (isLogin == false) {
  20. showloginpopup();
  21. } else {
  22. if (url == 'hallbookingform' || url == 'book') {
  23. CheckBookingLimitation(function (success) {
  24. if (success) {
  25. if (hallId != undefined && hallId != '' && hallId != 0) {
  26. // console.log('Navigating to hallbookingform with hallId:', hallId);
  27. window.location.href = '/communityhall/hallbookingform?hallId=' + hallId;
  28. } else {
  29. window.location.href = '/communityhall/user/' + url;
  30. }
  31. }
  32. });
  33. } else {
  34. if (url == 'viewhistory') {
  35. window.location.href = '/communityhall/user/' + url;
  36. }
  37. }
  38. }
  39. return false;
  40. }
  41. // Function to show login popup and reset mobile number field
  42. function showloginpopup() {
  43. $('#loginModal').modal('show'); // Show the login modal
  44. // Reset mobile number input field on login modal shown
  45. $('#loginModal').on('shown.bs.modal', function () {
  46. $('#mobileNumber').val(''); // Clear the mobile number input field
  47. });
  48. // Unbind the modal shown event after it has been triggered once
  49. $('#loginModal').one('hide.bs.modal', function () {
  50. $('#loginModal').off('shown.bs.modal'); // Unbind the shown.bs.modal event
  51. });
  52. }
  53. // Function to redirect to sign up tab and reset register form fields
  54. function redirectToSignUp() {
  55. // Activate the Register tab
  56. $('#loginTabs a[href="#register"]').tab('show');
  57. // Reset the register form fields
  58. $('#newform')[0].reset();
  59. // Unbind modal shown event to prevent unnecessary resets when switching tabs
  60. $('#loginModal').one('hide.bs.modal', function () {
  61. $('#newform')[0].reset(); // Reset again if modal is closed while on Register tab
  62. });
  63. }
  64. // Function to clear form fields if modal is closed without switching tabs
  65. $('#loginModal').on('hide.bs.modal', function () {
  66. $('#mobileNumber').val(''); // Clear mobile number input field
  67. $('#newform')[0].reset(); // Reset the form fields
  68. });
  69. // Add an event listener to handle login popup
  70. document.getElementById("loginpopup").addEventListener("click", function () {
  71. showloginpopup(); // Call the showLoginPopup() function when login popup icon is clicked
  72. });
  73. // Add event listeners to handle switching tabs and resetting forms accordingly
  74. $('#loginTabs a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  75. var targetTab = $(e.target).attr("href"); // Get the target tab href
  76. // Reset form fields based on the tab shown
  77. if (targetTab === "#login") {
  78. $('#mobileNumber').val(''); // Reset mobile number field for login tab
  79. } else if (targetTab === "#register") {
  80. $('#newform')[0].reset(); // Reset register form fields
  81. }
  82. });
  83. var verifyLogin = "";
  84. window.dataLayer = window.dataLayer || [];
  85. function gtag() {
  86. dataLayer.push(arguments);
  87. }
  88. gtag('js', new Date());
  89. gtag('config', 'UA-23581568-13');
  90. $(document).ready(function () {
  91. // Function to show/hide fields based on the selected User Type
  92. $("#userType").change(function () {
  93. var selectedUserType = $(this).val();
  94. document.getElementById('name').value = '';
  95. document.getElementById('name').readOnly = false;
  96. // Hide all fields initially
  97. $("#employeeFields, #pensionerFields, #counsellorFields , #govtmentfields").hide();
  98. if (selectedUserType === "GCC_EMPLOYEE") {
  99. $("#employeeFields").show();
  100. } else if (selectedUserType === "PENSIONER") {
  101. $("#pensionerFields").show();
  102. } else if (selectedUserType === "COUNCILLOR") {
  103. $("#counsellorFields").show();
  104. }
  105. });
  106. });
  107. $('.otp-input').on('keyup', function (e) {
  108. var $this = $(this);
  109. if ($this.val().length === 1) {
  110. $this.next('.otp-input').focus();
  111. }
  112. if ($this.val().length === 0) {
  113. $this.prev('.otp-input').focus();
  114. }
  115. });
  116. // Function to send OTP
  117. function sendOTP(mobileNum) {
  118. // Show a Swal loading dialog while processing the OTP
  119. Swal.fire({
  120. title: 'Processing OTP...',
  121. text: 'Please wait while we send the OTP.',
  122. allowOutsideClick: false,
  123. didOpen: () => {
  124. Swal.showLoading(); // Show the loading spinner
  125. }
  126. });
  127. // Set a minimum display time for the loading dialog (e.g., 5 seconds)
  128. let minDisplayTime = 5000; // 5 seconds
  129. let startTime = new Date().getTime(); // Track the time when the request started
  130. if (mobileNum != "" || mobileNum != undefined || mobileNum != null) {
  131. mobileNo = mobileNum;
  132. $("#mobilenotxt").html(mobileNo);
  133. $.ajax({
  134. type: "GET",
  135. url: '/communityhall/user/api/sendOTP',
  136. data: {'mobileNo': mobileNo, 'purpose': 'New User'},
  137. success: function (bodyMessage) {
  138. // Calculate the elapsed time since the request started
  139. let elapsedTime = new Date().getTime() - startTime;
  140. // Ensure the loading dialog stays on screen for at least the minimum display time
  141. let delay = Math.max(0, minDisplayTime - elapsedTime);
  142. setTimeout(function () {
  143. Swal.close(); // Close the Swal loading dialog
  144. if (bodyMessage != "Error") {
  145. // Show the OTP form if the OTP was sent successfully
  146. $('#otpForm').modal({
  147. backdrop: 'static',
  148. keyboard: false
  149. });
  150. $('#otpForm').modal('show');
  151. // Resend OTP Link function
  152. var resendTimeout;
  153. $("#resendlink").html('Please wait..<span id="countdown">60</span>s');
  154. var countdown = $("#countdown");
  155. function startCountdown() {
  156. var timeleft = 60;
  157. countdown.text(timeleft);
  158. resendTimeout = setInterval(function () {
  159. timeleft--;
  160. countdown.text(timeleft);
  161. if (timeleft <= 0) {
  162. clearInterval(resendTimeout);
  163. $("#resendlink").html('<a href="#" id="resend-link" class="text-info" onclick="return sendOTP(mobileNo);">Resend OTP</a>');
  164. }
  165. }, 1000);
  166. }
  167. startCountdown(); // Start Resend OTP count
  168. } else {
  169. // Show error message if OTP sending failed
  170. showErrorWithDelay('OTP Not Sent! No Internet Connection.');
  171. }
  172. }, delay); // Delay closing the loading dialog
  173. },
  174. error: function () {
  175. // Handle error case if the AJAX request fails
  176. let elapsedTime = new Date().getTime() - startTime;
  177. let delay = Math.max(0, minDisplayTime - elapsedTime);
  178. setTimeout(function () {
  179. Swal.close(); // Close the Swal loading dialog
  180. // Show network error Swal
  181. Swal.fire(
  182. 'Network Error!',
  183. 'Please try again later.',
  184. 'error'
  185. );
  186. }, delay); // Delay closing the loading dialog before showing the error
  187. }
  188. });
  189. } else {
  190. mobileNo = $("#mobileNumber").val();
  191. $("#mobile").val(mobileNo);
  192. $.ajax({
  193. type: "GET",
  194. url: '/communityhall/user/api/sendOTP',
  195. data: {'mobileNo': mobileNo, 'purpose': 'New User'},
  196. dataType: 'json',
  197. success: function (bodyMessage) {
  198. let elapsedTime = new Date().getTime() - startTime;
  199. let delay = Math.max(0, minDisplayTime - elapsedTime);
  200. setTimeout(function () {
  201. Swal.close(); // Close the Swal loading dialog
  202. if (bodyMessage != "Error") {
  203. // Show the OTP form if the OTP was sent successfully
  204. $('#otpForm').modal({
  205. backdrop: 'static',
  206. keyboard: false
  207. });
  208. $('#otpForm').modal('show');
  209. } else {
  210. // Show error message if OTP sending failed
  211. showErrorWithDelay('OTP Not Sent! No Internet Connection.');
  212. }
  213. }, delay); // Delay closing the loading dialog
  214. },
  215. error: function () {
  216. let elapsedTime = new Date().getTime() - startTime;
  217. let delay = Math.max(0, minDisplayTime - elapsedTime);
  218. setTimeout(function () {
  219. Swal.close(); // Close the Swal loading dialog
  220. // Show network error Swal
  221. Swal.fire(
  222. 'Network Error!',
  223. 'Please try again later.',
  224. 'error'
  225. );
  226. }, delay); // Delay closing the loading dialog before showing the error
  227. }
  228. });
  229. }
  230. return false;
  231. }
  232. // Function to show error with a delay
  233. function showErrorWithDelay(errorMessage) {
  234. Swal.fire(
  235. 'Error!',
  236. errorMessage,
  237. 'error'
  238. );
  239. }
  240. function verifyOtp() {
  241. // Show Swal loading dialog while processing OTP
  242. Swal.fire({
  243. title: 'Verifying OTP...',
  244. text: 'Please wait while we verify the OTP.',
  245. allowOutsideClick: false,
  246. didOpen: () => {
  247. Swal.showLoading(); // Show the loading spinner
  248. }
  249. });
  250. // Set a minimum display time for the loading dialog (e.g., 2 seconds)
  251. const minDisplayTime = 2000; // 2 seconds
  252. const startTime = new Date().getTime(); // Track the time when the request started
  253. var otpInputs = $('.otp-input');
  254. var otpValue = '';
  255. otpInputs.each(function () {
  256. otpValue += $(this).val();
  257. });
  258. var mobileNoValue = 0;
  259. if (verifyLogin === "new") {
  260. mobileNoValue = $("#mobileno").val();
  261. } else if (cancelBookingLogin) {
  262. mobileNoValue = mobileNumberForCancel;
  263. bookingId = cancelBookingId;
  264. } else {
  265. mobileNoValue = $("#mobileNumber").val(); // Add your logic to get the mobile number value here
  266. }
  267. $.ajax({
  268. type: "GET",
  269. url: '/communityhall/user/api/verifyOTP',
  270. data: {
  271. 'otp': otpValue,
  272. 'mobileNo': mobileNoValue
  273. },
  274. dataType: 'text',
  275. success: function (bodyMessage) {
  276. // Calculate the elapsed time since the request started
  277. const elapsedTime = new Date().getTime() - startTime;
  278. // Ensure the loading dialog stays on screen for at least the minimum display time
  279. const delay = Math.max(0, minDisplayTime - elapsedTime);
  280. setTimeout(function () {
  281. Swal.close(); // Close the Swal loading dialog
  282. if (bodyMessage.trim() === "Success") {
  283. $('#otpForm').modal('hide'); // Hide OTP form modal
  284. if (verifyLogin === "new") {
  285. document.getElementById("newform").submit();
  286. } else if (cancelBookingLogin) {
  287. $.ajax({
  288. type: "GET", // Changed to POST method to match Spring endpoint
  289. url: '/communityhall/user/api/cancelBookingbyId', // Corrected endpoint URL
  290. data: {
  291. bookingId: bookingId,
  292. status: 'CANCELED',
  293. comments: 'user cancelled'
  294. },
  295. success: function (response) {
  296. if (response) {
  297. Swal.fire(
  298. 'Cancelled!',
  299. 'Your booking has been cancelled.',
  300. 'success'
  301. ).then(() => {
  302. location.reload(); // Reload the page after the alert is closed
  303. });
  304. } else {
  305. Swal.fire(
  306. 'Error!',
  307. 'Failed to cancel the booking. Please contact Admin.',
  308. 'error'
  309. );
  310. }
  311. },
  312. error: function (xhr, status, error) {
  313. Swal.fire(
  314. 'Error!',
  315. 'Failed to cancel the booking. Please contact Admin.',
  316. 'error'
  317. );
  318. console.error(xhr.responseText);
  319. }
  320. });
  321. } else {
  322. if (isLogin === false) {
  323. $.ajax({
  324. type: "GET",
  325. url: '/communityhall/user/api/getUsername',
  326. success: function (response) {
  327. // alert("user type: "+response.userType);
  328. document.getElementById("pds").style.display = "none";
  329. $("#userNameLogin").html(response.displayName);
  330. document.getElementById("pds1").style.display = 'block';
  331. document.getElementById("pds").style.display = 'none';
  332. $('#loginModal').modal('hide');
  333. console.log("user type: "+response.userType);
  334. isLogin = true;
  335. },
  336. error: function (errortxt) {
  337. console.error(errortxt);
  338. }
  339. });
  340. } else {
  341. window.location.reload();
  342. }
  343. }
  344. // Enable the "Select Hall" button upon successful OTP verification
  345. $('#selectHallButton').prop('disabled', false); // Change to false to enable
  346. } else {
  347. $("#otperror").html("OTP is Incorrect!!!");
  348. Swal.fire(
  349. 'Error!',
  350. 'OTP is Incorrect!',
  351. 'error'
  352. );
  353. }
  354. }, delay); // Delay closing the loading dialog
  355. },
  356. error: function (xhr, status, error) {
  357. // Calculate the elapsed time since the request started
  358. const elapsedTime = new Date().getTime() - startTime;
  359. // Ensure the loading dialog stays on screen for at least the minimum display time
  360. const delay = Math.max(0, minDisplayTime - elapsedTime);
  361. setTimeout(function () {
  362. Swal.close(); // Close the Swal loading dialog
  363. Swal.fire({
  364. title: 'No Internet Connection',
  365. text: 'Please check your internet connection and try again.',
  366. icon: 'error',
  367. confirmButtonText: 'OK',
  368. allowOutsideClick: false
  369. }).then((result) => {
  370. if (result.isConfirmed) {
  371. // Reload the page when the user acknowledges the error
  372. location.reload();
  373. }
  374. });
  375. }, delay); // Delay closing the loading dialog before showing the error
  376. }
  377. });
  378. return false;
  379. }
  380. // Verify OTP when the OTP form is submitted
  381. /* $('#otpForm').submit(function (event) {
  382. event.preventDefault();
  383. verifyOtp();
  384. });*/
  385. function newPinCall() {
  386. $('#otpForm').modal({
  387. backdrop: 'static',
  388. keyboard: false
  389. });
  390. $('#otpForm').modal('hide');
  391. return false;
  392. }
  393. $('#otpForm').on('shown.bs.modal', function () {
  394. $('.otp-input').val('');
  395. $('#otperror').text('');
  396. // $('#mobilenotxt').text('');
  397. });
  398. function resetOtpForm() {
  399. $('#otpForm').find('.otp-input').val('');
  400. $('#otperror').text('');
  401. //$('#mobilenotxt').text('');
  402. }
  403. $("#sendOTPButton").click(function (event) {
  404. event.preventDefault();
  405. checkMobileNo(); // Call the checkMobileNo() function first
  406. });
  407. function validateUserType() {
  408. var usertype = $("#userType").val();
  409. if (usertype == "PUBLIC") {
  410. validateNumber();
  411. return false;
  412. }
  413. if (usertype === "GCC_EMPLOYEE") {
  414. var employeeId = $("#employeeId").val();
  415. if (!employeeId) {
  416. Swal.fire(
  417. 'Error!',
  418. 'Employee ID is required.',
  419. 'error'
  420. );
  421. return false;
  422. }
  423. $.ajax({
  424. type: "GET",
  425. url: '/communityhall/user/api/checkEmployee', // Ensure this URL matches your Spring controller's endpoint
  426. data: {id: employeeId},
  427. success: function (response) {
  428. if (response.isRegistered) {
  429. Swal.fire(
  430. 'Already Registered!',
  431. 'The Employee ID ' + employeeId + ' is already registered.',
  432. 'warning'
  433. );
  434. } else {
  435. $.ajax({
  436. type: "GET",
  437. url: '/communityhall/user/api/gccemployee',
  438. data: {id: employeeId},
  439. success: function (response) {
  440. if (!response.EmployeeDetailsResult || response.EmployeeDetailsResult.length === 0) {
  441. Swal.fire({
  442. title: "Oops",
  443. html: "The Employee ID " + employeeId + " was not found!",
  444. icon: "info",
  445. showCancelButton: false,
  446. confirmButtonText: "Ok"
  447. });
  448. return false;
  449. } else {
  450. var employeeDetails = response.EmployeeDetailsResult[0];
  451. if (employeeDetails) {
  452. $("#employeename").val(employeeDetails.name);
  453. validateNumber();
  454. }
  455. }
  456. },
  457. error: function () {
  458. Swal.fire(
  459. 'Error!',
  460. 'An error occurred while fetching employee details.',
  461. 'error'
  462. );
  463. }
  464. });
  465. }
  466. },
  467. error: function () {
  468. Swal.fire(
  469. 'Error!',
  470. 'An error occurred while checking employee registration.',
  471. 'error'
  472. );
  473. }
  474. });
  475. return false;
  476. } else if (usertype == "PENSIONER") {
  477. var pensionerId = $("#pensionerId").val();
  478. if (!pensionerId) {
  479. Swal.fire(
  480. 'Error!',
  481. 'Pensioner ID is required.',
  482. 'error'
  483. );
  484. return false;
  485. }
  486. $.ajax({
  487. type: "GET",
  488. url: '/communityhall/user/api/checkEmployee', // Ensure this URL matches your Spring controller's endpoint
  489. data: {id: pensionerId},
  490. success: function (response) {
  491. if (response.isRegistered) {
  492. Swal.fire(
  493. 'Already Registered!',
  494. 'The Pensioner ID ' + pensionerId + ' is already registered.',
  495. 'warning'
  496. );
  497. } else {
  498. $.ajax({
  499. type: "GET",
  500. url: '/communityhall/user/api/PensionerDetails',
  501. data: {'id': pensionerId},
  502. success: function (response) {
  503. if (response.mobileNo) {
  504. $("#mobileno").val(response.mobileNo);
  505. validateNumber(); // Call validateNumber() when mobile number is available
  506. } else {
  507. var alertMessage = "The Pensioner Id Not Found!";
  508. const swalInstance = Swal.fire({
  509. title: "Oops",
  510. html: alertMessage,
  511. icon: "info",
  512. showCancelButton: false,
  513. confirmButtonText: "Ok"
  514. });
  515. }
  516. },
  517. error: function (xhr, status, error) {
  518. console.error(xhr.responseText);
  519. // Handle error here
  520. }
  521. });
  522. }
  523. },
  524. error: function () {
  525. Swal.fire(
  526. 'Error!',
  527. 'An error occurred while checking employee registration.',
  528. 'error'
  529. );
  530. }
  531. });
  532. return false;
  533. } else if (usertype === "COUNCILLOR") {
  534. var mobileno = $("#mobileno").val();
  535. $.ajax({
  536. type: "GET",
  537. url: '/communityhall/user/api/checkCounsellorMobileExits',
  538. data: {'mobileno': mobileno},
  539. success: function (response) {
  540. // On success, populate the counselor's name
  541. document.getElementById('name').value = response;
  542. validateNumber();
  543. },
  544. error: function (xhr, status, error) {
  545. if (xhr.status === 404) {
  546. Swal.fire({
  547. title: "COUNCILLOR Mobile Number Not Found",
  548. html: "The entered mobile number does not exist!",
  549. icon: "warning",
  550. showCancelButton: false,
  551. confirmButtonText: "Ok"
  552. });
  553. } else if (xhr.status === 409) {
  554. Swal.fire({
  555. title: "Mobile Number Existed",
  556. html: "Your account is already linked to another mobile number. Multiple registrations are not allowed for one councillor.",
  557. icon: "error",
  558. showCancelButton: false,
  559. confirmButtonText: "Ok"
  560. });
  561. } else {
  562. console.error(xhr.responseText);
  563. }
  564. }
  565. });
  566. return false;
  567. }
  568. }
  569. function validateNumber() {
  570. var mobileNo = $("#mobileno").val();
  571. //alert("validate number.."+mobileNo);
  572. $.ajax({
  573. type: "GET",
  574. url: '/communityhall/user/api/checkMobileExits',
  575. data: {'mobileno': mobileNo},
  576. success: function (bodyMessage) {
  577. if (bodyMessage == "success") {
  578. var alertMessage = "This Mobile Number Is Already Registered!</a>";
  579. $('#otpForm').modal('hide'); // Hide OTP form modal
  580. //$('#loginModal').modal('hide');
  581. // Initialize SweetAlert instance with options
  582. const swalInstance = Swal.fire({
  583. title: "Mobile Number exist",
  584. html: alertMessage,
  585. icon: "info",
  586. showCancelButton: false,
  587. confirmButtonText: "Ok"
  588. });
  589. return false;
  590. } else {
  591. verifyLogin = "new";
  592. ;
  593. sendOTP(mobileNo);
  594. return false;
  595. }
  596. },
  597. error: function (errortxt) {
  598. console.error(errortxt);
  599. }
  600. });
  601. return false;
  602. }
  603. function checkMobileNo() {
  604. var mobileNo = $("#mobileNumber");
  605. // Check if the mobile number is provided
  606. if (mobileNo.val().length !== 10) {
  607. // Set custom validity message for incorrect mobile number length
  608. mobileNo[0].setCustomValidity("Please enter a 10-digit mobile number.");
  609. // Report validity to trigger the validation UI
  610. mobileNo[0].reportValidity();
  611. return; // Exit the function to prevent the AJAX call
  612. } else {
  613. // Clear the custom validity message
  614. mobileNo[0].setCustomValidity("");
  615. }
  616. $.ajax({
  617. type: "GET",
  618. url: '/communityhall/user/api/checkuserstatus',
  619. data: {mobileNo: mobileNo.val()},
  620. success: function (statusResponse) {
  621. if (statusResponse === "pending") {
  622. // User status is pending, show SweetAlert
  623. const swalInstance = Swal.fire({
  624. title: "Account Approval Required",
  625. text: "Please wait for the officer to approve your account.",
  626. icon: "info",
  627. showCancelButton: false,
  628. confirmButtonText: "OK",
  629. });
  630. } else if (statusResponse === "deactive") {
  631. // User status is pending, show SweetAlert
  632. const swalInstance = Swal.fire({
  633. title: "Account Deactivated",
  634. text: "Please contact Admin to active.",
  635. icon: "info",
  636. showCancelButton: false,
  637. confirmButtonText: "OK",
  638. });
  639. } else if (statusResponse === "checkmobileexist") {
  640. // User status is not pending, proceed to check mobile number existence
  641. $.ajax({
  642. type: "GET",
  643. url: '/communityhall/user/api/checkMobileExits',
  644. data: {'mobileno': mobileNo.val()},
  645. success: function (mobileResponse) {
  646. if (mobileResponse === "success") {
  647. sendOTP(mobileNo.val());
  648. } else {
  649. var alertMessage = "This Mobile Number Is Not Registered! Please register.";
  650. $('#otpForm').modal('hide'); // Hide OTP form modal
  651. //$('#loginModal').modal('hide');
  652. const swalInstance = Swal.fire({
  653. title: "Registration Required",
  654. html: alertMessage,
  655. icon: "info",
  656. confirmButtonText: "Register",
  657. showCancelButton: true,
  658. customClass: {
  659. container: 'custom-swal-container', // Add a custom class to the container
  660. },
  661. backdrop: true, // Enable backdrop to prevent clicks on the main popup
  662. onOpen: function () {
  663. // Append the SweetAlert container to the document body
  664. $('.swal2-container').appendTo($('body'));
  665. }
  666. }).then((result) => {
  667. if (result.isConfirmed) {
  668. $('#loginTabs a[href="#register"]').tab('show');
  669. }
  670. });
  671. }
  672. },
  673. error: function (errortxt) {
  674. console.error(errortxt);
  675. }
  676. });
  677. }
  678. },
  679. error: function (errortxt) {
  680. console.error(errortxt);
  681. }
  682. });
  683. }
  684. // Ensure the function is called on a specific event
  685. document.getElementById("mobileNumber").addEventListener('input', function () {
  686. this.setCustomValidity(""); // Clear custom validity on input
  687. });
  688. function CheckBookingLimitation(callback) {
  689. $.ajax({
  690. type: "GET",
  691. url: '/communityhall/user/api/bookingLimit',
  692. success: function (response) {
  693. if (response === "success") {
  694. callback(true);
  695. } else if (response === "pending") {
  696. Swal.fire({
  697. icon: 'error',
  698. title: 'USER STATUS PENDING',
  699. text: 'Waiting for Approval',
  700. }).then((result) => {
  701. if (result.isConfirmed) {
  702. window.location.href = "/communityhall/user/logout";
  703. }
  704. });
  705. callback(false);
  706. } else if (response === "rejected") {
  707. Swal.fire({
  708. icon: 'error',
  709. title: 'USER STATUS REJECTED',
  710. text: 'Please change your user type to public in order to book, or contact the administrator for assistance.',
  711. }).then((result) => {
  712. if (result.isConfirmed) {
  713. showProfileDetails();
  714. }
  715. });
  716. callback(false);
  717. } else {
  718. Swal.fire({
  719. icon: 'error',
  720. title: 'Booking Limit Reached',
  721. text: 'You have reached your booking limit.',
  722. }).then((result) => {
  723. if (result.isConfirmed) {
  724. window.location.href = "/communityhall/user/viewhistory";
  725. }
  726. });
  727. callback(false);
  728. }
  729. },
  730. error: function (errortxt) {
  731. console.error(errortxt);
  732. callback(false);
  733. }
  734. });
  735. }
  736. function showprofilepopup() {
  737. showProfileDetails();
  738. }
  739. function showProfileDetails() {
  740. $.ajax({
  741. url: '/communityhall/user/api/getUser',
  742. type: 'GET',
  743. data: {
  744. 'userId': 0
  745. },
  746. success: function (response) {
  747. $("#profileModal").hide();
  748. $('#p_userId').val(response.userId);
  749. $('#p_name').val(response.name);
  750. $('#p_email').val(response.email);
  751. $('#p_mobnum').val(response.mobileNo);
  752. $('#p_doornum').val(response.doorNo);
  753. $('#p_area').val(response.area);
  754. $('#p_location').val(response.location);
  755. $('#p_pincode').val(response.pinCode);
  756. $('#p_userstatus').val(response.userstatus);
  757. $('#p_image').attr('src', response.profilephoto);
  758. $('#p_usertype').val(response.usertype).prop('disabled', true); // Set usertype
  759. if (response.userstatus.toLowerCase() === 'rejected') {
  760. $('#rejectionReasonContainer').show();
  761. $('#p_rejectionreason').val(response.rejectionReason);
  762. // Make fields editable
  763. $('#p_name').prop('readonly', false);
  764. $('#p_doornum').prop('readonly', false);
  765. $('#p_area').prop('readonly', false);
  766. $('#p_location').prop('readonly', false);
  767. $('#p_usertype').prop('disabled', false);
  768. $('#p_usertype option[value="PENSIONER"]').prop('disabled', true);
  769. $('#p_usertype option[value="COUNCILLOR"]').prop('disabled', true);
  770. $('#p_usertype option[value="GCC_EMPLOYEE"]').prop('disabled', true);
  771. $('#updateButton').show();
  772. } else {
  773. $('#rejectionReasonContainer').hide();
  774. $('#usertypeContainer').hide();
  775. $('#p_email').prop('readonly', false);
  776. $('#p_doornum').prop('readonly', false);
  777. $('#p_area').prop('readonly', false);
  778. $('#p_location').prop('readonly', false);
  779. $('#p_pincode').prop('readonly', false);
  780. $('#updateButton').show();
  781. }
  782. $('#profileModal').modal('show');
  783. },
  784. error: function (xhr, status, error) {
  785. console.error(xhr.responseText);
  786. }
  787. });
  788. }
  789. function updateUserDetails() {
  790. var userId = $('#p_userId').val();
  791. var name = $('#p_name').val();
  792. var doorNo = $('#p_doornum').val();
  793. var area = $('#p_area').val();
  794. var location = $('#p_location').val();
  795. var userType = $('#p_usertype').val();
  796. var pinCode = $('#p_pincode').val();
  797. var email = $('#p_email').val();
  798. var profilephoto = $('#fileInput')[0].files[0]; // Get the selected file
  799. var formData = new FormData();
  800. formData.append("userId", userId);
  801. formData.append("name", name);
  802. formData.append("doorNo", doorNo);
  803. formData.append("area", area);
  804. formData.append("location", location);
  805. formData.append("usertype", userType);
  806. formData.append("email", email);
  807. formData.append("pinCode", pinCode);
  808. if (profilephoto) {
  809. formData.append("profilephoto", profilephoto);
  810. }
  811. Swal.fire({
  812. title: 'Do you want to update this User Profile?',
  813. showDenyButton: true,
  814. showCancelButton: true,
  815. confirmButtonText: 'YES',
  816. denyButtonText: 'NO',
  817. }).then((result) => {
  818. if (result.isConfirmed) {
  819. $.ajax({
  820. url: '/communityhall/user/api/updateUserDetails',
  821. type: 'POST',
  822. data: formData,
  823. processData: false,
  824. contentType: false,
  825. success: function (response) {
  826. if (response === 'success') {
  827. Swal.fire(
  828. 'Done',
  829. 'Successfully updated user details',
  830. 'success'
  831. ).then(() => {
  832. window.location.reload(); // Reload the page after successful update
  833. });
  834. } else {
  835. Swal.fire(
  836. 'Error',
  837. 'Failed to update user details',
  838. 'error'
  839. );
  840. }
  841. },
  842. error: function (xhr, textStatus, errorThrown) {
  843. Swal.fire(
  844. 'Error',
  845. 'Failed to update user details',
  846. 'error'
  847. );
  848. }
  849. });
  850. } else if (result.isDenied) {
  851. Swal.fire('Changes are not saved', '', 'info');
  852. }
  853. });
  854. }
  855. document.getElementById('p_image').addEventListener('click', function () {
  856. // Trigger the file input click event
  857. document.getElementById('fileInput').click();
  858. });
  859. // Listen for changes in the file input
  860. document.getElementById('fileInput').addEventListener('change', function (event) {
  861. const file = event.target.files[0];
  862. if (file) {
  863. const reader = new FileReader();
  864. reader.onload = function (e) {
  865. document.getElementById('p_image').src = e.target.result;
  866. };
  867. reader.readAsDataURL(file);
  868. }
  869. });
  870. // Attach CSS styles for error messages dynamically
  871. $('head').append('<style>.error-message { color: red; font-size: 12px; margin-top: 5px; }</style>');
  872. //script for pensioner
  873. document.getElementById('pensionerId').addEventListener('blur', function () {
  874. var pensionerId = this.value;
  875. if (pensionerId) {
  876. fetchPensionerDetails(pensionerId);
  877. }
  878. });
  879. function fetchPensionerDetails(pensionerId) {
  880. fetch('/communityhall/user/api/PensionerDetail?pensionerId=' + pensionerId)
  881. .then(response => response.json())
  882. .then(data => {
  883. if (data && data.PensionerDetailsResult && data.PensionerDetailsResult.length > 0) {
  884. var pensionerDetails = data.PensionerDetailsResult[0];
  885. document.getElementById('pendionerdepartment').value = pensionerDetails.Department;
  886. document.getElementById('name').value = pensionerDetails.Name;
  887. document.getElementById('governmentId').value = pensionerId;
  888. document.getElementById('department').value = pensionerDetails.Department;
  889. } else {
  890. document.getElementById('validationResult').innerText = "No pensioner found with this ID";
  891. }
  892. })
  893. .catch(error => console.error('Error fetching pensioner details:', error));
  894. }
  895. document.getElementById('employeeId').addEventListener('blur', function () {
  896. var employeeId = this.value;
  897. if (employeeId) {
  898. fetchEmployeeDetails(employeeId);
  899. }
  900. });
  901. function fetchEmployeeDetails(employeeId) {
  902. fetch('/communityhall/user/api/EmployeeDetails?employeeId=' + employeeId)
  903. .then(response => response.json())
  904. .then(data => {
  905. if (data && data.EmployeeDetailsResult && data.EmployeeDetailsResult.length > 0) {
  906. var employeeDetails = data.EmployeeDetailsResult[0];
  907. document.getElementById('name').value = employeeDetails.name;
  908. document.getElementById('name').readOnly = true;
  909. document.getElementById('employeedepartment').value = employeeDetails.department;
  910. document.getElementById('governmentId').value = employeeId;
  911. document.getElementById('department').value = employeeDetails.department;
  912. } else {
  913. document.getElementById('validationResult').innerText = "No Employee found with this ID";
  914. }
  915. })
  916. .catch(error => console.error('Error fetching Employee details:', error));
  917. }
  918. //Script for triggering send otp button while pressing enter key from system
  919. document.addEventListener('keydown', function (event) {
  920. if (event.key === 'Enter') {
  921. // Prevent default form submission action
  922. event.preventDefault();
  923. }
  924. });
  925. let isCompressing = false;
  926. // Attach the validation function to file input change event
  927. $(document).on('change', '.profile-file-upload', function () {
  928. validateFile(this);
  929. });
  930. function validateFile(fileInput) {
  931. const allowedExtensions = /(\.jpg|\.jpeg|\.pdf)$/i;
  932. const file = fileInput.files[0];
  933. const filePath = fileInput.value;
  934. let errorMessage = '';
  935. // Clear any previous error message
  936. clearError(fileInput);
  937. if (!allowedExtensions.exec(filePath)) {
  938. errorMessage = 'Only JPG, JPEG, and PDF files are allowed.';
  939. fileInput.value = ''; // Clear the file input
  940. displayError(fileInput, errorMessage);
  941. } else if (file && file.size > 2097152) { // Check if file size exceeds 2 MB
  942. //console.log('Starting image compression...');
  943. isCompressing = true;
  944. errorMessage = '';
  945. compressImage(file).then(compressedFile => {
  946. isCompressing = false;
  947. //console.log('Image compression completed successfully.');
  948. //console.log('Original file size:', file.size, 'bytes');
  949. //console.log('Compressed file size:', compressedFile.size, 'bytes');
  950. // Replace original file with compressed file
  951. const dataTransfer = new DataTransfer();
  952. dataTransfer.items.add(compressedFile);
  953. fileInput.files = dataTransfer.files;
  954. // Validate file size after compression if needed
  955. validateFileSize(fileInput);
  956. }).catch(error => {
  957. console.error('Image compression error:', error);
  958. isCompressing = false;
  959. errorMessage = 'Error compressing image.';
  960. displayError(fileInput, errorMessage);
  961. });
  962. return;
  963. } else {
  964. // File size is within limit, proceed with validation or other actions
  965. //console.log('File size is within limit:', file.size, 'bytes');
  966. // Clear any previous error message since the file is valid
  967. clearError(fileInput);
  968. }
  969. }
  970. function clearError(fileInput) {
  971. const errorElements = fileInput.parentNode.getElementsByClassName('error-message');
  972. while (errorElements.length > 0) {
  973. errorElements[0].remove();
  974. }
  975. }
  976. // Function to compress image using canvas
  977. function compressImage(file) {
  978. return new Promise((resolve, reject) => {
  979. const reader = new FileReader();
  980. reader.onload = function (event) {
  981. const img = new Image();
  982. img.onload = function () {
  983. const canvas = document.createElement('canvas');
  984. const ctx = canvas.getContext('2d');
  985. const maxSize = 2097152; // 2MB in bytes
  986. let scale = 1;
  987. if (file.size > maxSize) {
  988. scale = Math.sqrt(maxSize / file.size);
  989. }
  990. canvas.width = img.width * scale;
  991. canvas.height = img.height * scale;
  992. ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
  993. // Convert canvas content to blob
  994. canvas.toBlob(blob => {
  995. // Resolve with a new File object from the blob
  996. resolve(new File([blob], file.name, {type: 'image/jpeg', lastModified: Date.now()}));
  997. }, 'image/jpeg', 0.7); // Adjust JPEG quality as needed (0.7 is 70% quality)
  998. };
  999. img.src = event.target.result;
  1000. };
  1001. reader.readAsDataURL(file);
  1002. });
  1003. }
  1004. // Function to validate file size after compression
  1005. function validateFileSize(fileInput) {
  1006. const file = fileInput.files[0];
  1007. if (file && file.size > 2097152) {
  1008. //console.log('File size is still greater than 2MB after compression.');
  1009. // Handle the situation where the file size is still greater than 2MB
  1010. displayError(fileInput, 'File size is still greater than 2MB after compression.');
  1011. fileInput.value = ''; // Clear the file input
  1012. } else {
  1013. //console.log('File size is within limit after compression.');
  1014. // Handle the situation where the file size is within the limit
  1015. }
  1016. }
  1017. // Function to display error messages
  1018. function displayError(fileInput, errorMessage) {
  1019. // Example implementation: show error message near the file input
  1020. let errorContainer = fileInput.nextElementSibling;
  1021. if (!errorContainer || !errorContainer.classList.contains('error-message')) {
  1022. errorContainer = document.createElement('div');
  1023. errorContainer.classList.add('error-message');
  1024. fileInput.parentNode.insertBefore(errorContainer, fileInput.nextSibling);
  1025. }
  1026. errorContainer.textContent = errorMessage;
  1027. }
  1028. /*Newly added for counter login*/
  1029. // Add an event listener to handle login popup
  1030. document.getElementById("counterloginpopup").addEventListener("click", function () {
  1031. showcounterloginpopup(); // Call the showLoginPopup() function when login popup icon is clicked
  1032. });
  1033. // Function to show counter login popup
  1034. function showcounterloginpopup() {
  1035. $('#cloginModal').modal('show');
  1036. // Reset input field on login modal shown
  1037. $('#cloginModal').on('shown.bs.modal', function () {
  1038. $('#cusername').val('');
  1039. $('#cpassword').val('');
  1040. // $("#error").text("").removeClass("text-danger");
  1041. });
  1042. // Unbind the modal shown event after it has been triggered once
  1043. $('#cloginModal').one('hide.bs.modal', function () {
  1044. $('#cloginModal').off('shown.bs.modal'); // Unbind the shown.bs.modal event
  1045. $("#error").text("");
  1046. $('#cusername').val('');
  1047. $('#cpassword').val('');
  1048. });
  1049. }
  1050. function verifyCounterLogin() {
  1051. var username = $("#cusername");
  1052. var password = $("#cpassword");
  1053. console.log("username: ", username[0], "\npassword:", password[0]);
  1054. // Validate Username
  1055. if ($.trim(username.val()) === "") {
  1056. username[0].setCustomValidity("Please Enter user name.");
  1057. username[0].reportValidity();
  1058. return false;
  1059. } else {
  1060. username[0].setCustomValidity("");
  1061. }
  1062. // Validate Password
  1063. if ($.trim(password.val()) === "") {
  1064. password[0].setCustomValidity("Please enter password");
  1065. password[0].reportValidity();
  1066. return false;
  1067. } else {
  1068. password[0].setCustomValidity("");
  1069. }
  1070. // Send AJAX Request
  1071. $.ajax({
  1072. type: "GET",
  1073. url: "/communityhall/counter/verifyLogin",
  1074. data: {
  1075. username: username.val(), // Send actual values
  1076. password: password.val()
  1077. },
  1078. success: function (response) {
  1079. console.log("Response: ", response);
  1080. if (!response || response.userType.toLowerCase() === "error") {
  1081. $("#error").html("<p class='text-danger'>Invalid Username or Password!</p>");
  1082. username.val(""); // Clear input
  1083. password.val("");
  1084. return;
  1085. } else {
  1086. sessionStorage.setItem("jwtToken", response.token);
  1087. sessionStorage.setItem("userName", response.counterName);
  1088. $("#error").text("").removeClass("text-danger");
  1089. $('#cloginModal').modal('hide');
  1090. console.log("Successfully logged in as counter!!!"+ response.counterName);
  1091. // redirectToDashboard(response);
  1092. window.location.href = "/communityhall/user/dashboard";
  1093. }
  1094. },
  1095. error: function (jqXHR) {
  1096. if (jqXHR.status === 400 || jqXHR.status === 417) {
  1097. $("#error").html("<p class='text-danger'>" + jqXHR.responseText + "</p>");
  1098. } else {
  1099. console.error("AJAX Error: ", jqXHR);
  1100. }
  1101. }
  1102. });
  1103. return false;
  1104. }
  1105. </script>