{% extends "tcms_base.html" %}
{% load i18n %}
{% load static %}
{% load extra_filters %}
{% load attachments_tags %}
{% block subtitle %}{{ object.name }}{% endblock %}

{% block custom_stylesheet %}
<link rel="stylesheet" type="text/css" href="{% static 'style/print.css' %}" media="print">
<link rel="stylesheet" type="text/css" href="{% static 'style/patternfly_override.css' %}">
{% endblock %}
{% block custom_javascript %}
<script type="text/javascript" src="{% static 'js/lib/tablednd.js' %}"></script>
<script type="text/javascript" src="{% static 'js/testplan_actions.js' %}"></script>
<script type="text/javascript" src="{% static 'js/testcase_actions.js' %}"></script>
<script type="text/javascript">
Nitrate.Utils.after_page_load(Nitrate.TestPlans.Details.on_load);

Nitrate.TestPlans.Instance = {
	pk: {{ object.pk }},
	fields: {
		name: '{{ object.name }}',
		product_id: {{ object.product_id }},
		author_id: {{ object.author_id }},
		parent: {{ object.parent.pk|default:'null' }}
	},
}
</script>

<!-- temporary workaround so we can convert TestPlans.TreeView.filter to JSON RPC -->
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'js/jsonrpc.js' %}"></script>
{% endblock %}

