source: Scripts/Profile.js@ 75f74d9

main
Last change on this file since 75f74d9 was 75f74d9, checked in by Vlado 222039 <vlado.popovski@…>, 6 weeks ago

Initial commit: Adding Book Tracker code

  • Property mode set to 100644
File size: 3.2 KB
Line 
1// Add hover effect to table rows
2const tableRows = document.querySelectorAll('.loan-table tbody tr');
3tableRows.forEach(row => {
4 row.addEventListener('mouseover', () => {
5 row.style.backgroundColor = '#f9f9f9';
6 });
7 row.addEventListener('mouseout', () => {
8 row.style.backgroundColor = '';
9 });
10});
11
12function returnBook(loanId) {
13 if (confirm('Are you sure you want to return this book?')) {
14 // Send POST request to return.php
15 fetch('Return.php', {
16 method: 'POST',
17 headers: {
18 'Content-Type': 'application/x-www-form-urlencoded',
19 },
20 body: 'loanId=' + loanId
21 })
22 .then(response => response.json())
23 .then(data => {
24 if (data.success) {
25 // Reload the page to update the table
26 location.reload();
27 } else {
28 alert('Error returning book: ' + data.message);
29 }
30 })
31 .catch(error => {
32 console.error('Error:', error);
33 alert('An error occurred while returning the book');
34 });
35 }
36}
37
38function returnWithFine(loanId) {
39 if (confirm('This book is overdue. By returning it now, you acknowledge the fine that will be added to your account. Continue?')) {
40 fetch('ReturnWithFine.php', {
41 method: 'POST',
42 headers: {
43 'Content-Type': 'application/x-www-form-urlencoded',
44 },
45 body: 'loanId=' + loanId
46 })
47 .then(response => response.json())
48 .then(data => {
49 if (data.success) {
50 alert(`Book returned successfully. A fine has been added to your account.`);
51 location.reload();
52 } else {
53 alert('Error returning book: ' + data.message);
54 }
55 })
56 .catch(error => {
57 console.error('Error:', error);
58 alert('An error occurred while returning the book');
59 });
60 }
61}
62
63
64// Add fine payment functionality
65function payFines() {
66 const paymentLink = document.querySelector('.action-link-pay');
67 const totalAmount = paymentLink.getAttribute('data-total');
68
69 console.log('Total amount: ' + totalAmount);
70 console.log(paymentLink);
71
72 if (confirm(`Are you sure you want to pay all unpaid fines? Total amount: $${totalAmount}`)) {
73 fetch('PayFines.php', {
74 method: 'POST',
75 headers: {
76 'Content-Type': 'application/x-www-form-urlencoded',
77 }
78 })
79 .then(response => response.json())
80 .then(data => {
81 if (data.success) {
82 alert('All fines have been paid successfully!');
83 location.reload();
84 } else {
85 alert('Error processing payment: ' + data.message);
86 }
87 })
88 .catch(error => {
89 console.error('Error:', error);
90 alert('An error occurred while processing the payment');
91 });
92 }
93}
94
95/*
96// Add click event listener for the payment link
97document.addEventListener('DOMContentLoaded', function() {
98 const paymentLink = document.querySelector('.action-link-pay');
99 if (paymentLink) {
100 paymentLink.addEventListener('click', function(e) {
101 e.preventDefault();
102 payFines();
103 });
104 }
105});
106*/
107
108
109
Note: See TracBrowser for help on using the repository browser.