diff --git a/smash/web/api_views.py b/smash/web/api_views.py index bf4cc61ba54e654a5b8d8bf354c869d9f5120640..bebcbc63e152e55607cbd34e2d9d12f96c882b4d 100644 --- a/smash/web/api_views.py +++ b/smash/web/api_views.py @@ -191,6 +191,7 @@ def serialize_subject(subject): "dead": get_yes_no(subject.dead), "resigned": get_yes_no(subject.resigned), "postponed": get_yes_no(subject.postponed), + "id": subject.id, } return result diff --git a/smash/web/templates/subjects/index.html b/smash/web/templates/subjects/index.html index 581b6cfb159d663627cb5e60a47f3180b459afa3..12d07d7ea562ec21a63a34b7ef14e4c1bad95cf0 100644 --- a/smash/web/templates/subjects/index.html +++ b/smash/web/templates/subjects/index.html @@ -98,7 +98,7 @@ obj.html('<select ><option value selected="selected">----------</option></select>'); $.get("{% url 'web.api.locations' %}", function (data) { $.each(data.locations, function (index, location) { - $('select', obj).append( '<option value="' + location.id + '">' + location.name + '</option>'); + $('select', obj).append('<option value="' + location.id + '">' + location.name + '</option>'); }); }); }); @@ -107,6 +107,7 @@ var table = $('#table').DataTable({ serverSide: true, processing: true, + defaultContent: "<button>Click!</button>", ajax: "{% url 'web.api.subjects' list_type %}", columns: [ {"data": "nd_number"}, @@ -116,9 +117,22 @@ {"data": "default_location"}, {"data": "dead"}, {"data": "resigned"}, - {"data": "postponed"} - ] + {"data": "postponed"}, + {"data": null}, + ], + columnDefs: [{ + "targets": 8, + "data": "id", + "defaultContent": '<a href="#" type="button" class="btn btn-block btn-default">Edit</a>' + }] }); + + $('#table tbody').on('click', 'a', function () { + var data = table.row($(this).parents('tr')).data(); + var url = "{% url 'web.views.subject_edit' 12345 %}".replace(/12345/, data.id.toString()); + window.location.href = url; + }); + // Apply the search table.columns().every(function () { var that = this; @@ -138,7 +152,7 @@ } }); }); - $('#table_filter').css("display","none"); + $('#table_filter').css("display", "none"); }); </script>