From 1d393325e5bb420b8d57e2f1e8c851206dc693bd Mon Sep 17 00:00:00 2001 From: Christophe Fontaine Date: Fri, 30 Oct 2020 17:00:27 +0100 Subject: [PATCH] Add URI Fragment support Fix #13 Les champs disponibles sont: lastname,firstname,birthday,placeofbirth,address,city,zipcode,reason - "reason" peut etre repete plusieurs fois pour cocher plusieurs motifs. - "autogenpdf" simule un click pour une generation automatique du pdf. exemple: http://.../#lastname=Dupont&firstname=Jean&birthday=01/01/1950&placeofbirth=Paris&address=zzz&city=Paris&zipcode=75000&reason=travail&reason=achats&autogenpdf --- src/js/main.js | 2 ++ src/js/util.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/js/main.js b/src/js/main.js index 48fc43a2..9926f1a9 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -7,9 +7,11 @@ import './check-updates' import { prepareForm } from './form-util' import { warnFacebookBrowserUserIfNecessary } from './facebook-util' import { addVersion } from './util' +import { autoFill } from './util' import { createForm } from './form' warnFacebookBrowserUserIfNecessary() createForm() prepareForm() addVersion(process.env.VERSION) +autoFill() diff --git a/src/js/util.js b/src/js/util.js index 00b19eaf..e8aa9050 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -33,3 +33,26 @@ export function addVersion (version) { 'version', ).innerHTML = `${new Date().getFullYear()} - ${version}` } + +export function autoFill() { + const params = new URLSearchParams( + window.location.hash.substr(1) // skip the first char (#) + ); + const fields = ["lastname", "firstname", "birthday", "placeofbirth", + "address", "city", "zipcode"] + function fillField(f) { + if (params.has(f) == true) { + document.getElementById("field-"+f).value = params.get(f); + } + } + fields.forEach(fillField); + + function checkReason(r) { + document.getElementById("checkbox-"+r).checked = true; + } + params.getAll("reason").forEach(checkReason); + + if(params.has("autogenpdf") == true) { + document.getElementById("generate-btn").click(); + } +}