mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-01-18 05:50:34 +00:00
Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development
This commit is contained in:
commit
4dce792b51
@ -16,6 +16,29 @@ nopaque["foreignJobsSubscribers"] = [];
|
|||||||
|
|
||||||
|
|
||||||
// nopaque functions
|
// nopaque functions
|
||||||
|
nopaque["forms"] = {};
|
||||||
|
nopaque["forms"]["init"] = function() {
|
||||||
|
for (let form of document.querySelectorAll(".nopaque-form")) {
|
||||||
|
form.addEventListener("submit", function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (form.dataset.hasOwnProperty('loadingModal')) {
|
||||||
|
let loadingModalElement = document.getElementById(form.dataset.loadingModal);
|
||||||
|
M.Modal.getInstance(loadingModalElement).open();
|
||||||
|
}
|
||||||
|
let data = {};
|
||||||
|
for (let input of form.querySelectorAll("input")) {
|
||||||
|
if (input.type === "file") {
|
||||||
|
file = input.files[0];
|
||||||
|
data[`${input.name}-wrapper`] = {"bytes": file, "name": file.name};
|
||||||
|
} else {
|
||||||
|
data[input.name] = input.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nopaque.socket.emit(`submit-${form.id}`, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nopaque["navigation"] = {};
|
nopaque["navigation"] = {};
|
||||||
nopaque["navigation"]["init"] = function() {
|
nopaque["navigation"]["init"] = function() {
|
||||||
for (let entry of document.querySelectorAll("#slide-out a:not(.subheader)")) {
|
for (let entry of document.querySelectorAll("#slide-out a:not(.subheader)")) {
|
||||||
@ -112,6 +135,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
{"alignment": "right", "constrainWidth": false, "coverTrigger": false});
|
{"alignment": "right", "constrainWidth": false, "coverTrigger": false});
|
||||||
M.Dropdown.init(document.getElementById("nav-account"),
|
M.Dropdown.init(document.getElementById("nav-account"),
|
||||||
{"alignment": "right", "constrainWidth": false, "coverTrigger": false});
|
{"alignment": "right", "constrainWidth": false, "coverTrigger": false});
|
||||||
|
nopaque.forms.init();
|
||||||
nopaque.navigation.init();
|
nopaque.navigation.init();
|
||||||
nopaque.socket.emit("subscribe_user_ressources");
|
nopaque.socket.emit("subscribe_user_ressources");
|
||||||
});
|
});
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
DarkReader.enable({"brightness": 100, "contrast": 100, "sepia": 0});
|
DarkReader.enable({"brightness": 100, "contrast": 100, "sepia": 0});
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for flashed_message in get_flashed_messages() %}
|
{% for flashed_message in get_flashed_messages() %}
|
||||||
toast("{{ flashed_message }}");
|
nopaque.toast("{{ flashed_message }}");
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<form id="test-form">
|
<form class="nopaque-form" data-loading-modal="test-progress-modal" id="test-form">
|
||||||
{{ test_form.hidden_tag() }}
|
{{ test_form.hidden_tag() }}
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -45,32 +45,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</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>
|
<script>
|
||||||
var testFormElement = document.forms.namedItem("test-form");
|
var testFormElement = document.forms.namedItem("test-form");
|
||||||
|
|
||||||
testFormElement.addEventListener("submit", function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
let data = {};
|
|
||||||
for (let input of event.target.querySelectorAll("input")) {
|
|
||||||
if (input.type === "file") {
|
|
||||||
file = input.files[0];
|
|
||||||
data[input.name] = {"bytes": file, "name": file.name};
|
|
||||||
} else {
|
|
||||||
data[input.name] = input.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nopaque.socket.emit("submit-test-form", data);
|
|
||||||
});
|
|
||||||
|
|
||||||
nopaque.socket.on("submit-test-form", function(response) {
|
nopaque.socket.on("submit-test-form", function(response) {
|
||||||
console.log(response);
|
let loadingModalElement = document.getElementById(testFormElement.dataset.loadingModal);
|
||||||
if (response.status === "success") {
|
if (response.status === 201) {
|
||||||
testFormElement.reset();
|
testFormElement.reset();
|
||||||
nopaque.toast("Success!");
|
for (let helperText of testFormElement.querySelectorAll(".helper-text")) {
|
||||||
for (let helperText of testFormElement.querySelectorAll(".helper-text")) {
|
helperText.remove();
|
||||||
helperText.remove();
|
}
|
||||||
}
|
nopaque.toast("Success!");
|
||||||
} else if (response.status === "error") {
|
} else if (response.status === 400) {
|
||||||
let errorElement;
|
let errorElement;
|
||||||
for (let [field, error] of Object.entries(response.msg)) {
|
for (let [field, error] of Object.entries(response.msg)) {
|
||||||
errorElement = document.createElement("span");
|
errorElement = document.createElement("span");
|
||||||
@ -79,6 +74,7 @@ nopaque.socket.on("submit-test-form", function(response) {
|
|||||||
testFormElement.querySelector(`input[name="${field}"]`).closest(".input-field").appendChild(errorElement);
|
testFormElement.querySelector(`input[name="${field}"]`).closest(".input-field").appendChild(errorElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
M.Modal.getInstance(loadingModalElement).close();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -9,16 +9,15 @@ import io
|
|||||||
@socketio.on('submit-test-form')
|
@socketio.on('submit-test-form')
|
||||||
@login_required
|
@login_required
|
||||||
def recv_test_form(data):
|
def recv_test_form(data):
|
||||||
filename = secure_filename(data['file']['name'])
|
logger.warning("data_received")
|
||||||
stream = io.BytesIO(data['file']['bytes'])
|
filename = secure_filename(data['file-wrapper']['name'])
|
||||||
file = FileStorage(stream=stream, filename=filename)
|
stream = io.BytesIO(data['file-wrapper']['bytes'])
|
||||||
|
file = FileStorage(filename=filename, stream=stream)
|
||||||
data['file'] = file
|
data['file'] = file
|
||||||
test_form = TestForm(data=data)
|
test_form = TestForm(data=data)
|
||||||
if test_form.validate():
|
if test_form.validate():
|
||||||
logger.warning('test_form is ok!')
|
socketio.emit('submit-test-form', {'msg': {},
|
||||||
socketio.emit('submit-test-form', {'status': 'success',
|
'status': 201})
|
||||||
'msg': 'test_form is ok!'})
|
|
||||||
else:
|
else:
|
||||||
logger.warning('test_form is not ok!')
|
socketio.emit('submit-test-form', {'msg': test_form.errors,
|
||||||
socketio.emit('submit-test-form', {'status': 'error',
|
'status': 400})
|
||||||
'msg': test_form.errors})
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user