{% extends "tcms_base.html" %}
{% load static %}

{% block subtitle %}Add cases from other plans{% endblock %}

{% block custom_stylesheet %}
<link rel="stylesheet" type="text/css" href="{% static "style/dataTables/jquery.dataTables.css" %}" />
<link rel="stylesheet" type="text/css" href="{% static "style/dataTables/jquery.dataTables_themeroller.css" %}" />
{% endblock %}

{% block custom_javascript %}
<script type="text/javascript" src="{% static "js/lib/jquery.dataTables.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.SearchCase.on_load);
</script>
{% endblock %}

{% block contents %}
<div id="content">
	<div id="tcms_values" class="hidden">
		<input id="value_plan_id" type="hidden" name="plan_id" value="{{ test_plan.plan_id }}" />
		<input id="value_product_id" type="hidden" mame="product_id" value="{{ test_plan.product_id }}">
	</div>
	<div class="sprites crumble">
		<a href="{% url "nitrate-index" %}">Home</a>
		>> <a href="{% url "plans-all" %}?is_active=on">Planning</a>
		>> <a href="{{ test_plan.get_absolute_url }}">{{ test_plan.plan_id }}: {{ test_plan.name }}</a>
		>> Add cases from other plans
	</div>
	<h2>{{ test_plan.name }}</h2>

	<div class="Detailform border-1">
		<div class="Detailform-variety_0">
			<div class="grey tit">Search cases to add into this test plan.</div>
			<form action="{% url "plan-search-cases-for-link" test_plan.plan_id %}" method="post">{% csrf_token %}
				<fieldset class="no-border">
				<input type="hidden" name="a" value="link_cases" />
				<input type="hidden" name="action" value="search" />
				<input type="hidden" id="search_mode" name="search_mode" value="{{ search_mode|default:'quick' }}" />
				<div id="itemSearch" class="itemSearch">
					<div class="sprites crumble profile_tab">
						<ul>
							<li {% if search_mode|default:'quick' == 'quick' %}class="profile_tab_active"{%endif%} id="quick_tab">
								<a href="#" id="quick_search_cases">
										Quick Search
								</a>
							</li>
							<li {% if search_mode|default:'quick' == 'normal'  %}class="profile_tab_active"{%endif%} id="normal_tab">
								<a href="#" id="advanced_search_cases">
										Normal Search
								</a>
							</li>
						</ul>
					</div>
					<div id="tp_quick_search_cases_form" style="{% if search_mode|default:'quick' == 'normal' %}display:none;{% endif %} margin: 15px 0px 0px 0px">
						{% include "case/form/quick_search.html" %}
					</div>
					<div id="tp_advanced_search_case_form" style="{% if search_mode|default:'quick' == 'quick' %}display:none;{% endif %} margin: 15px 0px 0px 0px">
						{% include "case/form/search.html" %}
					</div>
					<div class='clear'></div>
					<div class="errors">
						{{ search_form.errors|default:quick_form.errors }}
					</div>
					<div class='clear'></div>
					<div class="bottom">
						<input type="submit" size="7" value="Search" name="" />
						<input type="reset" size="7" value="Reset" name="" />
					</div>
				</div>
			</form>
			</fieldset>
		</div>
		<form id="id_form_cases" action="{% url "plan-link-cases" test_plan.plan_id %}" method="post">{% csrf_token %}
			{% if test_cases %}
			<div class="middle-list">
				<div id="searchcase" class="mixbar">
					<input type="submit" value="Add selected cases" />
				</div>
			</div>
			<table class="list" cellpadding="0" cellspacing="0" border="0" width="100%;" id="id_table_cases">
				<thead>
					<tr>
						<th align="left" width="2%" class="nosort">
							<input id="id_checkbox_all_cases" type="checkbox" class="js-select-all" />
						</th>
						<th align="left" class="widthID">ID</th>
						<th align="left" width="20%">Summary</th>
						<th align="left" width="10%">Author</th>
						<th align="left" width="10%">Default Tester</th>
						<th align="left" width="5%">Priority</th>
						<th align="left" width="13%">Created</th>
						<th align="left" width="10%">Status</th>
					</tr>
				</thead>
				<tbody>
					{% for test_case in test_cases %}
					<tr class="{% cycle 'odd' 'even' %}">
						<td align="left"><input id="id_checkbox_case_{{ forloop.counter }}" type="checkbox" name="case" value="{{ test_case.case_id }}"></td>
						<td><a href="{% url "case-get" test_case.case_id %}">{{ test_case.case_id }}</a></td>
						<td valign="top">{{ test_case.summary }}</td>
						<td valign="top">{{ test_case.author.email }}</td>
						<td valign="top">{{ test_case.default_tester.email }}</td>
						<td valign="top">{{ test_case.priority }}</td>
						<td valign="top">{{ test_case.create_date }}</td>
						<td valign="top">{{ test_case.case_status}}</td>
					</tr>
						{% endfor %}
					</tbody>
				</table>
				<div class="middle-list">
					<div id="searchcase" class="mixbar">
						<input id="add-selected-cases" type="submit" value="Add selected cases" disabled />
					</div>
				</div>
				{% else %}
				<div class="middle-list">
					<lable class="grey">No test cases found.</label>
				</div>
				{% endif %}
			</form>
		</div>
	</div>
</div>
{% endblock %}
