Also make pressing return submit the manual number
This commit is contained in:
parent
1258bfe3a1
commit
9ca961d706
|
@ -25,14 +25,19 @@
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column col-md-12 col-6">
|
<div class="column col-md-12 col-6">
|
||||||
<h2>Handmatig Toevoegen</h2>
|
<h2>Handmatig Toevoegen</h2>
|
||||||
|
<form id="student_number_wrapper">
|
||||||
<p><label for="student_number">Leerlingnummer:</label></p>
|
<p><label for="student_number">Leerlingnummer:</label></p>
|
||||||
<input type="text" id="student_number" name="student_number" placeholder="Leerlingnummer">
|
<input type="text" id="student_number" name="student_number" placeholder="Leerlingnummer">
|
||||||
<button class="btn btn-primary" id="add_student">"Scan"</button>
|
<button class="btn btn-primary" id="add_student">"Scan"</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="column col-md-12 col-6">
|
<div class="column col-md-12 col-6">
|
||||||
<h2>Extra opties</h2>
|
<h2>Extra opties</h2>
|
||||||
<p><a href="/party/{{id}}/lijst">Bekijk een tabel in je browser</a></p>
|
<p><a href="/party/{{id}}/lijst">Bekijk een tabel in je browser</a></p>
|
||||||
<p><a href="/party/{{id}}/export">Exporteer als CSV</a></p>
|
<p><a href="/party/{{id}}/export">Exporteer als CSV</a></p>
|
||||||
|
<p><label for="file-selector">Importeer CSV:</label><input type="file" id="file-selector"
|
||||||
|
accept=".csv" /></p>
|
||||||
|
<p><button id="file-selector-button">Importeer</button> <span id="import-result"></span></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -120,11 +125,19 @@
|
||||||
return data;
|
return data;
|
||||||
}).then(set_state);
|
}).then(set_state);
|
||||||
}
|
}
|
||||||
|
function return_handler(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
let code = document.getElementById("student_number").value;
|
||||||
|
console.log(code);
|
||||||
|
scan_ticket(code);
|
||||||
|
}
|
||||||
|
|
||||||
function button_click_handler() {
|
function button_click_handler() {
|
||||||
let code = document.getElementById("student_number").value;
|
let code = document.getElementById("student_number").value;
|
||||||
scan_ticket(code);
|
scan_ticket(code);
|
||||||
}
|
}
|
||||||
document.getElementById("add_student").addEventListener("click", button_click_handler);
|
document.getElementById("add_student").addEventListener("click", button_click_handler);
|
||||||
|
document.getElementById("student_number_wrapper").addEventListener("submit", return_handler);
|
||||||
document.getElementById("start_scan_btn").addEventListener('click', start_scanning);
|
document.getElementById("start_scan_btn").addEventListener('click', start_scanning);
|
||||||
|
|
||||||
const videoElement = document.querySelector("video");
|
const videoElement = document.querySelector("video");
|
||||||
|
@ -216,5 +229,29 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function upload_csv() {
|
||||||
|
let file = document.getElementById("file-selector").files[0];
|
||||||
|
if (file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
let num = 0;
|
||||||
|
reader.onload = (evt) => {
|
||||||
|
let result = evt.target.result;
|
||||||
|
for (let line of result.split("\n")) {
|
||||||
|
for (let llnr of line.split(",")) {
|
||||||
|
if (llnr.length === 6 && !isNaN(llnr)) {
|
||||||
|
scan_ticket(llnr);
|
||||||
|
num += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.getElementById("import-result").innerHTML = `${num} leerlingen geïmporteerd!`
|
||||||
|
}
|
||||||
|
reader.readAsText(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("file-selector-button").addEventListener("click", upload_csv);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in a new issue