From 91c4e72aedbccb9b07c0b6b57687a6503f70ad0d Mon Sep 17 00:00:00 2001
From: Quentin Dunand
- En application du décret n°2020-1310 du 29 octobre 2020 prescrivant les mesures générales
- nécessaires pour faire face à l'épidémie de Covid19 dans le cadre de l'état d'urgence sanitaire
+ En application du décret n°2020-1310 du 29 octobre 2020 prescrivant les mesures générales
+ nécessaires pour faire face à l'épidémie de Covid19 dans le cadre de l'état d'urgence sanitaire
id="alert-facebook"
>
- -
++ +
+
+ [1] Les personnes souhaitant bénéficier de l'une de ces exceptions doivent se munir s'il y a lieu, lors de leurs déplacements hors de leur domicile, d'un document leur permettant de justifier que le déplacement considéré entre dans le champ de l'une de ces exceptions.
diff --git a/src/js/form-util.js b/src/js/form-util.js
index 4ce61869..91c235ec 100644
--- a/src/js/form-util.js
+++ b/src/js/form-util.js
@@ -4,6 +4,11 @@ import { $, $$, downloadBlob } from './dom-utils'
import { addSlash, getFormattedDate } from './util'
import pdfBase from '../certificate.pdf'
import { generatePdf } from './pdf-util'
+import SecureLS from 'secure-ls'
+
+const secureLS = new SecureLS({ encodingType: 'aes' })
+const clearDataSnackbar = $('#snackbar-cleardata')
+const storeDataInput = $('#field-storedata')
const conditions = {
'#field-firstname': {
@@ -55,6 +60,45 @@ function validateAriaFields () {
.includes(true)
}
+function updateSecureLS (formInputs, reasonInputs) {
+ if (wantDataToBeStored() === true) {
+ secureLS.set('profile', getProfile(formInputs))
+ secureLS.set('reason', getReasonsObject(reasonInputs))
+ } else {
+ clearSecureLS()
+ }
+}
+
+function clearSecureLS () {
+ secureLS.clear()
+}
+
+function clearForm () {
+ const formProfile = $('#form-profile')
+ formProfile.reset()
+}
+
+function setCurrentDate (releaseDateInput, releaseTimeInput) {
+ const currentDate = new Date()
+
+ releaseDateInput.value = getFormattedDate(currentDate)
+ releaseTimeInput.value = currentDate.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' })
+}
+
+function showSnackbar (snackbarToShow, showDuration = 6000) {
+ snackbarToShow.classList.remove('d-none')
+ setTimeout(() => snackbarToShow.classList.add('show'), 100)
+
+ setTimeout(function () {
+ snackbarToShow.classList.remove('show')
+ setTimeout(() => snackbarToShow.classList.add('d-none'), 500)
+ }, showDuration)
+}
+
+export function wantDataToBeStored () {
+ return storeDataInput.checked
+}
+
export function setReleaseDateTime (releaseDateInput) {
const loadedDate = new Date()
releaseDateInput.value = getFormattedDate(loadedDate)
@@ -90,8 +134,40 @@ export function getReasons (reasonInputs) {
return reasons
}
-export function prepareInputs (formInputs, reasonInputs, reasonFieldset, reasonAlert, snackbar) {
+export function getReasonsObject (reasonInputs) {
+ const reasons = reasonInputs
+ .filter((reason) => reason.checked)
+ .reduce(function (map, reason) {
+ map[reason.value] = reason.checked
+ return map
+ }, {})
+ return reasons
+}
+
+export function prepareInputs (formInputs, reasonInputs, reasonFieldset, reasonAlert, snackbar, releaseDateInput, releaseTimeInput) {
+ const lsProfile = secureLS.get('profile')
+ const lsReason = secureLS.get('reason')
+ const currentDate = new Date()
+ const formattedDate = getFormattedDate(currentDate)
+ const formattedTime = currentDate.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' })
+
+ // Continue to store data if already stored
+ storeDataInput.checked = lsReason || lsProfile
+
formInputs.forEach((input) => {
+ switch (input.name) {
+ case 'datesortie':
+ input.value = formattedDate
+ break
+ case 'heuresortie':
+ input.value = formattedTime
+ break
+ case 'field-reason':
+ if (lsReason) input.checked = lsReason[input.value]
+ break
+ default:
+ if (lsProfile) input.value = lsProfile[input.name]
+ }
const exempleElt = input.parentNode.parentNode.querySelector('.exemple')
const validitySpan = input.parentNode.parentNode.querySelector('.validity')
if (input.placeholder && exempleElt) {
@@ -123,6 +199,17 @@ export function prepareInputs (formInputs, reasonInputs, reasonFieldset, reasonA
})
})
+ $('#formgroup-storedata').addEventListener('click', () => {
+ (storeDataInput.checked) ? storeDataInput.checked = false : storeDataInput.checked = true
+ })
+
+ $('#cleardata').addEventListener('click', () => {
+ clearSecureLS()
+ clearForm()
+ setCurrentDate(releaseDateInput, releaseTimeInput)
+ showSnackbar(clearDataSnackbar, 1200)
+ })
+
$('#generate-btn').addEventListener('click', async (event) => {
event.preventDefault()
@@ -139,6 +226,8 @@ export function prepareInputs (formInputs, reasonInputs, reasonFieldset, reasonA
return
}
+ updateSecureLS(formInputs, reasonInputs)
+
const pdfBlob = await generatePdf(getProfile(formInputs), reasons, pdfBase)
const creationInstant = new Date()
@@ -166,6 +255,7 @@ export function prepareForm () {
const reasonFieldset = $('#reason-fieldset')
const reasonAlert = reasonFieldset.querySelector('.msg-alert')
const releaseDateInput = $('#field-datesortie')
+ const releaseTimeInput = $('#field-heuresortie')
setReleaseDateTime(releaseDateInput)
- prepareInputs(formInputs, reasonInputs, reasonFieldset, reasonAlert, snackbar)
+ prepareInputs(formInputs, reasonInputs, reasonFieldset, reasonAlert, snackbar, releaseDateInput, releaseTimeInput)
}
From de08bf906f8ff95aa92ee9e36e657c7b740d0566 Mon Sep 17 00:00:00 2001
From: Quentin Dunand
id="field-storedata"
value="storedata">
-
+
[1] Les personnes souhaitant bénéficier de l'une de ces exceptions doivent se munir s'il y a lieu, lors de leurs déplacements hors de leur domicile, d'un document leur permettant de justifier que le déplacement considéré entre dans le champ de l'une de ces exceptions.
diff --git a/src/js/form-util.js b/src/js/form-util.js
index 527ac7d0..d052d439 100644
--- a/src/js/form-util.js
+++ b/src/js/form-util.js
@@ -136,13 +136,12 @@ export function getReasons (reasonInputs) {
}
export function getReasonsObject (reasonInputs) {
- const reasons = reasonInputs
+ return reasonInputs
.filter((reason) => reason.checked)
- .reduce(function (map, reason) {
+ .reduce((map, reason) => {
map[reason.value] = reason.checked
return map
}, {})
- return reasons
}
export function prepareInputs (formInputs, reasonInputs, reasonFieldset, reasonAlert, snackbar, releaseDateInput, releaseTimeInput) {
From eba728accbf804250233e5f233affa4e2ab090ef Mon Sep 17 00:00:00 2001
From: Enguerran P
Effacer les données du formulaire ?
+ href="javascript:void(0)">Effacer les données du formulaire