Commit 70d47c00 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

device config correct ajax and redirect added. done

parent dcbba1e7
......@@ -2,7 +2,10 @@
{% block title %} HPC&A IoT - Device Configuration {% endblock %}
{% block header %} <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> {% endblock %}
{% block header %}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
{% endblock %}
{% block location %} <a class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block" href="./applications">Applications</a>
<p class="h4 mb-0 text-white text-uppercase d-none d-lg-inline-block"> &nbsp;-&nbsp; </p>
......@@ -22,7 +25,7 @@
<h3 class="mb-0">Device Configuration - {{ dev[0] }}</h3>
</div>
<div class="card-body">
<form action="" method="post">
<form id="confform" onsubmit="onsub()">
<div class="form-group">
<label>Config ID:</label><br>
<input type="number" min="0" max="255" size="3" class="form-control" id="confid" name="confid" required><br>
......@@ -39,7 +42,7 @@
<br>
</form>
<div class="card-header bg-transparent">
<h3 class="mb-0">Configuration history</h3>
<h3 class="mb-0" id="confhistory">Configuration history</h3>
</div>
{% if config_list %}
<table class="table">
......@@ -62,7 +65,7 @@
{% endif %}
</span>
</td>
<td> <a href="/application/{{ app[1] }}/device/{{ dev[1] }}/remove-configuration?conf={{ c[3] }}"> <span class="fa fa-remove"</span> </a> </td>
<td> <a href="javascript:void(0)" onclick="return remove_configuration('{{ c[3][0:-1] }}')"> <span class="fa fa-remove"> </span> </a> </td>
</tr>
{% endfor %}
</tbody>
......@@ -77,3 +80,27 @@
</div>
</div>
{% endblock %}
{% block script %}
<script type="text/javascript">
function onsub() {
$.ajax({
url:"/application/{{ app[1] }}/device/{{ dev[1] }}/configure",
type:"post",
data:$("#confform").serialize(),
success: function() {
location.reload();
}
});
}
function remove_configuration(b64) {
$.ajax({
url:"/application/{{ app[1] }}/device/{{ dev[1] }}/remove-configuration?conf="+b64,
type:"get",
success: function() {
location.reload();
}
});
}
</script>
{% endblock %}
......@@ -263,11 +263,11 @@ def application_device_configuration(appkey, devid):
config_list.append((config_id, config_args, ack, pm[2]))
return render_template('new/public/device-configuration.html', dev=dev, app=ap, config_list=config_list)
else:
elif request.method == 'POST':
base64_args = misc.pend_base64_encode(request.form['arg'], request.form['confid'])
pend.create(appkey, devid, base64_args)
return redirect(url_for('applications'))
return '', 201
else:
return redirect(url_for('login'))
......@@ -430,10 +430,10 @@ def dev_conf_rm(appkey, devid):
if res[0]:
flash('Configuration message successfully removed.','success')
return redirect(url_for('applications'))
else:
flash('Error removing configuration message: {}'.format(res[1]), 'danger')
return redirect(url_for('applications'))
return '', 200
else:
return redirect(url_for('login'))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment