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

{% block subtitle %}{% trans "Add TestCase to TestRun" %}{% endblock %}

{% block custom_stylesheet %}
{% endblock %}

{% block custom_javascript %}
<script type="text/javascript" src="{% static 'js/testrun_actions.js' %}"></script>
<script type="text/javascript" src="{% static 'js/testcase_actions.js' %}"></script>
<script type="text/javascript" src="{% static 'js/testplan_actions.js' %}"></script>
<script type="text/javascript">
Nitrate.Utils.after_page_load(Nitrate.TestRuns.AssignCase.on_load);
</script>
{% endblock %}

{% block contents %}
<div id="content">
	<h2 id="display_title">Add TestCase(s) to <a href="{% url "testruns-get" test_run.pk %}">{{ test_run.summary }}</a></h2>
	<table class="runsDetail" border="0" width="66%" cellspacing="0" cellpadding="0">
		<tr class="cell">
                    <td class="lab">{% trans "Build" %}</td>
			<td id="display_build">{{ test_run.build }}</td>
		</tr>
		<tr class="cell">
                    <td class="lab">{% trans "Manager" %}</td>
			<td class="name"><a href="{% url "tcms-profile" test_run.manager.username %}">{{ test_run.manager.username }}</a></td>
		</tr>
		<tr class="cell">
                    <td class="lab">{% trans "Test Plan" %}</td>
			<td><a href="{% url 'test_plan_url_short' test_run.plan.pk %}">{{ test_run.plan.name }}</a></td>
                        <td class="lab">{% trans "All Confirmed Cases" %}</td>
			<td><a>{{ confirmed_cases_count }}</a></td>
		</tr>
		<tr class="cell">
			<td></td>
			<td></td>
                        <td class="lab"><span>{% trans "Test Cases in Run" %}</span></td>
			<td>{{ executions_count }}</td>
		</tr>
	</table>
	<form action="{% url "add-cases-to-run" test_run.pk %}" method="post">
		<div class="Detailform border-1" id="testcases_selected">
			<div class="mixbar">
                            <span class="tit"><b>{% trans "Cases in this Run" %}: {{ executions_count }}</b></span>
				<input id="id_checkbox_plan_sortkey" type="checkbox" name="_use_plan_sortkey" />
                                <label for="id_checkbox_plan_sortkey" title="Uncheck it will set the sortkey to 0">{% trans "Use the sortkey stored in plan" %}</label>
				<input type="submit" value="Update" title="Update the cases in this run"/>
				<input type="reset" value="Reset" title="Reset to the original cases "/>
				<span class="right-action">	
                                    <a class="helplink js-how-assign-case" id="" title="view the help information about assigning case">{% trans "How to Assign case?" %}</a>
				</span>
			</div>
			<div class="Detailform system_info border-1" id="help_assign" style="display:none">
				<div class="Detailform-variety_1">
					<p>
                                        {% trans "The table below list all the confirmed test cases of plan" %} {{ test_run.plan }}, {% trans "check the checkbox to add cases into test run. Remember to update at last" %}. 
						<span class="right-action">
							<a href="#" class="js-close-how-assign" >X</a>
						</span>
					</p>
				</div>
			</div>
			<table id="id_table_cases" class="list" cellpadding="0" cellspacing="0" border="0" >
				<thead>
					<tr>
						<th class="nosort" align="left" width="20px"><input id="id_check_all_button" type="checkbox" /></th>
						<th class="nosort" align="left" width="20px"></th>
                                                <th class="sortcol widthID" align="left" width="50px">{% trans "ID" %}</th>
                                                <th class="sortcol">{% trans "Test Case Summary" %}</th>
                                                <th class="sortcol" width="130">{% trans "Author" %}</th>
                                                <th class="sortcol" width="150">{% trans "Created Date" %}</th>
                                                <th class="sortcol" width="150">{% trans "Category" %}</th>
                                                <th class="sortcol"  width="70">{% trans "Priority" %}</th>
                                                <th class="sortcol"  width="70">{% trans "Selected" %}</th>
					</tr>
				</thead>
				<tbody>
					{% for test_case in confirmed_cases %}
					<tr id="row_{{ forloop.counter }}" class="{% cycle 'odd' 'even' %} selection_row">
						<td align="left">
							{# Hide the check box when it is in the exist_case_runs, and remove it from form submitation #}
							<input type="checkbox" name="case"  {% if test_case.case in exist_execution_ids %}value="{{ test_case.case }}" disabled="true"  checked="true"{% else %}value="{{ test_case.case }}"{% endif %} />
						</td>
						<td>
							<a id="blind_link_{{ forloop.counter }}" class="blind_link js-toggle-button" data-param="{{ forloop.counter }}" href="javascript:void(0);">
								<img id="blind_icon_{{ forloop.counter }}" src="{% static 'images/t1.gif' %}" border="0" alt="">
							</a>
						</td>
						<td>
							<a href="{% url "testcases-get" test_case.case %}">{{ test_case.case }}</a>
						</td>
						<td class="js-case-summary" data-param="{{ forloop.counter }}" >
							<a id="link_{{ forloop.counter }}" class="blind_title_link" href="{% url "testcases-get" test_case.case %}">
								{{ test_case.case__summary }}
							</a>
						</td>
						<td>{{ test_case.case__author__username }}</td>
						<td>{{ test_case.case__create_date }}</td>
						<td>{{ test_case.case__category__name }}</td>
						<td>{{ test_case.case__priority__value }}</td>
						<td></td>
					</tr>
					<tr class="hide"  id="hidenRow_{{ forloop.counter }}" class="Detailform border-1" style="display: none;">
						<td colspan="9" id="id_case_text_{{ forloop.counter }}">
							<div class="ajax_loading"></div>
						</td>
					</tr>
					{% endfor %}
				</tbody>
			</table>
		</div>
	</form>
</div>
{% endblock %}
