forked from dohinaf/basic-icecream-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.js
100 lines (84 loc) · 3.71 KB
/
profile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
document.addEventListener("DOMContentLoaded", function () {
// Handle profile picture change
const profileImage = document.getElementById("profile-image");
const uploadInput = document.getElementById("upload");
// Trigger file input when 'Change Picture' button is clicked
profileImage.addEventListener("click", function () {
uploadInput.click();
});
// Handle image file selection and preview
uploadInput.addEventListener("change", function () {
const file = uploadInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function (e) {
profileImage.src = e.target.result;
};
reader.readAsDataURL(file);
}
});
// Form Submission Handler (You can replace this with your server-side form handling)
const form = document.querySelector("form");
form.addEventListener("submit", function (e) {
e.preventDefault();
const formData = new FormData(form);
console.log("Form Submitted with Data:", Object.fromEntries(formData.entries()));
alert("Profile Saved!");
// Add AJAX call here to send data to the server if needed
});
// Cancel button: clear form fields and reset profile picture
const cancelButton = document.querySelector(".cancel-btn");
cancelButton.addEventListener("click", function () {
form.reset();
profileImage.src = "profilepic.png"; // Reset profile picture to default
});
// Logout button handler
const logoutButton = document.querySelector(".logout-btn");
logoutButton.addEventListener("click", function () {
alert("Logging out...");
window.location.href = "index.html"; // Redirect to logout page
});
// Delete Account button handler
const deleteButton = document.querySelector(".delete-btn");
deleteButton.addEventListener("click", function () {
const confirmDelete = confirm("Are you sure you want to delete your account?");
if (confirmDelete) {
alert("Account Deleted!");
// Add AJAX call here to handle account deletion if needed
window.location.href = "index.html"; // Redirect after deletion
}
});
// Social sign-in buttons (you can add additional functionality or API integration here)
document.querySelector(".google").addEventListener("click", function () {
window.open('https://accounts.google.com/signin');
});
document.querySelector(".facebook").addEventListener("click", function () {
window.open('https://www.facebook.com/');
});
document.querySelector(".instagram").addEventListener("click", function () {
window.open('https://www.instagram.com/accounts/login/');
});
const upcomingBookings = [
{ trip: 'Bus to Mumbai', date: '15th Oct 2024', departure: 'City Terminal', seat: 'A12' },
{ trip: 'Train to Delhi', date: '25th Oct 2024', departure: 'Central Station', seat: 'B34' }
];
const upcomingList = document.getElementById("upcoming-list");
// Populate Upcoming Bookings
upcomingBookings.forEach(booking => {
const li = document.createElement("li");
li.classList.add("booking-item");
li.innerHTML = `
<div>
<strong>${booking.trip}</strong>
<span>Date: ${booking.date}</span>
<span>Departure: ${booking.departure}</span>
<span>Seat: ${booking.seat}</span>
<button onclick="downloadTicket('${booking.trip}')">Download Ticket</button>
</div>
`;
upcomingList.appendChild(li);
});
});
function downloadTicket(trip) {
alert(`Downloading ticket for ${trip}`);
}