{% extends "admin/base_site.html" %}

{% block title %}{% endblock %}

{% load markup %}

{% block content_title %}
<a class="brand" href="{% url 'admin:signalbox_reply_change' reply.id %}">User responses</a>

{% endblock %}

{% block content %}


<div class="line">

<div class="unit lastUnit size4of7">

        {% if reply.observation.created_by_script.is_clinical_data %}
        <div class="alert alert-warning">
            Clinical data
        </div>
        {% endif %}

        {% if not reply.complete %}
        <div class="alert alert-warning">
            Alert: Reply was not completed in full</div>
        {% endif %}


        <p> Questionnaire: <a href="{% url 'admin:ask_asker_change' reply.asker.id %}">{{reply.asker}}</a></p>


        {% if reply.computed_scores %}
        <h3>Auto-scored answers</h3>

        <table class="table">
            <tr>
                    <tr><th>Scoresheet</th><th>Score</th><th>Messages</th>  </tr>
                    {% for i in reply.computed_scores %}
                    <tr>
                        <td><a href="{% url 'admin:signalbox_scoresheet_change' i.scoresheet.id %}">{{i.scoresheet}}</a></td>
                        <td>{{i.score}}</td>
                        <td>{{i.message}}</td>
                    </tr>
                    {% endfor %}
            </tr>
        </table>

        {% endif %}

        <h3>Raw responses</h3>

        <p>
            <form class="form">
            <label class="checkbox">
                <input type="checkbox" onclick="$('.unanswered').toggle();">Hide questions not attempted</label>
        </form>

        {% if reply.answer_set.all %}
            <table class="table">
            <tr>
            <th>Variable name</th>
            <th>Page</th>
            <th>Label</th>
            <th width=20%>Response</th>
            </tr>
            {% for a in reply.answer_set.all %}
            <tr class="{% if not a.reply %}unanswered{% endif %}">
                <td><code>{{a.variable_name}}</code></td>
                <td>{{a.page.index}}</td>
                <td>
                    <div class="" id="lab_{{a.id}}">
                        {%if a.question.text%}<pre>{{a.question.text|capfirst}}</pre>{% endif %}

                        <span class="hide" id="choices_{{a.id}}">
                            <pre>{{a.possible_choices_json}}</pre>
                        </span>
                    </div>
                </td>
                <td>
                    {% if not a.reply %}<code>Not Answered</code>{% endif %}

                    {% if a.question.show_as_image_data_url %}
                        <img src="{{a.answer}}">
                    {% else %}
                        {% if a.choice_label %}
                            {{a.choice_label}}
                            {% if a.possible_choices_json %}
                            <a class="" id="link{{a.id}}" href="#" onclick="$('#choices_{{a.id}}').show(); return false;">
                                <i class="icon-info-sign"></i>
                            </a>
                            {% endif %}
                        {% endif %}
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
            </table>
        {% else %}
            No answers given in this reply.
        {% endif %}

        <p>Answers last modified: {{reply.last_submit}}</p>
        <p>Token: {{reply.token}}</p>
</div>
</div>
{% endblock %}

