{% load i18n %}
{% load static %}
{% load comments %}
{% load extra_filters %}
{% load attachments_tags %}

<td colspan="13" style="padding:10px;">
	<div class="caserunDetail">
		<div class="caserunInfo">
			<div class="container" style="min-height:190px;">
				<h4 style="padding-bottom:3px;">Comments</h4>
				{% if perms.django_comments.add_comment %}
				<form class="update_form" method="POST">
					<table border="0" cellpadding="0" cellspacing="0" width="100%">
						{% get_comment_form for execution as comment_form %}
						<tr>
							<td>
								{{ comment_form.comment }}
								{{ comment_form.content_type }}
								{{ comment_form.object_pk }}
								{{ comment_form.timestamp }}
								{{ comment_form.security_hash }}
							</td>
						</tr>
						<tr>
							<td style="padding:5px 9px 10px 9px;">
								<input type="hidden" name="type" value="html" />
								<input type="hidden" name="field" value="status" />
								<input type="hidden" name="case_id" value="{{ execution.case_id }}" />
								<input type="hidden" name="assignee" value="{{ execution.assignee_id }}" />
								<input type="hidden" name="tested_by" value="{{ execution.tested_by_id }}" />
								<input type="hidden" name="value" value="" />
								{% if perms.testruns.change_testexecution %}
								{% for status in execution_status %}
								<input type="submit" class="btn btn_{{ status.name.lower }} btn_status js-status-button" title="{{ status.name }}" value="" crs_id="{{ status.pk }}" {% ifequal status.pk execution.status_id %}disabled="True"{% endifequal %} data-formvalue="{{ status.pk }}" />
								{% endfor %}
								{% endif %}
								<input type="submit" class="submit-post" value="Submit">
							</td>
						</tr>
					</table>
				</form>
				{% endif %}
				<h4 class="borderB">Comments History ({{ comments_count }}):
				{% ifequal comments_count 0 %}
                                <span>[ <a id="showText" href="javascript:void(0);">{% trans "Show All" %}</a> ]</span>
				{% else %}
                                <span>[ <a id="showText" class="js-show-comments" data-param="comment{{ execution.pk }}" href="javascript:void(0);">{% trans "Show All" %}</a> ]</span>
				{% endifequal %}
				</h4>
				<ul class="comment" id="comment{{ execution.pk }}" style="display:none;">
					{% for comment in execution_comments %}
					<li>
						<span>#{{ forloop.counter }}</span>
						<span>{{ comment.user.username }}</span>
						<span>{{ comment.submit_date }}</span>
						<div>
						{{ comment.comment|urlize|linebreaksbr }}
						<br>
						{% if perms.comments.can_moderate and comment.user.pk == request.user.pk %}
						<form action="{% url "comments-delete" %}" method="post" class="form_comment" style="display:inline;">
							<input type="hidden" name="comment_id" value="{{ comment.pk }}" />
							<input type="hidden" name="object_pk" value="{{ execution.case_id }}" />
							<input class='commentdelete sprites' value='' type='submit' title="Remove Comment" />
						</form>
						{% endif %}
						</div>
					</li>
					{% endfor %}
				</ul>
			</div>
			<div style="padding: 5px 9px 15px 18px;">
				<h4>{% trans "Test Execution Information" %}</h4>
                                <div><span class="detail_title"><span class="detail_title">{% trans "Run Date" %}:</span>{{ execution.close_date }}</div>
                                <div><span class="detail_title">{% trans "Build" %}:</span>{{ execution.build }} <span class="detail_title marginLeft">{% trans "Text Version" %}:</span>{{ execution.case_text_version }}</div>
			</div>
			<div class="container">
                            <h4 class="borderB">{% trans "bug" %}
					<span>
                                            <a href="javascript:void(0);" title="File" class="js-file-caserun-bug" data-params='[{{ execution.run_id }}, {{ execution.case_id }}, {{ execution.pk }}]'>{% trans "Report" %}</a>&nbsp;|&nbsp;
						{% if perms.testcases.add_bug %}
                                                <a href="javascript:void(0);" title="Add" class="js-add-caserun-bug" data-params='[{{ execution.run_id }}, {{ execution.case_id }}, {{ execution.pk }}]'>{% trans "Add" %}</a>
						{% endif %} ]
					</span>
				</h4>
				<ul class="ul-no-format">
					{% for bug_id, bugs in grouped_case_bugs %}
						<li id="bug_item">
							<table cellpadding="3" cellspacing="0" border="0">
								<tr>
									<td><a href="{{ bugs.0.get_full_url }}">{{ bug_id }}</a></td>
								<td>
								{% for bug in bugs %}
								    {% if bug.case_run_id %}
                                                                    <span class="grey">{% trans "From Run" %}</span><a href="{% url "testruns-get" bug.case_run.run_id %}">{{ bug.case_run.run_id }}</a>
								        {% if bug.case_run_id == execution.pk and perms.testcases.delete_bug %}
								        <a id="bug_{{ bug_id }}_{{ bug.case_id }}_{{ bug.case_run_id }}" href="javascript:void(0);" title="Remove This Bug" class="js-remove-caserun-bug" data-params='[{{ execution.run.pk }}, "{{ bug.bug_id }}", {{ bug.case_id }}, {{ bug.case_run_id }}]'>
                                                                            <img width="9" height="9" title="remove this bug" src="{% static 'images/remove_small.png' %}">
                                                                        </a>
								        {% endif %}
								    {% else %}
                                                                    <span class="grey">{% trans "From Case" %}</span>
								        <a href="{% url "testcases-get" bug.case_id %}">{{ bug.case_id }}</a>
								    {% endif %}
								{% endfor %}
								</td>
								</tr>
							</table>
						</li>
					{% empty %}
                                        <li class="grey">{% trans "No bug found" %}</li>
					{% endfor %}
				</ul>
			</div>
			<div class="container" style="min-height:50px;">
				{% if execution_logs %}
				<h4 class="borderB">Change Log<span>[ <a href="javascript:void(0);" class="js-show-changelog" data-param="changeLog{{ execution.pk }}">Show All</a> ]</span></h4>
				<ul id="changeLog{{execution.pk}}" style="display:none;">
					{% for log in execution_logs %}
					<li><span>{{ log.history_date }}</span><span>{{ log.history_user }}</span><br />{{ log.history_change_reason }}</li>
					{% endfor %}
				</ul>
				{% else %}
				<h4 class="borderB">Change Log</h4>
                                <ul><li class="grey">{% trans "No log recorded" %}.</li></ul>
				{% endif %}
			</div>
		</div>
		<div class="caseInfo">
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr>
					<td colspan='3'>
						<div class="container">
							<h4>Text</h4>
							<div class="content">{{ test_case_text|markdown2html }}</div>
						</div>
					</td>
				</tr>
			</table>
			<div class="container">
				<table cellpadding="0" cellspacing="0" border="0" width="98%;" style="margin:0 auto;">
					<tr>
						<td>
							<h4 class="borderB">
								Attachments
							</h4>
							<ul class="ul-no-format">
                                                                {% get_attachments_for test_case as attachments_list %}
								{% for attachment in attachments_list %}
								<li>
                                                                    <a href="{{ attachment.attachment_file.url }}">{{ attachment.filename }}</a>
								</li>
								{% empty %}
                                                                <li class="grey">{% trans "No attachment found" %}</li>
								{% endfor %}
							</ul>
							{% if perms.attachments.add_attachment %}
                                                            {% url 'testruns-get' execution.run_id as testrun_url %}
                                                            {% attachment_form execution.case next=testrun_url %}
							{% endif %}
						</td>
						<td style="width:24px;"></td>
						<td>
                                                    <h4 class="borderB">{% trans "Component" %}</h4>
							<ul class="ul-no-format">
								{% for component in test_case.component.all %}
								<li>{{ component.name }}</li>
								{% empty %}
                                                                <li class="grey">{% trans "No component found" %}</li>
								{% endfor %}
							</ul>
						</td>
						<td style="width:24px;"></td>
						<td>
							<h4 class="borderB">Tag:</h4>
							<ul class="ul-no-format">
								{% for tag in test_case.tag.all %}
								<li>{{ tag }}</li>
								{% empty %}
                                                                <li class="grey">{% trans "No tag found" %}</li>
								{% endfor %}
							</ul>
						</td>
					</tr>
				</table>
			</div>
			<div class="container">
				<table cellpadding="0" cellspacing="0" border="0" width="98%;" style="margin:0 auto;">
					<tr>
						<td>
                                                    <h4 class="borderB">{% trans "Test Link" %} <span>[<a href="javascript:void(0);" class="js-add-testlog" data-params='[{{ execution.case_id }}, {{ execution.pk }}]'>{% trans "Add" %}</a>]</span></h4>
							<div class="content">
									<ul class="ul-format">
										{% for link in execution.links %}
										<li>
											<a href="{{ link.url }}" target="_blank" title="{{ link.url }}">{{ link.name|escape }}</a>
											<span class="grey">{{ link.created_on|date:"N d, Y" }}</span>
											<a href="javascript:void(0);" class="js-remove-testlog" data-param="{{ link.pk }}">
												<img title="Remove this log" src="{% static 'images/remove_small.png' %}" />
											</a>
										</li>
										{% endfor %}
									</ul>
							 </div>
							</td>
						</tr>
					</table>
			</div>
		</div>
		<div class="clear"></div>
	</div>
</td>
