From 13203c936746f6fd59440fa43ead8a2fac1651cd Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 31 Oct 2017 11:41:02 +0100
Subject: [PATCH] edit button in list of subjects is standard 'a' tag

---
 smash/web/static/js/subject.js          | 11 ++++-------
 smash/web/templates/subjects/index.html |  3 +--
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/smash/web/static/js/subject.js b/smash/web/static/js/subject.js
index bfee2f14..1cc539c9 100644
--- a/smash/web/static/js/subject.js
+++ b/smash/web/static/js/subject.js
@@ -13,7 +13,7 @@ function createColumn(dataType, name, filter, visible, renderFunction) {
     };
 }
 
-function getColumns(type) {
+function getColumns(type, getSubjectEditUrl) {
     var result = [];
     // don't confuse end user
     // result.push(createColumn("id", "Id", null, false));
@@ -29,7 +29,9 @@ function getColumns(type) {
     result.push(createColumn("information_sent", "Info sent", "yes_no_filter", true));
     result.push(createColumn("type", "Type", "type_filter", true));
     result.push(createColumn("id", "Edit", null, true, function (data, type, row, meta) {
-        return '<a href="#" type="button" class="btn btn-block btn-default">Edit</a>';
+        var url = getSubjectEditUrl(row.id.toString());
+
+        return '<a href="' + url + '" type="button" class="btn btn-block btn-default">Edit</a>';
     }));
     for (var i = 1; i <= 8; i++) {
         var renderFunction = (function () {
@@ -207,11 +209,6 @@ function createSubjectsTable(params) {
             order: [[0, 'desc']]
         });
 
-        $('#table tbody').on('click', 'a', function () {
-            var data = table.row($(this).parents('tr')).data();
-            window.location.href = getSubjectEditUrl(data.id.toString());
-        });
-
         // Apply the search
         table.columns().every(function () {
             var that = this;
diff --git a/smash/web/templates/subjects/index.html b/smash/web/templates/subjects/index.html
index 5d1b7148..7f97eb86 100644
--- a/smash/web/templates/subjects/index.html
+++ b/smash/web/templates/subjects/index.html
@@ -53,13 +53,12 @@
         {% endfor %}
 
         createSubjectsTable({
-            getSubjectEditUrl: getSubjectEditUrl,
             worker_locations: worker_locations,
             subject_types_url: "{% url 'web.api.subject_types' %}",
             locations_url: "{% url 'web.api.locations' %}",
             subjects_url: "{% url 'web.api.subjects' list_type %}",
             tableElement: document.getElementById("table"),
-            columns: getColumns("{{ list_type }}"),
+            columns: getColumns("{{ list_type }}", getSubjectEditUrl),
             checkboxesElement: document.getElementById("visible-column-checkboxes")
         })
         ;
-- 
GitLab