{% load i18n %}
<form id="id_tag_form">
	<table class="list" cellpadding="0" cellspacing="0" border="0">
		<thead>
			<tr>
                            <th>{% trans "Tag" %}</th>
                            <th>{% trans "Plans" %}</th>
                            <th>{% trans "Cases" %}</th>
                            <th>{% trans "Runs" %}</th>
                            <th>{% trans "Action" %}</th>
			</tr>
		</thead>
		<tbody id='tag' count='{{tags.count}}'>
			{% for tag in tags %}
			<tr class="{% cycle 'even' 'odd'%} js-one-tag" data-params='["{{ api_module}}", {{ object.pk }}, "{{ tag }}"]'>
				<td><span class="tagvalue">{{ tag }}</span></td>
				<td><a href="{% url "plans-search" %}?tag__name__in={{ tag }}" title="{{ tag.num_plans }} plans tagged {{ tag }}">{{ tag.num_plans }}</a></td>
				<td><a href="{% url "testcases-search" %}?tag__name__in={{ tag }}"  title="{{ tag.num_cases }} cases tagged {{ tag }}">{{ tag.num_cases }}</a></td>
				<td><a href="{% url "testruns-search" %}?tag__name__in={{ tag }}"  title="{{ tag.num_runs }} runs tagged {{ tag }}">{{ tag.num_runs }}</a></td>
				{% if perms.testplans.delete_testplantag %}
                                <td><a href="#tag" class="remove js-remove-tag" title="remove tag">{% trans "Remove" %}</a></td>
				{% else %}
                                <td><span class="disabled grey">{% trans "Remove" %}</span></td>
				{% endif %}
			</tr>
			{% empty %}
			<tr>
                            <td colspan="5" align="center"><span class="grey">{% trans "No tag found" %}</span></td>
			</tr>
			{% endfor %}
			<tr>
				<td colspan="5" align="center" style="padding:0">
				{% if perms.testplans.add_testplantag %}
				<div class="addtag">
                                    <span class="tit">{% trans "Add Tag" %}</span>
						<input id="id_tags" type="text" name="tags" data-params='["{{ api_module}}", {{ object.pk }}]'>
                                                <a href="#tag" class="addlink" id="js-add-tag">{% trans "Add" %}</a>
						<div id="id_tags_autocomplete"></div>
				</div>
				{% endif %}
				</td>
			</tr>
		</tbody>
	</table>
</form>
<script type="text/javascript">
$('.js-remove-tag').bind('click', function() {
    var tag = $(this).parents('.js-one-tag');
    removeTag($('#tag')[0], $(tag).data('params'));
});

$('#js-add-tag').bind('click', function() {
    addTag($('#tag')[0]);
});
</script>
