[% META
    title  = 'Haematological Malignancy Research Network &raquo; Edit Referral Data'    
%]

<!-- BEGIN [% component.name %] -->
    [% # PROCESS dumper.tt dump = data %]
    
	[% addcss =	[
			'validationEngine.jquery.css' # for validationEngine
			'smoothness/jquery-ui-1.8.4.custom.css' # for DatePicker
		]
	%]
	
	[% # PROCESS site/js/jquery.tt # already loaded in html_wrapper %]
	<script type="text/javascript" src="/js/jquery-ui-1.8.4.custom.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $('.datepicker').datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy',
            });
        });
	</script>

    [% IF not_using_validationEngine_jquery # then use 'basic' jquery val %]
    <script type="text/javascript" src="/js/jquery.validate.js"></script>
    <script type="text/javascript"> 
	    $(document).ready(function() { 
	      $("#referral").validate({ 
            rules: {
				[% c.jquery_validation_profile("${profile_name}").join(',') %]
            },
          });
        });
    </script>
    <script type="text/javascript">
        // override default message:
        jQuery.extend(jQuery.validator.messages, {
            remote:   "&#171; invalid entry",
            required: "&#171; required field",
        });
    </script>
    [% ELSE; INCLUDE site/js/validationEngine.tt %]
	<script type="text/javascript">
		$(document).ready(function() {
			$("#referral").validationEngine()
		})
	</script>
    [% END %]
   
    <h3>Edit referral data:</h3>    

    [% IF dfv_errors %]
        <p class="error">[% c.cfg('msg').dfv_errors %]</p>
    [% END %]

    <form method="post" name="referral" id="referral" [% # hmrn_treatment_onsubmit # using jQuery val %]
        action="[% app_url %]/hmrn_data/do_edit_referral/[% data.request_id %]/[% data.id %]">

	  <table class="indent">	
		<tr>
			<td class="label">Referral date:</td>
			<td class="content">
				<input type="text" name="referral_date" class="validate[ajax[ajaxDate]] datepicker"
					id="referral_date" value="[% data.referral_date.strftime('%d.%b.%Y') %]" size="10" />
				[% error_referral_date %]
			</td>
		</tr>
		<tr>
			<td class="label">Referral type:</td>
			<td class="content">
				<select name="referral_type_id" id="referral_type_id" class="validate[required]">
					<option value=""></option>
					[% FOREACH key IN data.maps.referral_types.keys.sort %]
                    <option value="[% data.maps.referral_types.$key %]"
					[% 'selected' IF data.maps.referral_types.$key == data.referral_type_id %]>
                        [% key %]
					</option>
					[% END %]
				</select>
				[% error_referral_type_id %]
			</td>
		</tr>
		<tr>
			<td class="label">Referred from:</td>
			<td class="content">
				<select name="from_source_id" id="from_source_id" class="validate[required]">
					<option value=""></option>
					[% FOREACH key IN data.maps.referral_sources.keys.sort %]
                    <option value="[% data.maps.referral_sources.$key %]"
					[% 'selected' IF data.maps.referral_sources.$key == data.from_source_id %]>
                        [% key %]
					</option>
					[% END %]
				</select>
				[% error_from_source_id %]
			</td>
		</tr>
		<tr>
			<td class="label">Referred to:</td>
			<td class="content">
				<select name="to_source_id" id="to_source_id" class="validate[required]">
					<option value=""></option>
					[% FOREACH key IN data.maps.referral_sources.keys.sort %]
                    <option value="[% data.maps.referral_sources.$key %]"
					[% 'selected' IF data.maps.referral_sources.$key == data.to_source_id %]>
                        [% key %]
					</option>
					[% END %]
				</select>
				[% error_to_source_id %]
			</td>
		</tr>
		<tr>
			<td class="label">Date first seen:</td>
			<td class="content">
				<input type="text" name="date_first_seen" class="validate[ajax[ajaxDate]] datepicker"
					id="date_first_seen" value="[% data.date_first_seen.strftime('%d.%b.%Y') %]" size="10" />
				[% error_date_first_seen %]
			</td>
		</tr>
	
		<tr class="borderless">
			<td>[% site.html.back_button %]</td>
			<td align="right">
			[% IF c.query.param('delete') %]
				<span class="title">confirm deletion (no undo possible):</span>
				<input type="checkbox" name="confirm_delete" value="1" />
				<input type="hidden" name="delete" value="1" />
				[% site.html.submit %]
			[% ELSE %]
				[% site.html.submit %]
				[% site.html.reset %]
				<a href="[% app_url %]/hmrn_data/edit_referral/[% c.param('id')
						%]/[% c.param('Id') %]?delete=1">
					<span class="highlight">delete</span>
				</a>
			[% END %]
			</td>
		</tr>
      </table>
    </form>
<!-- END [% component.name %] -->
