{% load static %}
{% if not is_ajax %}
<ul id="env_area">
	{% for run_env_value in test_run.env_value.select_related.all %}
	<li>
		<form class="js-run-env" id="id_form_value_{{ run_env_value.pk }}">
			<span class="lab">
				<input type="hidden" value="{{ run_env_value.property_id }}" name="env_property_id"/>
				<input type="hidden" value="{{ run_env_value.pk }}" name="current_run_env"/>
		{{ run_env_value.property }}:

				<span id="id_env_value_{{ run_env_value.pk }}" style="display:">{{ run_env_value.value }}</span>
				<select style="display:none" name="env_value_id" id="id_select_value_{{ run_env_value.pk }}">
					<option value="{{ run_env_value.pk }}" selected></option>
				</select>
				<input type="button" value="Submit" name="submit" id="id_submit_value_{{ run_env_value.pk }}" class="js-env-submit" style="display:none" data-params='["{{ test_run.run_id }}", "{{ run_env_value.pk }}", "id_env_value_{{ run_env_value.pk }}", "id_submit_value_{{ run_env_value.pk }}"]'/>
			</span>
			<span class="action_property">
				{% if perms.testruns.change_tcmsenvrunvaluemap %}
					<a href="javascript:void(0)" class="js-edit-property" data-params='["id_env_value_{{ run_env_value.pk }}", "id_select_value_{{ run_env_value.pk }}", "id_submit_value_{{ run_env_value.pk }}"]'>
						<img src="{% static "images/icon_changelink.gif" %}" title="Edit this value"/>
					</a>
				{% endif %}
				{% if perms.testruns.delete_tcmsenvrunvaluemap %}
					<a href="javascript:void(0)">
						<img src="{% static "images/remove_small.png" %}" title="Remove this property" class="js-remove-property"
							 data-param="{{ test_run.run_id }}" />
					</a>
				{% endif %}
			</span>
		</form>
	</li>
	{% endfor %}
</ul>
{% if perms.testruns.add_tcmsenvrunvaluemap %}
<div>
	<a class="addlink js-add-property" href="javascript:void(0)" data-params='["{{ test_run.run_id }}", "{{env_group.id}}"]'>Add Property</a>
</div>
{% endif %}
{% for env_group in testplan.env_group.all %}
<input type="hidden" name="env_group_id" value="{{ env_group.id }}"/>
{% endfor%}
{% else %}
{% for run_env_value in test_run.env_value.select_related.all %}
<li>
	<form class="js-run-env" id="id_form_value_{{ run_env_value.pk }}">
		<span class="lab">
			<input type="hidden" value="{{ run_env_value.property_id }}" name="env_property_id"/>
			<input type="hidden" value="{{ run_env_value.pk }}" name="current_run_env"/>
	{{ run_env_value.property }}:

			<span id="id_env_value_{{ run_env_value.pk }}" style="display:">{{ run_env_value.value }}</span>
			<select style="display:none" name="env_value_id" id="id_select_value_{{ run_env_value.pk }}">
				<option value="{{ run_env_value.pk }}" selected></option>
			</select>
			<input type="button" value="Submit" name="submit" id="id_submit_value_{{ run_env_value.pk }}" class="js-env-submit" style="display:none" data-params='["{{ test_run.run_id }}", "{{ run_env_value.pk }}", "id_env_value_{{ run_env_value.pk }}", "id_submit_value_{{ run_env_value.pk }}"]'/>
		</span>
		<span class="action_property">
			{% if perms.testruns.change_tcmsenvrunvaluemap %}
				<a href="javascript:void(0)" class="js-edit-property" data-params='["id_env_value_{{ run_env_value.pk }}", "id_select_value_{{ run_env_value.pk }}", "id_submit_value_{{ run_env_value.pk }}"]'>
					<img src="{% static "images/icon_changelink.gif" %}" title="Edit this value"/>
				</a>
			{% endif %}
			{% if perms.testruns.delete_tcmsenvrunvaluemap %}
				<a href="javascript:void(0)">
					<img src="{% static "images/remove_small.png" %}" title="Remove this property" class="js-remove-property"
						 data-param="{{ test_run.run_id }}" />
				</a>
			{% endif %}
		</span>
	</form>
</li>
{% endfor %}
{% endif %}

<div id="addEnvPropertyDialog" title="Add Environment Property" style="display: none">
	<table style="width: 100%">
		<tr><td><label for="propertiesSelect">Property</label></td></tr>
		<tr><td><select id="propertiesSelect" style="width: 100%"></select></td></tr>
		<tr><td>&nbsp;</td></tr>
		<tr><td><label for="propertyValuesSelect">Value</label></td></tr>
		<tr><td><select id="propertyValuesSelect" style="width: 100%"></select></td></tr>
	</table>
</div>
