{% extends "tcms_base.html" %}

{% load extra_filters %}
{% load static %}

{% block subtitle %}Test case - {{ test_case.case_id }}: {{ test_case.summary }}{% endblock %}

{% block custom_stylesheet %}
{% endblock %}

{% block custom_javascript %}
<script type="text/javascript" src="{% static "js/lib/jquery.dataTables.js" %}"></script>
<script type="text/javascript" src="{% static "js/lib/dataTables.numHTML.js" %}"></script>
<script type="text/javascript" src="{% static "js/testcase_actions.js" %}"></script>
<script type="text/javascript" src="{% static "js/nitrate.attachments.js" %}"></script>
<script type="text/javascript" src="{% static "js/nitrate.toggledetail.js" %}"></script>
<script type="text/javascript">
Nitrate.Utils.after_page_load(Nitrate.TestCases.Details.on_load);
Nitrate.Utils.after_page_load(Nitrate.Attachments.on_load);

Nitrate.TestCases.Instance = {
	pk: {{ test_case.pk }},
	product_id: {{ test_case.category.product.pk }},
	category_id: {{ test_case.category_id }},
	author_id: {{ test_case.author_id }},
}
</script>
{% endblock %}

{% block content_type %}
	<input type="hidden" name="content_type" value="testcases.testcase" />
	<input type="hidden" name="object_pk" value="{{ test_case.pk }}" />
	<input type="hidden" name="name" value="{{ test_case.summary }}" />
	<input type="hidden" name="description" value="{{ test_case.notes }}" />
{% endblock %}

