Skip to content
Snippets Groups Projects
Commit b6545312 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

configuration panel allows modifying elements

parent ac1a2f00
No related branches found
No related tags found
1 merge request!36Resolve "configuration panel"
...@@ -24,8 +24,9 @@ urlpatterns = [ ...@@ -24,8 +24,9 @@ urlpatterns = [
# appointment types # appointment types
url(r'^appointment_types$', appointment_type.appointment_types, name='web.api.appointment_types'), url(r'^appointment_types$', appointment_type.appointment_types, name='web.api.appointment_types'),
# appointments # configuration items
url(r'^configuration_items$', configuration.configuration_items, name='web.api.configuration_items'), url(r'^configuration_items$', configuration.configuration_items, name='web.api.configuration_items'),
url(r'^configuration_items/update$', configuration.update_configuration_item, name='web.api.update_configuration_item'),
# subjects data # subjects data
url(r'^cities$', subject.cities, name='web.api.cities'), url(r'^cities$', subject.cities, name='web.api.cities'),
......
...@@ -31,3 +31,26 @@ def configuration_items(request): ...@@ -31,3 +31,26 @@ def configuration_items(request):
"recordsFiltered": count_filtered, "recordsFiltered": count_filtered,
"data": data "data": data
}) })
@login_required
def update_configuration_item(request):
id = int(request.GET.get("id", None))
value = request.GET.get("value", None)
if (id is None) or (value is None):
return JsonResponse({
"status": "error",
"message": "id and value are obligatory"
})
item = ConfigurationItem.objects.get(id=id)
if item is None:
return JsonResponse({
"status": "error",
"message": "item with given id doesn't exist"
})
item.value=value
item.save()
return JsonResponse({
"status": "ok",
})
...@@ -22,21 +22,22 @@ ...@@ -22,21 +22,22 @@
{% block maincontent %} {% block maincontent %}
<div> <div>
<div> <div id="message">
<table id="table" class="table table-bordered table-striped">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<hr/>
</div> </div>
<table id="table" class="table table-bordered table-striped">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<hr/>
</div> </div>
{% endblock maincontent %} {% endblock maincontent %}
...@@ -49,6 +50,33 @@ ...@@ -49,6 +50,33 @@
<script src="{% static 'AdminLTE/plugins/moment.js/moment.min.js' %}"></script> <script src="{% static 'AdminLTE/plugins/moment.js/moment.min.js' %}"></script>
<script> <script>
function update(id) {
var value = $("#value-" + id).val();
var data = {
"id": id,
"value": value,
"_": Math.random()
};
$.ajax({
type: "GET",
url: "{% url 'web.api.update_configuration_item' %}",
data: data,
success: function (response) {
var message;
var classString;
if (response.status == "ok") {
message = "Element modified successfully";
classString = "alert alert-success"
} else {
message = "Problem with modifying element: " + response.message;
classString = "alert alert-danger"
}
$("#message").html(message);
$("#message").attr('class', classString);
},
});
}
$(function () { $(function () {
$(function () { $(function () {
var table = $('#table').DataTable({ var table = $('#table').DataTable({
...@@ -60,6 +88,21 @@ ...@@ -60,6 +88,21 @@
{"data": "name"}, {"data": "name"},
{"data": "value"}, {"data": "value"},
], ],
columnDefs: [
{
render: function (data, type, row) {
return '<button class="btn btn-block btn-default" onclick="update(' + row.id + ')">Save</button>'
},
targets: 2
},
{
render: function (data, type, row) {
return '<input id="value-' + row.id + '" type="text" value="' + row.value + '" class="form-control"/>'
},
targets: 1
}
]
}); });
$('#table_filter').css("display", "none"); $('#table_filter').css("display", "none");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment