  [% META title = 'Admin &raquo; Screening Terms' -%]
<!-- BEGIN [% template.name %] -->
	[% # PROCESS dumper.tt dump = screen_categories %]

    [% PROCESS admin/system_nav.tt page = 'screen_term' %]

    [% screening_terms_dfv_js %]

	<h2 align="center">Screen Terms</h2>

    [% IF dfv_errors %]
        <p class="error">[% c.config('msg').dfv_errors %]</p>
        [% IF error_description # a 2-col unique key %]
            <span class="red indent">
                [% c.messages('admin').screen_term.not_unique %]
            </span>
        [% END %]
    [% END %]

    <p class="title">
		[% div_name = 'new'; INCLUDE site/snippets/toggleview.tt %]
		Add new entry
	</p>

	<div class="[% dfv_errors ? 'visible' : 'itemhidden' %]" id="[% div_name %]">
		<form method="post" action="[% app_url %]/admin/screen_term/update"
        [% screening_terms_onsubmit %] name="screening_term" id="screening_term">

		<div class="indent">
			<table>
				<tr>
					<td class="label">Description:</td>
					<td class="content">
                        [% # now uses 2-col unique key so can't validate by AJAX
                            # PROCESS site/ajax_input.tt field = 'description'
							# id = 'screen_description' %]
                        <input type="text" name="description" size="20" />
						[% error_description %]
					</td>
				</tr>
				<tr>
					<td class="label">Category:</td>
					<td class="content">
						<select name="category_id" [% site.html.onfocus %]>
							<option value="">&nbsp;</option>
							[% FOREACH entry IN screen_categories;
                                NEXT UNLESS entry.is_active.match('yes') %]
							<option value="[% entry.id %]">[% entry.name %]</option>
							[% END %]
						</select>
						[% error_category_id %]
					</td>
				</tr>
				<tr>
					<td class="label">Active:</td>
					<td class="content">
						<select name="active"  [% site.html.onfocus %]>
						[% FOREACH option IN ['yes', 'no'] %]
						 <option value="[% option %]">[% option %]</option>
						[% END %]
						</select>
                        [% error_active %]
					</td>
				</tr>
			</table>

			<p class="indent">[% site.html.submit %]</p>
		</div>
		</form>
	</div>

	<hr />

	<form method="get" action="[% app_url %]/admin/screen_term"
        name="screens" id="screens">
		<p class="classname">Restrict by screening category (optional):
		<select name="category_id" onChange="submit()">
			<option value="">-- none --</option>
			[% FOREACH entry IN screen_categories;
                # NEXT UNLESS entry.is_active.match('yes') %]
			<option value="[% entry.id %]"
              [% 'selected' IF entry.id == c.query.param('category_id') %]>
              [% entry.name %]
            </option>
			[% END %]
		</select>
		[% # site.html.submit %]
		</p>
	</form>

    [% IF screening_list.size %]
	<div class="[% dfv_errors ? 'itemhidden' : 'visible' %]">
		[% PROCESS site/page_count.tt %]
		<table>
			<tr>
				<th></th>
				<th>
					<a href="[% app_url %]/admin/screen_term">Description</a>
				</th>
				<th>
					<a href="[% url_with_path %]?sort_by=category.name">Category</a>
				</th>
				<th>Active</th>
			</tr>

			[% FOREACH item IN screening_list %]
			<tr>
				<td>
                    [% IF cgi_pager; cgi_pager.first_pos_displayed + loop.count - 1;
                        ELSE; loop.count; END %]
				</td>
				<td>
					<input type="text" size="50" name="description" value="[% item.description | html %]"
						[% site.html.disabled %] />
				</td>
				<td>
					<select name="category_id" [% site.html.disabled %]>
						[% FOREACH entry IN screen_categories %]
						 <option value="[% entry.id %]" [%
                                'selected' IF entry.id == item.category_id %]>
							[% entry.name %]
						</option>
						[% END %]
					</select>
				</td>
				<td>
					<select name="active"  [% site.html.disabled %]>
					[% FOREACH option IN ['yes', 'no'] %]
						 <option value="[% option %]" [% 'selected' IF option == item.active %]>
							[% option %]
						</option>
					[% END %]
					</select>
				</td>
				<td align="center">
					<a href="[% app_url %]/admin/screen_term/edit/[% item.id %]">Edit</a>
				</td>
			</tr>
			[% END %]

		</table>
	</div>
	[% PROCESS site/cgi_pager.tt %]
    [% END %]
<!-- END [% template.name %] -->