{% block contents %}
<div id="content">
	<input id="id_plan_id" type="hidden" name="plan_id" value="{{ object.pk }}">
	<div class="control">
		<span id="id_buttons" class="button">
			<input id="btn_edit" type="button" value="{% trans "Edit Plan" %}" title="{% trans "Edit test plan" %}" data-param="{% url 'plan-edit' object.pk %}" {% if perms.testplans.change_testplan %}{% else%}disabled{% endif %}>
			<input id="btn_clone" type="button" value="{% trans "Clone Plan" %}" title="{% trans "Clone this plan to other product" %}" data-params='["{% url "plans-clone" %}", {{ object.pk }}]' {% if perms.testplans.add_testplan %}{% else %}disabled{% endif %}>
			<input id="btn_print" type="button" value="{% trans "Print Plan" %}" title="{% trans "Print Plan" %}" data-params='["{% url "plans-printable" %}", {{ object.pk }}]'>
			<input id="btn_delete" type="button" value="{% trans "Delete Plan" %}" title="{% trans "Delete test plan" %}" data-param="{% url 'admin:testplans_testplan_delete' object.pk %}" {% if perms.testplans.delete_testplan %}{% else %}disabled{% endif %}>
		</span>
	</div>
	<h2 id="display_title" class="{% ifequal object.is_active 0 %}line-through{% endifequal %}">
		{{ object.name }}
	</h2>
	<div class="listinfo_content">
		<div class="leftlistinfo">
			<div class="listinfo">
				<div class="title grey">{% trans "Author" %}&nbsp;:</div>
				<div id="display_author"  class="name " > <a href="{% url "tcms-profile" object.author.username %}">{{ object.author.username }}</a></div>
			</div>
			<div class="listinfo">
				<div class="title grey">{% trans "Product" %}&nbsp;:</div>
				<div id="display_product"  class="name "><a href="{% url "plans-search" %}?product={{ object.product_id }}" title="Search plans of {{ object.product }} ">{{ object.product }}</a></div>
			</div>
			<div class="listinfo">
				<div class="title grey">{% trans "Version" %}&nbsp;:</div>
				<div id="display_product_version"  class="name ">{{ object.product_version.value }}</div>
			</div>
			<div class="listinfo">
				<div class="title grey">{% trans "Plan Type" %}&nbsp;:</div>
				<div id="display_type"  class="name ">{{ object.type.name }}</div>
			</div>
		 </div>
		<div class="rightlistinfo">
			<div class="listinfo">
				<div class="title grey">{% trans "Reference Link" %}&nbsp;:</div>
				<div class="name">
					{% if object.extra_link %}
					<a href="{{ object.extra_link }}">{{ object.extra_link }}</a>
					{% else %}
					{% trans "None" %}
					{% endif %}
				</div>
			</div>
			<div class="listinfo">
				<div class="title grey">{% trans "Create Time" %}&nbsp;:</div>
				<div class="name ">{{object.create_date}}</div>
				
			</div>
			<div class="listinfo">
				<div class="title grey">{% trans "Parent" %}&nbsp;:</div>
				<div class="name ">
				{% if object.parent.pk %}
					<a href="{% url 'test_plan_url_short' object.parent.pk %}">{{ object.parent.pk }}</a>
				{% else %}
					{% trans "None" %}
				{% endif %}
				</div>
			</div>
			<div class="listinfo">
				<div class="title"><a href="/admin/testplans/testplan/{{ object.pk }}/history/">{% trans "View Edit History" %}</a></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
	<div id="plan_detail">
		<div class="Detailform border-1">
			<ul id="contentTab" class="content_tab">
				<li id="tab_document" class="tab">
					<a href="#document" title="document">{% trans "Document" %}</a>
				</li>
				<li id="tab_testcases" class="tab tab_focus">
					<a href="#testcases" title="testcases">{% trans "Cases" %} (<span id='run_case_count' class="js-testcases-count">{{ run_case_count }}</span>/<span id='case_count'>{{ object.case.count }}</span>)</a>
				</li>
				<li id="tab_reviewcases" class="tab">
					<a href="#reviewcases" title="reviewcases">{% trans "Reviewing Cases" %} (<span id='review_case_count' class="js-reviewcases-count">{{ review_case_count }}</span>)</a>
				</li>
				<li id="tab_testruns"  class="tab">
					<a href="#testruns" title="testruns">{% trans "Runs" %} (<span id='run_count'>{{ object.run.count }}</span>)</a>
				</li>
				<li id="tab_attachment" class="tab">
					<a href="#attachment" title="attachment">{% trans "Attachments" %} (<span id='attachment_count'>{% attachments_count object %}</span>)</a>
				</li>
				<li id="tab_tag" class="tab">
					<a href="#tag" title="tag">{% trans "Tags" %} (<span id='tag_count'>{{ object.tag.count }}</span>)</a>
				</li>
				<li id="tab_treeview" class="tab">
					<a href="#treeview" title="treeview">{% trans "Tree View" %}</a>
				</li>
			</ul>
			<div id="document" class="tab_list" style="display:none">
                            <div class="listinfo_doc_content">
                                <div id="display_summary" class="listinfo_doc markdown-text">
                                {% if object.text %}
                                    {{ object.text|markdown2html }}
                                {% else %}
                                    <span style="color: #666">{% trans "The document for this plan hasn't been written yet." %}</span>
                                {% endif %}
                                </div>
                            </div>
			</div>
			<div id="attachment" class="tab_list" style="display:none">
				{% include "plan/get_attachments.html" %}
			</div>
			<div id="testruns" class="tab_list" style="display:none;">
                            <!--
                                todo:
                                a temporary solution until we can convert the entire page to Patternfly
                                and figure out a way to re-use the search forms!
                             -->
                            <iframe src="{% url 'testruns-search' %}?nonav=1&plan={{ object.pk }}"
                                    width="100%" height="1000px" scrolling="auto" frameBorder="0">
                            </iframe>
			</div>
			<div id="treeview" class="tab_list" style="display:none;">
				{% include "plan/get_treeview.html" with test_plan=object %}
			</div>
			<div id="reviewcases" class="tab_list" style="display:none">
				<div class="ajax_loading"></div>
			</div>
			<div id="testcases" class="tab_list">
				<div class="ajax_loading"></div>
			</div>
			<div id="tag" class="tab_list" style="display:none">
				<div class="ajax_loading"></div>
			</div>
		</div>
	</div>
</div>
{% endblock %}
