  [% META title="Outreach &raquo; Edit Follow-up" %]

<!-- BEGIN [% template.name %] -->
  [% # PROCESS dumper.tt dump = followup_data %]
  [% # PROCESS dumper.tt dump = followup_options %]

  <h2>Edit Outreach follow-up [
      [% request_data.patient_case.patient.last_name  | upper %],
      [% request_data.patient_case.patient.first_name | ucfirst %]
      [% PROCESS site/lab_number.tt data = request_data %]
    ]
  </h2>

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

	[% addcss =	[
			'validationEngine.jquery.css'
			'smoothness/jquery-ui-1.8.4.custom.css' # for DatePicker
		]
	%]

  [% INCLUDE site/snippets/help.tt file = 'editfollowup' %]

    <p class="info indent">select ONE item only - see help for details</p>

  [% # 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>

	[% INCLUDE site/js/validationEngine.tt %]
	<script type="text/javascript">
		$(document).ready(function() {
			$("#followup").validationEngine()
		})
	</script>

    [% outreach_followup_dfv_js %]

    <form method="post" action="[% app_url %]/outreach/do_edit_followup/[% request_data.id %]"
      name="followup" id="followup" [% outreach_followup_onsubmit %]>
    <table class="indent">
      <tr>
        <td class="label">Follow up:</td>
        <td>
          <select name="followup_option_id">
            <option value="">--select one--</option>
            [% PROCESS outreach/option_list.tt; # creates 'option_list', an array
                # of followup_options sorted by 'position' column:
                FOREACH o IN option_list; # INCLUDE dumper.tt dump = o;
                #NEXT IF followup_data.pack_sent # allowing change to duration now
                #  AND option.match('month') # no point changing duration if already sent
                #  AND followup_data.followup_option_id != id # allow existing
            %]
            <option value="[% o.id %]"
                [% 'selected' IF followup_data.followup_option_id == o.id %]>
              [% o.label %]
            </option>
          [% END %]
          </select>
          [% error_followup_option_id %]
        </td>
      </tr>

      [% IF followup_data.appointment_date %]
        <tr>
            <td class="label">Clinic date:</td>
            <td>
                <input type="text" name="appointment_date" id="appointment_date"
                    value="[% followup_data.appointment_date.strftime('%d.%b.%Y') %]"
                    class="validate[ajax[ajaxDate]] datepicker" />
            </td>
        </tr>
      [% END %]

      <tr>
        <td class="label">Pack due:</td>
        <td>
          [% IF followup_data.pack_due;
                USE date; # allow change to pack_due date only if after today:
                IF followup_data.pack_due.epoch <= date.now; # read-only:
                    followup_data.pack_due.strftime('%a %d.%b.%Y');
                ELSE;
            %]
            <input type="text" value="[% followup_data.pack_due.strftime('%d.%b.%Y') %]"
                name="pack_due" id="pack_due" class="validate[ajax[ajaxDate]] datepicker" />
            [% END; END %]
        </td>
      </tr>

      <tr>
        <td class="label">Pack sent:</td>
        <td>[% followup_data.pack_sent.strftime('%a %d.%b.%Y') %]</td>
      </tr>

      [% IF followup_data.return_due %]
      <tr>
        <td class="label">Return due:</td>
        <td>
          <input type="text" name="return_due" id="return_due"
            class="validate[ajax[ajaxDate]] datepicker"
            value="[% followup_data.return_due.strftime('%d.%b.%Y') %]" />
          [% error_return_due %]
        </td>
      </tr>
      [% END %]

      <tr class="borderless">
        <td colspan="2" align="center">
          [% site.html.back_button %]
          [% site.html.submit %]
          [% site.html.reset %]
        </td>
      </tr>
  </table>
<!-- END [% template.name %] -->
