  [% META title = 'Admin &raquo; Edit Report Notification Contact' -%]

<!-- BEGIN [% template.name %] -->
  [% # PROCESS dumper.tt dump = c.stash.errs %]
  [% # PROCESS dumper.tt dump = data # hashref not object %]
  [% # PROCESS dumper.tt dump = departments %]

	[% PROCESS site/autosuggest.tt varname = 'hospital' %]

    [% email_contacts_dfv_js %]

	[% # PROCESS admin/misc_nav.tt page = 'error-codes' %]

	[% meta_data = c.get_meta_data('ReportNotification') %]

  <h2 align="center">Edit Report Notification Contact</h2>

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

	[% IF data.type.match('organisation') %]
		<div class="warning">
			*** if changing type from organisation to hospital to you will need
			to replace the referral source entry with the required hospital ***
		</div >
	[% END %]
    [% IF dfv_errors %]
    <dl>
        <dt class="error">[% c.cfg('msg').dfv_errors %]</dt>
        [% IF error_name %]
            <dd>Display name [% error_name %]</dd>[% END %]
        [% IF error_type %]
            <dd>Type [% error_type %]</dd>[% END %]
        [% IF error_department_id %]
            <dd>Department [% error_department_id %]</dd>[% END %]
        [% IF error_id_type %]
            <dd>Referral source [% error_id_type %]</dd>[% END %]
        [% IF error_status %]
            <dd>Status [% error_status %]</dd>[% END %]
        [% IF error_contact_address %]
            <dd>Email [% error_contact_address %]</dd>[% END %]
        [% IF error_active %]
            <dd>Active [% error_active %]</dd>[% END %]
    </dl>
    [% END %]

    <form method="post" action="[% app_url %]/config/report-notifications/update/[% data.id %]"
		[% email_contact_onsubmit %] name="report-notification" id="report-notification">

    <table>
      <tr>
        <th [% IF error_name %]class="error"[% END %]>Display name</th>
      	<th [% IF error_type %]class="error"[% END %]>Type</th>
		[% UNLESS data.type.match('referrer') # not applicable %]
			<th [% IF error_department_id %]class="error"[% END %]>Department</th>
		[% END %]
		[% label = data.type.match('referrer') ? 'Identifier' : 'Referral Source' %]
        <th [% IF error_id_type %]class="error"[% END %]>[% label %]</th>
      	<th [% IF error_status %]class="error"[% END %]>Status</th>
      	<th [% IF error_contact_address %]class="error"[% END %]>Email</th>
      	<th [% IF error_is_active %]class="error"[% END %]>Active</th>
      </tr>
      <tr>
        <td>
          <input type="text" name="name" value="[% data.name | html %]" size="25" />
        </td>
        <td>
			[% IF data.type.match('referrer'); # can't change type %]
				<input type="text" value="referrer" name="type" readonly="readonly" />
			[% ELSE %]
      		<select name="type">
      			<option value=""></option>
              [% FOREACH item IN meta_data.column('type').check_in;
				NEXT IF item.match('referrer') %]
              <option value="[% item %]" [% 'selected' IF item == data.type %]>
                [% item %]</option>
			 [% END %]
			[% END %]
            </select>
        </td>
		[% UNLESS data.type.match('referrer') # not applicable %]
        <td>
      		<select name="department_id">
      			<option value=""></option>
                [% FOREACH d IN departments.keys.sort; #
                    # INCLUDE dumper.tt dump = [d, departments.$d] %]
                  <option value="[% departments.$d %]"
						  [% 'selected' IF departments.$d == data.department_id %]>
                    [% d %]</option>
                [% END %]
            </select>
        </td>
		[% END %]
		[% IF data.type.match('referrer') %]
			<td>
				<input type="text" name="identifier"
					value="[% data.identifier | html %]" />
			</td>
		[% ELSE # load referral source search function: %]
        <td class="search_bar">
          <input style="width: 300px" type="text" id="location_name" name="_display_name"
            value="[% data.location %] "/>
          <input type="hidden" id="source_id" name="referral_source_id" />
          <input type="hidden" name="_referral_source_id"
            value="[% data.identifier %]" />
        </td>
		[% END %]
        <td>
      		<select name="status">
      			<option value=""></option>
              [% FOREACH item IN meta_data.column('status').check_in %]
              <option value="[% item %]" [% 'selected' IF item == data.status %]>
                [% item %]</option>
			 [% END %]
            </select>
        </td>
        <td>
          <input type="text" name="contact_address" size="30"
              value="[% data.contact_address | html %]" />
        </td>
        <td>
          <select name="is_active">
          [% FOREACH option IN ['yes', 'no'] %]
            <option value="[% option %]" [% 'selected' IF option == data.is_active %]>
              [% option %]
            </option>
			    [% END %]
          </select>
        </td>
        <td>
         [% site.html.submit %]
        </td>
      </tr>
    </table>

    </form>

    <p>[% site.html.back_button %]</p>
<!-- END [% template.name %] -->
