From 612f2ebaf519ef89dbc70fd9f54e1ca7dea7dbb2 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Mon, 7 Oct 2019 13:30:01 +0200
Subject: [PATCH] Link to edit response from virus/host detailed view

---
 src/viralhostrange/viralhostrangedb/static/css/browse.css | 2 +-
 .../viralhostrangedb/static/js/virus_or_host_detail.js    | 5 ++++-
 .../templates/viralhostrangedb/vh_detail.html             | 8 +++++++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/viralhostrange/viralhostrangedb/static/css/browse.css b/src/viralhostrange/viralhostrangedb/static/css/browse.css
index c6621312..8d0e543a 100644
--- a/src/viralhostrange/viralhostrangedb/static/css/browse.css
+++ b/src/viralhostrange/viralhostrangedb/static/css/browse.css
@@ -106,7 +106,7 @@ th.hover {
     left: 0;
     top: auto;
 }
-.popover a[href] {
+.popover a[href]:not(.allow-deco) {
     color: inherit;
 }
 .out-of-scope{
diff --git a/src/viralhostrange/viralhostrangedb/static/js/virus_or_host_detail.js b/src/viralhostrange/viralhostrangedb/static/js/virus_or_host_detail.js
index 4db643a1..1e3fa4c9 100644
--- a/src/viralhostrange/viralhostrangedb/static/js/virus_or_host_detail.js
+++ b/src/viralhostrange/viralhostrangedb/static/js/virus_or_host_detail.js
@@ -157,13 +157,16 @@ function hover_behavior(selector){
                 popover.find("a.close_cmd").on('click', function(e){
                     elt.popover('hide').popover('dispose').attr("aria-describedby",null);
                 });
+                var url=update_response.replace("000000",$(elt).attr("data-col")).replace("111111",$(elt).attr("data-row"));
                 content = $('<dl class="mb-0">'+
                     '<dt>'+gettext('Data source name')+'</dt>'+
                     '<dd data-data-source='+$(elt).attr("data-col")+'></dd>'+
                     '<dt>'+in_row_kind+'</dt>'+
                     '<dd data-row='+$(elt).attr("data-row")+'></dd>'+
                     '<dt>'+detailed_kind+'</dt>'+
-                    '<dd>'+$("#detailed_name").html()+'</dd>'
+                    '<dd>'+$("#detailed_name").html()+'</dd>'+
+                    '</dl>'+
+                    '<a class="allow-deco pull-right mb-2" href="'+url+'">'+gettext('Edit response')+' <i class="fa fa-pencil"></i></a>'
                 ).appendTo($(popover).find(".popover-body").empty());
                 $($('#grid_host thead>tr>th[data-col='+$(elt).attr("data-col")+']').html()).appendTo(
                     content.find('[data-data-source='+$(elt).attr("data-col")+']')
diff --git a/src/viralhostrange/viralhostrangedb/templates/viralhostrangedb/vh_detail.html b/src/viralhostrange/viralhostrangedb/templates/viralhostrangedb/vh_detail.html
index b2825a49..3e694e3e 100644
--- a/src/viralhostrange/viralhostrangedb/templates/viralhostrangedb/vh_detail.html
+++ b/src/viralhostrange/viralhostrangedb/templates/viralhostrangedb/vh_detail.html
@@ -66,7 +66,13 @@ var get_responses = "{% url 'viralhostrangedb-api:responses' %}?{{object|class_v
 var get_infection_ratios = "{% url 'viralhostrangedb-api:infection-ratio-detail' slug=object|class_verbose_name|lower slug_pk=object.id %}";
 var row_pks=[{% for d in data_sources%}{%if not forloop.first%},{%endif%}{{d.pk}}{%endfor%}];
 var get_virus_url = "{% url 'viralhostrangedb:virus-detail' pk='000000' %}";
-var focus_is_on_first_level_of_data={{focus_is_on_first_level_of_data|yesno:"true,false"}};
+{%if focus_is_on_first_level_of_data %}
+var update_response = "{% url 'viralhostrangedb:response-update' ds_pk='000000' virus_pk=object.id host_pk='111111' %}";
+var focus_is_on_first_level_of_data=true;
+{%else%}
+var update_response = "{% url 'viralhostrangedb:response-update' ds_pk='000000' virus_pk='111111' host_pk=object.id %}";
+var focus_is_on_first_level_of_data=false;
+{%endif%}
 var in_row_kind="{{in_row_kind}}";
 var detailed_kind="{{detailed_kind}}";
 </script>
-- 
GitLab