1
0
forked from ScoDoc/ScoDoc
ScoDoc/app/templates/entreprises/form.html

71 lines
2.9 KiB
HTML
Raw Normal View History

2021-12-23 19:28:25 +01:00
{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block styles %}
{{super()}}
<link type="text/css" rel="stylesheet" href="/ScoDoc/static/css/autosuggest_inquisitor.css" />
<script src="/ScoDoc/static/libjs/AutoSuggest.js"></script>
{% endblock %}
{% block app_content %}
<h1>{{ title }}</h1>
<br>
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form, novalidate=True) }}
</div>
</div>
<script>
window.onload = function(e){
var etudiants_options = {
script: "/ScoDoc/entreprises/etudiants?",
varname: "term",
json: true,
noresults: "Valeur invalide !",
minchars: 2,
timeout: 60000
};
var as_etudiants = new bsn.AutoSuggest('etudiant', etudiants_options);
var responsables_options = {
script: "/ScoDoc/entreprises/responsables?",
varname: "term",
json: true,
noresults: "Valeur invalide !",
minchars: 2,
timeout: 60000
};
var as_responsables = new bsn.AutoSuggest('responsable', responsables_options);
document.getElementById("siret").addEventListener("keyup", autocomplete);
function autocomplete() {
var input = document.getElementById("siret").value;
data = null
if(input.length == 14) {
fetch("https://entreprise.data.gouv.fr/api/sirene/v1/siret/" + input)
.then(response => {
if(response.ok)
return response.json()
else {
document.getElementById("nom_entreprise").value = ''
document.getElementById("adresse").value = ''
document.getElementById("codepostal").value = ''
document.getElementById("ville").value = ''
document.getElementById("pays").value = ''
throw new Error("404")
}
})
.then(function(response) {
data = JSON.parse(JSON.stringify(response))
document.getElementById("nom_entreprise").value = data.etablissement.l1_normalisee
document.getElementById("adresse").value = data.etablissement.l4_normalisee
document.getElementById("codepostal").value = data.etablissement.code_postal
document.getElementById("ville").value = data.etablissement.libelle_commune
document.getElementById("pays").value = 'France'
})
.catch(err => err)
}
}
}
</script>
{% endblock %}