-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
171 lines (171 loc) · 8.72 KB
/
index.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"use strict";
// Wait for the DOM content to be fully loaded
document.addEventListener("DOMContentLoaded", () => {
// Safely get elements from the DOM
const resumeBox = document.getElementById("resume-box");
const hiddenButtons = document.getElementById("buttons");
const resumeContainer = document.getElementById("resume");
const editButton = document.getElementById("edit-resume-button");
// Initial setup: hide the resume box and hidden buttons
if (resumeBox)
resumeBox.style.display = "none";
if (hiddenButtons)
hiddenButtons.style.display = "none";
const form = document.getElementById("resume-form");
if (form) {
form.addEventListener("submit", (event) => {
event.preventDefault();
// Safely get form inputs
const nameInput = document.getElementById("name");
const fileInput = document.getElementById("file");
const emailInput = document.getElementById("email");
const phoneInput = document.getElementById("phone-number");
const locationInput = document.getElementById("location");
const jobTypeInput = document.getElementById("job-type");
const companyInput = document.getElementById("comapny");
const jobDateInput = document.getElementById("job-date");
const degreeInput = document.getElementById("degree");
const institutionInput = document.getElementById("insitution");
if (nameInput && fileInput && emailInput && phoneInput &&
locationInput && jobTypeInput && companyInput &&
jobDateInput && degreeInput && institutionInput &&
resumeContainer && resumeBox) {
// Create the form data object
const formData = {
name: nameInput.value,
file: fileInput.files ? fileInput.files[0] : null,
email: emailInput.value,
phoneNumber: phoneInput.value,
location: locationInput.value,
jobType: jobTypeInput.value,
company: companyInput.value,
jobDate: jobDateInput.value,
degree: degreeInput.value,
institution: institutionInput.value,
};
// Create a URL for the uploaded image file if provided
let imageURL = '';
if (formData.file) {
imageURL = URL.createObjectURL(formData.file);
}
// Generate HTML for the resume
const resumeHTML = `
<h1>Resume Generated</h1>
<hr>
<div id="name-img">
<h2>${formData.name}</h2>
<span><img src="${imageURL}" alt="Image"></span>
</div>
<hr>
<p><strong>Email:</strong> ${formData.email}</p>
<p><strong>Phone Number:</strong> ${formData.phoneNumber}</p>
<p><strong>Location:</strong> ${formData.location}</p>
<hr>
<h3>Experience</h3>
<p><strong>Job Type:</strong> ${formData.jobType}</p>
<p><strong>Company:</strong> ${formData.company}</p>
<p><strong>Job Date:</strong> ${formData.jobDate}</p>
<hr>
<h3>Education</h3>
<p><strong>Degree:</strong> ${formData.degree}</p>
<p><strong>Institution:</strong> ${formData.institution}</p>
`;
// Update the resume container with the generated HTML
if (resumeContainer) {
resumeContainer.innerHTML = resumeHTML;
}
// Show the resume box and hidden buttons
if (hiddenButtons)
hiddenButtons.style.display = "flex";
if (resumeBox)
resumeBox.style.display = "flex";
// Scroll into view
const outputResume = document.getElementById("output-resume");
if (outputResume) {
outputResume.scrollIntoView({ behavior: 'smooth' });
}
}
});
// Handle the edit button click event
if (editButton) {
editButton.addEventListener("click", () => {
const nameInput = document.getElementById("name");
const fileInput = document.getElementById("file");
const emailInput = document.getElementById("email");
const phoneInput = document.getElementById("phone-number");
const locationInput = document.getElementById("location");
const jobTypeInput = document.getElementById("job-type");
const companyInput = document.getElementById("comapny");
const jobDateInput = document.getElementById("job-date");
const degreeInput = document.getElementById("degree");
const institutionInput = document.getElementById("insitution");
if (nameInput && fileInput && emailInput && phoneInput &&
locationInput && jobTypeInput && companyInput &&
jobDateInput && degreeInput && institutionInput &&
resumeBox) {
// Repopulate form fields with previous data
if (nameInput)
nameInput.value = nameInput.value; // No changes
if (fileInput)
fileInput.value = ''; // Files cannot be programmatically set
if (emailInput)
emailInput.value = emailInput.value;
if (phoneInput)
phoneInput.value = phoneInput.value;
if (locationInput)
locationInput.value = locationInput.value;
if (jobTypeInput)
jobTypeInput.value = jobTypeInput.value;
if (companyInput)
companyInput.value = companyInput.value;
if (jobDateInput)
jobDateInput.value = jobDateInput.value;
if (degreeInput)
degreeInput.value = degreeInput.value;
if (institutionInput)
institutionInput.value = institutionInput.value;
// Hide the resume box to show the form again
if (resumeBox)
resumeBox.style.display = "none";
}
});
}
}
});
// // Declare the jsPDF property on the global window object
// declare global {
// interface Window {
// jspdf: any; // 'any' type is used here for simplicity. You can specify the jsPDF type if you prefer.
// }
// }
// document.addEventListener("DOMContentLoaded", () => {
// const downloadButton = document.getElementById('download-pdf-button') as HTMLButtonElement;
// // Handle Download PDF button click
// downloadButton?.addEventListener('click', () => {
// // Use window.jspdf as declared above
// const doc = new window.jspdf.jsPDF();
// // Capture form data
// const name = (document.getElementById('name') as HTMLInputElement).value;
// const email = (document.getElementById('email') as HTMLInputElement).value;
// const phone = (document.getElementById('phone-number') as HTMLInputElement).value;
// const location = (document.getElementById('location') as HTMLInputElement).value;
// const jobType = (document.getElementById('job-type') as HTMLInputElement).value;
// const company = (document.getElementById('comapny') as HTMLInputElement).value;
// const jobDate = (document.getElementById('job-date') as HTMLInputElement).value;
// const degree = (document.getElementById('degree') as HTMLInputElement).value;
// const institution = (document.getElementById('insitution') as HTMLInputElement).value;
// // Add form data to the PDF document
// doc.text("Resume Information", 10, 10);
// doc.text(`Name: ${name}`, 10, 20);
// doc.text(`Email: ${email}`, 10, 30);
// doc.text(`Phone Number: ${phone}`, 10, 40);
// doc.text(`Location: ${location}`, 10, 50);
// doc.text(`Job Type: ${jobType}`, 10, 60);
// doc.text(`Company: ${company}`, 10, 70);
// doc.text(`Job Date: ${jobDate}`, 10, 80);
// doc.text(`Degree: ${degree}`, 10, 90);
// doc.text(`Institution: ${institution}`, 10, 100);
// // Save the PDF
// doc.save('resume.pdf');
// });
// })