Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ne pas utiliser le localStorage #34

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions src/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,16 @@ function setReleaseDateTime () {
releaseTimeInput.value = `${hour}:${minute}`
}

function saveProfile () {
function getProfile () {
const fields = {}
for (const field of $$('#form-profile input')) {
if (field.id === 'field-datesortie') {
var dateSortie = field.value.split('-')
localStorage.setItem(field.id.substring('field-'.length), `${dateSortie[2]}/${dateSortie[1]}/${dateSortie[0]}`)
fields[field.id.substring('field-'.length)] = `${dateSortie[2]}/${dateSortie[1]}/${dateSortie[0]}`
} else {
localStorage.setItem(field.id.substring('field-'.length), field.value)
fields[field.id.substring('field-'.length)] = field.value
}
}
}

function getProfile () {
const fields = {}
for (let i = 0; i < localStorage.length; i++) {
const name = localStorage.key(i)
fields[name] = localStorage.getItem(name)
}
return fields
}

Expand Down Expand Up @@ -201,11 +194,10 @@ function downloadBlob (blob, fileName) {
link.click()
}

function getAndSaveReasons () {
function getReasons () {
const values = $$('input[name="field-reason"]:checked')
.map(x => x.value)
.join('-')
localStorage.setItem('reasons', values)
return values
}

Expand Down Expand Up @@ -240,10 +232,8 @@ const snackbar = $('#snackbar')
$('#generate-btn').addEventListener('click', async event => {
event.preventDefault()

saveProfile()
const reasons = getAndSaveReasons()
const reasons = getReasons()
const pdfBlob = await generatePdf(getProfile(), reasons)
localStorage.clear()
downloadBlob(pdfBlob, 'attestation.pdf')

snackbar.classList.remove('d-none')
Expand Down