<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:tal="http://xml.zope.org/namespaces/tal"
	xmlns:metal="http://xml.zope.org/namespaces/metal"
	xmlns:i18n="http://xml.zope.org/namespaces/i18n"
	i18n:domain="plone">
<head><title></title></head>
<body>
	<metal:view_macro define-macro="view">
		<table class="listing nosort">

	</table>
</metal:view_macro>

	<metal:edit_macro define-macro="edit">
		<metal:use use-macro="field_macro | context/widgets/field/macros/edit">
			<metal:body_macro fill-slot="widget_body"
				tal:define="
					fieldname python: field.getName();
					field python: context.Schema()[fieldname];
					accessor python: field.getAccessor(context);
					current_field_value accessor;
					sort_on python:(('title', 'nocase', 'asc'),);
					ReferenceDefinitions python:sequence.sort([p.getObject() for p in context.bika_setup_catalog(portal_type='ReferenceDefinition') \
					                            if p.inactive_state=='active'], sort_on);
					BlankDefinitions python: [r for r in ReferenceDefinitions if r['Blank']];
					ControlDefinitions python: [r for r in ReferenceDefinitions if not r['Blank']];
					types context/getAnalysisTypes;
					num_positions request/NoOfPositions | python:0;
					num_positions python:int(num_positions);
					display_rows python:widget.get_template_rows(num_positions, current_field_value);
					analyses python:[s.UID() for s in context.getService()];
					hasblanks python:len(BlankDefinitions) > 0;
					hascontrols python:len(ControlDefinitions) > 0;">
	<dl class="portalMessage warn" tal:condition="python:not hasblanks or not hascontrols">
		<dt>Alert</dt>
		<dd>
			<p tal:omit-tag="" tal:condition="python: not hasblanks and hascontrols" i18n:translate="">No Reference Definitions for Blanks available.<br/>To add a Blank in this Worksheet Template, create a Reference Definition for a Blank sample first.</p>
			<p tal:omit-tag="" tal:condition="python: not hascontrols and hasblanks" i18n:translate="">No Reference Definitions for Controls available.<br/>To add a Control in this Worksheet Template, create a Reference Definition for a Control sample first.</p>
			<p tal:omit-tag="" tal:condition="python: not hascontrols and not hasblanks" i18n:translate="">No ReferenceDefinitions for Controls nor Blanks available.<br/>To add a Control or Blank in this Worksheet Template, create a Reference Definition first.</p>
		</dd>
	</dl>
	<label i18n:translate="">Number of Positions</label>
	<input name="NoOfPositions"
		size="3"
		value=""
		tal:attributes="value request/NoOfPositions | python:len(display_rows)"/>
	<input type="submit" name="form.button.more"
		class="context"
		i18n:attributes="value"
		value="Reset" />

	<table
		summary="Worksheet template form"
		class="listing nosort"
		cellpadding="0" cellspacing="0">

	<tr>
		<th i18n:translate="">Pos</th>
		<th i18n:translate="">Analysis Type</th>
		<th i18n:translate="">Reference Definition</th>
		<th i18n:translate="">Dup of</th>
	</tr>

	<tr tal:repeat="row display_rows">

	<td>
		<span tal:content="row/pos"/>
		<input  type="hidden"
			tal:attributes="value row/pos"
			name="Layout.pos:records:ignore_empty"/>
	</td>

	<td>
		<select name="Layout.type:records:ignore_empty"
			class="analysis_type"
			tal:attributes="pos row/pos;">
		<tal:item
			tal:define="vocab types"
			tal:repeat="item vocab">
			<tal:selected_type
				tal:condition="python:item == row['type']"
				tal:define="global selected_type row/type"/>
			<option selected="selected"
				tal:define="this_selected python:item == row['type']"
				tal:attributes="
					value item;
					selected this_selected"
				tal:content="python:context.translate(item, default=vocab.getValue(item))"
				tal:condition="python:(item=='b' and hasblanks) or (item=='c' and hascontrols) or (item!='b' and item!='c')"></option>
		</tal:item>
		</select>
	</td>

	<td>
	  <!-- dropdown for Blank references -->
		<select name="Layout.blank_ref:records:ignore_empty"
			tal:attributes="
				style python: 'display:inline' if (selected_type == 'b' and hasblanks) else 'display:none';
				class string:blank_ref_dropdown;
				pos string:${row/pos};">
		<tal:item tal:repeat="ref BlankDefinitions">
			<option
				tal:attributes="
					value ref/UID;
					selected python:'blank_ref' in row and row['blank_ref'] == ref.UID() and 'selected' or ''"
				tal:content="ref/Title"></option>
		</tal:item>
		</select>
	  <!-- dropdown for Control references -->
		<select name="Layout.control_ref:records:ignore_empty"
			tal:attributes="
				style python: 'display:inline' if (selected_type == 'c' and hascontrols) else 'display:none';
				class string:control_ref_dropdown;
				pos string:${row/pos};">
		<tal:item tal:repeat="ref ControlDefinitions">
			<option
				tal:attributes="
					value ref/UID;
					selected python:'control_ref' in row and row['control_ref'] == ref.UID() and 'selected' or ''"
				tal:content="ref/Title"></option>
		</tal:item>
		</select>
	</td>
	<!-- Dropdown for Duplicate Analysis -->
	<td>
		<div id="" tal:define="num_rows repeat/row/length">
			<select name="Layout.dup:records:ignore_empty"
				tal:attributes="
					style python: selected_type == 'd' and 'display:inline;;' or 'display:none;;';
					class string:duplicate_analysis_dropdown;
					pos string:${row/pos};">
			<tal:item tal:repeat="i python:[x+1 for x in range(num_rows) if display_rows[x]['type'] == 'a']">
				<option
					tal:condition="python:i != repeat['row'].number()"
					tal:define="this_selected python:str(row.get('dup', '')) == str(i) and 'selected' or ''"
					tal:attributes="value i; selected this_selected"
					tal:content="i"></option>
			</tal:item>
			</select>
		</div>
	</td>

</tr>
</table>

	</metal:body_macro>
</metal:use>
</metal:edit_macro>
</body>
</html>
