{% extends "base.html" %}

{% block title %}
	&raquo; Sites &raquo; {{site.code}} {{site.name}}
{% endblock %}

{% block style %}
	<style>
		label {
			width: 11em;
			float: left;
		}
	</style>
{% endblock %}

{% block nav %}
	<a href="/sites">Sites</a> &raquo;
	<a href="/sites/{{site.id}}">{{site.code}} {{site.name}}</a> &raquo; Edit
{% endblock %}

{% block content %}
	{% if request.method == "GET" and request.values.delete %}
		<form method="post" action="/sites/{{site.id}}/edit">
			<fieldset>
				<legend>
					Are you sure you want to delete this site and any associated snags?
				</legend>
				<input type="submit" name="delete" value="delete"> 
				<a href="/sites/{{site.id}}/edit">Cancel</a>
			</fieldset>
		</form>
	{% else %}
		<form action="/sites/{{site.id}}/edit" method="post">
			<fieldset>
				<legend>Update this site</legend>
				<label>Name</label> {{input_text('site_name', site.name, 40)}}
				<label>Code</label> {{input_text('code', site.code)}}
				<input name="update" type="submit" value="Update">
			</fieldset>
		</form>

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


		<form action="/sites/{{site.id}}/edit" method="post">
			<fieldset>
				<legend>Insert a gas supply</legend>
				<label>Name</label> {{input_text('name')}}
				<fieldset>
						<legend>Start Date</legend>
						{{input_date('start')}}
				</fieldset>
				<label>Meter Serial Number</label> {{input_text('msn')}}
				<label>Correction Factor</label> {{input_text('correction_factor', '1.02264')}}
				<label>MPRN</label> {{input_text('mprn', '')}}
				<label>Exit Zone</label>
				<select name="g_exit_zone_id">
					{% for g_exit_zone in g_exit_zones %}
						{{input_option('g_exit_zone_id', g_exit_zone.id, g_exit_zone.code)}}
					{% endfor %}
				</select>
				<label>Contract</label>
				<select name="g_contract_id">
					{% for g_contract in g_contracts %}
						{{ input_option('g_contract_id', g_contract.id, g_contract.name)}}
					{% endfor %}
				</select>
				<label>Account</label> {{input_text('account')}}
				<label>Units</label>
				<select name="g_unit_id">
					{% for g_unit in g_units %}
						{{ input_option(
								'g_unit_id', g_unit.id, g_unit.code + ' ' + g_unit.description)}}
					{% endfor %}
				</select>
				<label>Reading Frequency</label>
				<select name="g_reading_frequency_id">
					{% for g_reading_frequency in g_reading_frequencies %}
						{{ input_option(
								'g_reading_frequency_id', g_reading_frequency.id,
								g_reading_frequency.code + ' ' + g_reading_frequency.description)}}
					{% endfor %}
				</select>
				<input name="insert_gas" type="submit" value="Insert">
			</fieldset>
		</form>
	{% endif %}
{% endblock %}
