mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
81 lines
2.6 KiB
Django/Jinja
81 lines
2.6 KiB
Django/Jinja
{% extends "limited_width.html.j2" %}
|
|
|
|
{% block page_content %}
|
|
<div class="col s12">
|
|
<h3>Submit a Test</h3>
|
|
</div>
|
|
|
|
<div class="col s12">
|
|
<div class="card">
|
|
<form class="nopaque-form" data-loading-modal="test-progress-modal" id="test-form">
|
|
{{ test_form.hidden_tag() }}
|
|
<div class="card-content">
|
|
<div class="row">
|
|
<div class="col s12 m4">
|
|
<div class="input-field">
|
|
<i class="material-icons prefix">title</i>
|
|
{{ test_form.title(class='validate', data_length='32') }}
|
|
{{ test_form.title.label }}
|
|
</div>
|
|
</div>
|
|
<div class="col s12 m8">
|
|
<div class="input-field">
|
|
<i class="material-icons prefix">description</i>
|
|
{{ test_form.description(class='validate', data_length='255') }}
|
|
{{ test_form.description.label }}
|
|
</div>
|
|
</div>
|
|
<div class="col s12">
|
|
<div class="file-field input-field">
|
|
<div class="btn">
|
|
<span>{{ test_form.file.label.text }}</span>
|
|
{{ test_form.file() }}
|
|
</div>
|
|
<div class="file-path-wrapper">
|
|
<input class="file-path validate" type="text">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-action right-align">
|
|
<button class="btn waves-effect waves-light" name="submit" type="submit">Submit<i class="material-icons right">send</i></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal" id="test-progress-modal">
|
|
<div class="modal-content">
|
|
<h4>Waiting for data transfer</h4>
|
|
<div class="progress">
|
|
<div class="indeterminate"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var testFormElement = document.forms.namedItem("test-form");
|
|
|
|
nopaque.socket.on("submit-test-form", function(response) {
|
|
let loadingModalElement = document.getElementById(testFormElement.dataset.loadingModal);
|
|
if (response.status === 201) {
|
|
testFormElement.reset();
|
|
for (let helperText of testFormElement.querySelectorAll(".helper-text")) {
|
|
helperText.remove();
|
|
}
|
|
nopaque.toast("Success!");
|
|
} else if (response.status === 400) {
|
|
let errorElement;
|
|
for (let [field, error] of Object.entries(response.msg)) {
|
|
errorElement = document.createElement("span");
|
|
errorElement.classList.add("helper-text", "red-text");
|
|
errorElement.innerText = error;
|
|
testFormElement.querySelector(`input[name="${field}"]`).closest(".input-field").appendChild(errorElement);
|
|
}
|
|
}
|
|
M.Modal.getInstance(loadingModalElement).close();
|
|
});
|
|
</script>
|
|
{% endblock %}
|