{% extends "tcms_base.html" %}
{% load static %}
{% load i18n %}
{% block subtitle %}{% trans "Add cases from other plans" %}{% endblock %}

{% block custom_javascript %}
<script src="{% static 'jquery/dist/jquery.min.js' %}"></script>
<script src="{% static 'js/jsonrpc.js' %}"></script>
<script src="{% static 'js/utils.js' %}"></script>

<script type="text/javascript" src="{% static 'datatables.net/js/jquery.dataTables.min.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">
	<h2>{{ test_plan.name }}</h2>

	<div class="Detailform border-1">
		<div class="Detailform-variety_0">
                    <div class="grey tit">{% trans "Search cases to add into this test plan." %}</div>
			<form action="{% url "plan-search-cases-for-link" test_plan.pk %}" method="post">
				<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">
                                                                    {% trans "Quick Search" %}
								</a>
							</li>
							<li {% if search_mode|default:'quick' == 'normal'  %}class="profile_tab_active"{%endif%} id="normal_tab">
								<a href="#" id="normal_search_cases">
                                                                    {% trans "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_normal_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.pk %}" method="post">
			{% 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" /></th>
                                                <th align="left" class="widthID" >{% trans "ID" %}</th>
                                                <th align="left" width="20%" >{% trans "Summary" %}</th>
						<th align="left" width="10%" >{% trans "Author" %}</th>
						<th align="left" width="10%" >{% trans "Default Tester" %}</th>
						<th align="left" width="5%" >{% trans "Priority" %}</th>
						<th align="left" width="13%" >{% trans "Created" %}</th>
						<th align="left" width="10%" >{% trans "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.pk }}"></td>
						<td><a href="{% url "testcases-get" test_case.pk %}">{{ test_case.pk }}</a></td>
						<td valign="top" >{{ test_case.summary }}</td>
						<td valign="top" ><a href="{% url "tcms-profile" test_case.author.username %}">{{ test_case.author.username }}</a></td>
						<td valign="top" >
                                                {% if test_case.default_tester %}
                                                    <a href="{% url "tcms-profile" test_case.default_tester.username %}">{{ test_case.default_tester.username }}</a>
                                                {% endif %}
                                                </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 type="submit" value="Add selected cases" />
					</div>
				</div>
				{% else %}
				<div class="middle-list">
                                    <label class="grey">{% trans "No test cases found." %}</label>
				</div>
				{% endif %}
			</form>
		</div>
	</div>
</div>
{% endblock %}