{% block contents %}
<div id="content">
	{% if test_plan %}
	<div id="tcms_values" class="hidden">
		<input id="value_product_id" type="hidden" name="product_id" value="{{ test_plan.product_id }}" />
		<input id="id_case_id" type="hidden" name="case_id" value="{{ test_case.case_id }}" />
	</div>
	<div class="sprites crumble">
		<a href="{% url "nitrate-index" %}">Home</a>
		>> Plan: <a href="{{ test_plan.get_absolute_url }}">{{ test_plan.plan_id }}:{{ test_plan.name }}</a>
		>>Case: {{ test_case.case_id }}: {{ test_case.summary }}
	</div>
	{% else %}
	<div class="sprites crumble">
		<a href="{% url "nitrate-index" %}">Home</a>
		&gt;&gt; <a href="{% url "cases-search" %}">Search Case</a>
		&gt;&gt; Case: {{ test_case.case_id }}: {{ test_case.summary }}
	</div>
	<div id="tcms_values" class="hidden">
		<input id="id_case_id" type="hidden" name="case_id" value="{{ test_case.case_id }}" />
	</div>
	{% endif %}
	<div class="control">
		{% if perms.testcases.change_testcase %}
		<span id="id_buttons"><input id="btn_edit" type="button" value="Edit" data-link="{% url "case-edit" test_case.case_id %}?from_plan={{ test_plan.plan_id }}"/></span>
		{% endif %}
		{% if perms.testcases.add_testcaseplan %}
		<span id=""><input type="button" id="btn_clone" value="Clone case" data-link="{% url "cases-clone" %}?from_plan={{ test_plan.plan_id }}&case={{ test_case.case_id }}"/></span>
		{% endif %}
		{% if test_plan %}
		<span class="right-action">
			<a href="{{ test_plan.get_absolute_url }}">Back to Test Plan</a>
		</span>
		{% endif %}
	</div>
	<h2 id="display_title">{{ test_case.summary }}</h2>

	<div class="listinfo_content">
		<fieldset class="no-border">
			<div class="leftlistinfo">
				<div class="listinfo">
					<div class="title grey">Default Tester&nbsp;:</div>
					<div class="name">
						{% if test_case.default_tester %}
						<span id="display_default_tester"><a href="{% url "user-profile" test_case.default_tester.username %}">{{ test_case.default_tester.email }}</a></span>
						{% else %}
						<span >No default tester</span>
						{% endif %}
					</div>
				</div>
				<div class="listinfo">
					<div class="title grey">Product&nbsp;:</div>
					<div class="name">
						<span>{{ test_case.category.product }}</span>
					</div>
				</div>
				<div class="listinfo">
					<div class="title grey">Category&nbsp;:</div>
					<div class="name">
						<span id="display_category">{{ test_case.category }}</span>
					</div>
				</div>
				<div class="listinfo">
					<div class="title grey">Estimated Time&nbsp;:</div>
					<div id="display_estimated_time" class="name">{{ test_case.estimated_time|timedelta2string }}</div>
				</div>
				<div class="listinfo">
					<div class="title grey">Priority&nbsp;:</div>
					<div class="name"><span id="display_priority">{{ test_case.priority }}</span></div>
				</div>
				<div class="listinfo">
					<div class="title grey">Status&nbsp;:</div>
					<div class="name"><span id="display_priority">{{ test_case.case_status }}</span></div>
				</div>
				<div class="listinfo">
					<div class="title grey"><span>Alias&nbsp;:</span></div>
					<div class="name {% if not test_case.alias %}grey{% endif %}">
						<span id="display_script">{{ test_case.alias|default:'None' }}</span>
					</div>
				</div>

			</div>
			<div class="rightlistinfo">
				<div class="listinfo">
					<div class="title grey">Author&nbsp;:</div>
					<span class="name">
						<a href="{% url "user-profile" test_case.author.username %}">
							{{ test_case.author.email }}
						</a>
					</span>
				</div>
				<div class="listinfo">
					<div class="title grey">Created&nbsp;:</div>
					<div class="name">{{ test_case.create_date }}</div>
				</div>
				<div class="listinfo">
					<div class="title grey">Automated&nbsp;:</div>
					<div class="name">{{ test_case.get_is_automated_status }}</div>
				</div>
				<div class="listinfo">
					<div class="title grey">Requirement&nbsp;:</div>
					<div class="name {% if not test_case.requirement %}grey{% endif %}">
						<span id="display_requirement">{{ test_case.requirement|default:'None' }}</span>
					</div>
				</div>
				<div class="listinfo">
					<div class="title grey">Script&nbsp;:</div>
					<div class="name {% if not test_case.script %}grey{% endif %}">
						<span id="display_script">{{ test_case.script|default:'None' }}</span>
					</div>
				</div>

				<div class="listinfo">
					<div class="title grey"><span>Arguments&nbsp;:</span></div>
					<div class="name {% if not test_case.arguments %}grey{% endif %}">
						<span id="display_script">{{ test_case.arguments|default:'None' }}</span>
					</div>
				</div>

				<div class="listinfo">
					<div class="title grey"><span>Reference Link&nbsp;:</span></div>
					<div class="name {% if not test_case.extra_link %}grey{% endif %}">
						<span id="display_script">
						{% if test_case.extra_link %}
							<a href="{{ test_case.extra_link }}">{{ test_case.extra_link }}</a>
						{% else %}
						None
						{% endif %}
						</span>
					</div>
				</div>
			</div>
			<div class="clear"></div>
			<div class="listinfo">
				<div class="title grey">Notes&nbsp;:</div>
				<div class="name" style="max-width:800px;"><span id="display_priority">{{ test_case.notes|urlize|linebreaksbr }}</span></div>
			</div>
		</fieldset>
	</div>

	<div class="Detailform border-1">
		<ul id="contentTab" class="content_tab">
			<li id="tab_document" class="tab tab_focus">
				<a href="#document" title="document">Document</a>
			</li>
			<li id="tab_attachment" class="tab">
				<a href="#attachment" title="attachment">Attachments (<span id='attachment_count'>{{ test_case.attachments.count }}</span>)</a>
			</li>
			<li id="tab_case_plan" class="tab">
				<a href="#plan" title="plan">Test plans (<span id='plan_count'>{{ test_case.plan.count }}</span>)</a>
			</li>
			<li id="tab_component" class="tab">
				<a href="#component" title="component">Components (<span id='component_count'>{{ test_case.component.count }}</span>)</a>
			</li>
			<li id="tab_case_tag" class="tab">
				<a href="#tag" title="tag">Tags (<span id='tag_count'>{{ test_case.tag.count }}</span>)</a>
			</li>
			<li id="tab_case_issues" class="tab">
				<a href="#issues" title="issues">Issues (<span id='case_issues_count'>{{ test_case.issues.count }}</span>)</a>
			</li>
			<li id="tab_case_run" class="tab">
				<a href="#case_run" title="case_run">Case Runs (<span id='case_run_count'>{{ test_case_runs.count }}</span>)</a>
			</li>
			<li id="tab_case_log" class="tab">
				<a href="#log" title="log">Change Logs</a>
			</li>
		</ul>
		<div  id="document" class="Detailform-variety_2 tab_list" style="clear:left;">
			{% include "case/get_text.html" %}
		</div>
		<div id="attachment" class="tab_list" style="display:none">
			{% if perms.management.add_testattachment %}
			<div class="mixbar">
				<span class="tit">Add attachment</span>
				<a href="{% url "case-attachment" test_case.pk %}?from_plan={{ test_plan.pk }}" class="addlink">add</a>
			</div>
			{% endif %}
			{% include 'plan/attachments_table.html' with attachments=test_case.attachments.all from='from_case' object_id=test_case.pk %}
		</div>
		<div id="plan" style="display:none" class="tab_list">
			{% include "case/get_plan.html" %}
		</div>
		<div id="component" style="display:none" class="tab_list">
			{% include "case/get_component.html" %}
		</div>
		<div id="tag" class="tab_list" style="display:none">
			<div class="ajax_loading"></div>
		</div>
		<div id="issues" class="tab_list" style="display:none">
			{% include "case/get_issues.html" %}
		</div>
		 <div id="case_run" class="tab_list" style="display:none">
			{% include "case/get_case_run.html" %}
		</div>
		<div id="log" class="tab_list" style="display:none">
			{% include "logs_table.html" %}
		</div>
	</div>
</div>
{% endblock %}
