nopaque/app/templates/test/index.html.j2

81 lines
2.6 KiB
Plaintext
Raw Normal View History

{% 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">
2020-01-23 10:19:37 +00:00
<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>
2020-01-23 08:43:51 +00:00
{{ 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>
2020-01-23 08:43:51 +00:00
{{ 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>
2020-01-23 10:19:37 +00:00
<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>
2020-01-23 08:43:51 +00:00
var testFormElement = document.forms.namedItem("test-form");
nopaque.socket.on("submit-test-form", function(response) {
2020-01-23 10:19:37 +00:00
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);
}
}
2020-01-23 10:19:37 +00:00
M.Modal.getInstance(loadingModalElement).close();
});
</script>
{% endblock %}