{% extends "base.html" %}

{% block title %}
	Gas Contracts &raquo; {{g_rate_script.g_contract.name}} &raquo;
 	Rate Scripts &raquo; {{g_rate_script.start_date|hh_format}} &raquo; Edit
{% endblock %}

{% block nav %}
	<a href="/g_contracts">Gas Contracts</a> &raquo;
	<a
	 		href="/g_contracts/{{g_rate_script.g_contract.id}}"
			>{{g_rate_script.g_contract.name}}</a> &raquo;
	<a
	 		href="/g_rate_scripts/{{g_rate_script.id}}"
			>Rate Script {{g_rate_script.start_date|hh_format}}</a> &raquo; Edit
{% endblock %}

{% block content %}
	{% if request.method == 'GET' and request.values.delete %}
		<div class="layer-section">
			<div class="section-content">
				<div class="section-data">
					<div class="standardForm">
						<form
								method="post"
							 	action="/g_rate_scripts/{{g_rate_script.id}}/edit">
							<fieldset>
								<legend>
									Are you sure you want to delete this rate script?
								</legend>
								<input type="submit" name="delete" value="Delete">
							</fieldset>
						</form>
						<p>
							<a href="/g_rate_scripts/{{g_rate_script.id}}/edit">Cancel</a>
						</p>
					</div>
				</div>
			</div>
		</div>
	{% else %}
		<div class="layer-section">
			<div class="section-header">
				<h2>Update Rate Script</h2>	
			</div>
			<div class="section-content">
				<div class="standardForm textWidthAuto">
					<form
							action="/g_rate_scripts/{{g_rate_script.id}}/edit"
							method="post">
						<fieldset>
							<br>
							<div class="section-data">
								<fieldset>
									<legend>Start date</legend>
									{{ input_date('start', g_rate_script.start_date) }}
								</fieldset>
							</div>
							<div class="section-data">
								<fieldset>
									<legend>Finish date</legend>
									<label>
										Ended?
										{{
											input_checkbox(
												'has_finished', g_rate_script.finish_date != None) }}
									</label>
									{{ input_date('finish', g_rate_script.finish_date) }}
								</fieldset>
							</div>
							<br>
							<div class="section-data">
								Script
								<br>
								{{ input_textarea(
									'script', g_rate_script.script, 40, 80, show_pos=True) }}
								<br>
								<input type="submit" value="Update">
								<input type="reset" value="Reset">
							</div>
						</fieldset>
					</form>
				</div>
			</div>
		</div>
		<div class="layer-section">
			<div class="section-header">
				<h2>Delete this Rate Script</h2>	
			</div>
			<div class="section-content">
				<div class="section-data">
					<form action="/g_rate_scripts/{{g_rate_script.id}}/edit">
						<fieldset>
							<input type="submit" name="delete" value="Delete">
						</fieldset>
					</form>
				</div>
			</div>
		</div>
	{% endif %}
{% endblock %}
