diff --git a/smash/web/api_urls.py b/smash/web/api_urls.py index 304f018ed9f83b9d6e3be8c5cdefa1523c4805f9..7556904693f0ccd6f35c23e7dca33c37b53d86bc 100644 --- a/smash/web/api_urls.py +++ b/smash/web/api_urls.py @@ -24,8 +24,9 @@ urlpatterns = [ # 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/update$', configuration.update_configuration_item, name='web.api.update_configuration_item'), # subjects data url(r'^cities$', subject.cities, name='web.api.cities'), diff --git a/smash/web/api_views/configuration.py b/smash/web/api_views/configuration.py index efa7daf01d38021fc713b615bad5938ac526615f..25d529626f102c8c3854be0a9a86e51048e04619 100644 --- a/smash/web/api_views/configuration.py +++ b/smash/web/api_views/configuration.py @@ -31,3 +31,26 @@ def configuration_items(request): "recordsFiltered": count_filtered, "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", + }) diff --git a/smash/web/templates/configuration/index.html b/smash/web/templates/configuration/index.html index 60e11a3d5af0ea03e7c96a32083dc211fc1dcee2..0b89158255f34e2027b3a624b14db6fb052333f6 100644 --- a/smash/web/templates/configuration/index.html +++ b/smash/web/templates/configuration/index.html @@ -22,21 +22,22 @@ {% block maincontent %} <div> - <div> - <table id="table" class="table table-bordered table-striped"> - <thead> - <tr> - <th>Name</th> - <th>Value</th> - </tr> - </thead> - <tbody> - </tbody> - </table> - - <hr/> - + <div id="message"> </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> {% endblock maincontent %} @@ -49,6 +50,33 @@ <script src="{% static 'AdminLTE/plugins/moment.js/moment.min.js' %}"></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 () { var table = $('#table').DataTable({ @@ -60,6 +88,21 @@ {"data": "name"}, {"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");