Autofull UV small changes

This commit is contained in:
tleb
2019-10-20 17:09:36 +02:00
parent bddb88d97f
commit 4759551c16
2 changed files with 14 additions and 9 deletions

View File

@ -24,7 +24,7 @@
{% if field.name == 'code' %}
<a href="javascript:void(0)" id="autofill">Fill</a>
<button type="button" id="autofill">{% trans %}Import from UTBM{% endtrans %}</button>
{% endif %}
</p>
{% endif %}
@ -48,13 +48,13 @@
autofillBtn.addEventListener('click', () => {
const today = new Date()
let year = today.getFullYear()
if (today.getMonth() < 7) { // student year, starts in september
if (today.getMonth() < 7) { // student year starts in september
year--
}
const url = "{{ url('api:uv_endpoint') }}?year=" + year + "&code=" + codeInput.value
$.getJSON(url, function(data, _, xhr) {
if (xhr.status != 200) {
alert('{% trans %}Unknown UV code{% endtrans %}')
alert("{% trans %}Unknown UV code{% endtrans %}")
return
}
for (let key in data) {
@ -68,9 +68,10 @@
}
}
alert('{% trans %}Successful autocomplete{% endtrans %}')
})
})
})
</script>
{% endblock %}