Emit query data via socketio

This commit is contained in:
Stephan Porada 2019-11-04 13:19:15 +01:00
parent fa61f97413
commit 9c611afdc3

View File

@ -3,7 +3,7 @@
{% block page_content %}
<div class="col s12 m3 l3 sticky">
<div class="card">
<form method="POST">
<form id="query_form" method="POST">
<div class="card-content">
{{ form.hidden_tag() }}
<span class="card-title">Query and analysis</span>
@ -16,7 +16,7 @@
{% endfor %}
</div>
<div class="right-align">
<button class="btn" type="submit" name="action">Start Query
<button id="sent_query" class="btn" type="submit" name="action">Start Query
<i class="material-icons left">search</i>
</button>
</div>
@ -97,4 +97,25 @@
</div>
</div>
</div>
<script>
let queryData = document.forms['query_form'].elements;
console.log(queryData);
var queryBtn = document.getElementById('sent_query');
queryBtn.addEventListener('click', function(event) {
event.preventDefault();
sendQueryData();
});
function sendQueryData() {
var query_data = {};
for (element of queryData) {
if (!element.value || element.name == 'csrf_token' || !element.id) {
continue;
}
query_data[element.id] = element.value
}
console.log(query_data)
socket.emit('query_event', query_data);
console.log('Query data has been sent!')
}
</script>
{% endblock %}