{% extends "base.html" %}

{% block title %}
	&raquo; Supplies &raquo; {{supply.id}} &raquo; Edit
{% endblock %}

{% block nav %}
	<a href="/e/supplies">Supplies</a> &raquo; 
	<a href="/e/supplies/{{supply.id}}">{{supply.id}}</a> &raquo; Edit
{% endblock %}

{% block content %}

	{% if request.method == 'GET' and request.values.delete %}	

		<form method="post">
			<fieldset>						
				<legend>Are you sure you want to delete this supply?</legend>
				<input type="submit" name="delete" value="Delete">
				<a class="btn" href="/e/supplies/{{supply.id}}/edit">Cancel</a>
			</fieldset>
		</form>

	{% else %}

		<form method="post" action="/e/supplies/{{supply.id}}/edit">
			<fieldset>
				<legend>Update this supply</legend>
				<label>Name</label> {{input_text('name', supply.name)}}
				<label>Source</label>
				<select name="source_id">
					{% for source in sources %}
						{{input_option('source_id', source.id, source.code, supply.source.id)}}
					{% endfor %}
				</select>
				<label>Generator Type (if source is 'gen' or 'gen-net')</label>
				<select name="generator_type_id">
					{% for generator_type in generator_types %}
						{{input_option(
							'generator_type_id', generator_type.id, generator_type.code,
							supply.generator_type.id)}}
					{% endfor %}
				</select>
					</div>
				</div>
				<label>GSP Group</label>
				<select name="gsp_group_id">
					{% for gsp_group in gsp_groups %}
						{{input_option(
							'gsp_group_id', gsp_group.id,
							gsp_group.code + ' '  + gsp_group.description, supply.gsp_group.id)}}
					{% endfor %}
				</select>
				<input type="submit" value="Update">
			</fieldset>
		</form>

		<form action="/e/supplies/{{supply.id}}/edit">
			<fieldset>
				<legend>Delete this supply</legend>
				<input type="submit" name="delete" value="Delete">
			</fieldset>
		</form>					

		<form method="post" action="/e/supplies/{{supply.id}}/edit">
			<fieldset>
				<legend>Insert a new era</legend>
				<label>Start date</label> {{input_date('start', None)}}
				<input type="submit" name="insert_era" value="Insert">
			</fieldset>
		</form>

		<table>
			<caption>Existing Eras</caption>
			<thead>
				<tr>
					<th>Start date</th>
					<th>Finish date</th>
					<th>Import Mpan Core</th>
					<th>Export Mpan Core</th>
				</tr>
			</thead>
			<tbody>
			{% for era in eras %}
				<tr>
					<td>{{era.start_date|hh_format}}</td>
					<td>{{era.finish_date|hh_format}}</td>
					<td>
						{% if era.imp_mpan_core %}
							{{era.imp_mpan_core}}
						{% endif %}
					</td>
					<td>
						{% if era.exp_mpan_core %}
							{{era.exp_mpan_core}}
						{% endif %}
					</td>
				</tr>
			{% endfor %}
			</tbody>
		</table>

	{% endif %}

{% endblock %}
