<%@page import="com.ardeo.entities.autoforms.FormField"%>
<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<tiles:importAttribute /><%--This imports all tiles atributes to page --%>
<%
	FormField field=(FormField)pageContext.getAttribute("field");
%>
<%-- START LIST EDIT --%>
<c:set var="fieldNameVariable" value="<%=field.getName()%>"/>
<c:if test="${consultationNoteForm.view.note.locked eq true}">
	<c:set var="disabled" value="true"/>
</c:if>
<c:if test="${field.fieldType eq 100}">
<c:choose>
<%-- When there is no child for this list defined for the list --%>
<c:when test="${field.filterChildField eq NULL || field.filterChildField eq 0}"> 
		<c:choose>
		  <%-- Get the filtered list based on the selected master list code --%>
			<c:when test="${requestScope.ATT_ChildListId2Filter eq field.id}">
			 	<webapp:namedListSpring disabled="${disabled}" path='<%="value[" + field.getName() + "]"%>' id="<%=field.getName()%>" domain="${field.optionsMapDomain}" name="${field.optionsMapName}" filterName="${requestScope.ATT_FilterdCode}"  currentValue="${consultationNoteForm.value[fieldNameVariable]}"/>
			</c:when>
			<c:otherwise>
				<webapp:namedListSpring path='<%="value[" + field.getName() + "]"%>' id="<%=field.getName()%>" disabled="${disabled}" domain="${field.optionsMapDomain}" name="${field.optionsMapName}"  currentValue="${consultationNoteForm.value[fieldNameVariable]}" nlFromFormDefinition="${namedListMap[field.optionsMapDomain][field.optionsMapName]}"/>
			</c:otherwise>
		</c:choose>
</c:when>
<c:otherwise>
	<%-- this list has a related parent list which is used to filter this --%>
	<c:if test="${!empty(fn:trim(field.optionsMapName))}">
           <c:choose>
            <c:when test="${requestScope.ATT_ChildListId2Filter eq field.id}">
                <webapp:namedListSpring path='<%="value[" + field.getName() + "]"%>' id="<%=field.getName()%>" disabled="${disabled}" domain="${field.optionsMapDomain}" name="${field.optionsMapName}" filterName="${requestScope.ATT_FilterdCode}"  currentValue="${consultationNoteForm.value[fieldNameVariable]}"/>
            </c:when>
            <c:otherwise>
				<webapp:namedListSpring path='<%="value[" + field.getName() + "]"%>' id="<%=field.getName()%>" disabled="${disabled}" domain="${field.optionsMapDomain}" name="${field.optionsMapName}"  currentValue="${consultationNoteForm.value[fieldNameVariable]}" nlFromFormDefinition="${namedListMap[field.optionsMapDomain][field.optionsMapName]}"/>
            </c:otherwise>
        </c:choose>
        </c:if>
</c:otherwise>
</c:choose>
</c:if>
<%-- multiselect widget list --%>
<c:if test="${field.fieldType eq 101}">	

	<tiles:insertTemplate template="/emdt/tiles/${field.alignment}MultiSelectWidget.jsp" flush="false">
		<tiles:putAttribute name="fieldName" value="${field}"/>
		<tiles:putAttribute name="listDomain" value="${field.optionsMapDomain}"/>
		<tiles:putAttribute name="listName" value="${field.optionsMapName}"/>
		<tiles:putAttribute name="filterHospitalCode" value="${field.filterHospitalCode}"/>
		<tiles:putAttribute name="labelProperty" value="second"/>
		<tiles:putAttribute name="valueProperty" value="first"/>
		<tiles:putAttribute name="rows" value="6"/>
		<tiles:putAttribute name="disabled" value="${disabled}"/>
	</tiles:insertTemplate>
</c:if>
<%-- radio button list --%>
<c:if test="${field.fieldType eq 102}">
	<webapp:namedList id="nl" domain="${field.optionsMapDomain}" name="${field.optionsMapName}" nlFromFormDefinition="${namedListMap[field.optionsMapDomain][field.optionsMapName]}"/>
	<c:forEach var="pair" items="${nl.pairIterator}" varStatus="radioCount">
		<c:set var="radioCountInteger" value="${radioCount.count}"/>
		<% 
			Integer radioCountInteger=(Integer)pageContext.getAttribute("radioCountInteger");
		%>
		<input type="hidden" id="includesCount_<%=field.getName() + radioCountInteger%>" value="<%=field.getName()%>"/>
		<smvc:radiobutton disabled="${disabled}" path='<%="multiValue[" + field.getName() + "]"%>' value="${pair.first}" id="<%=field.getName() + radioCountInteger%>"/>&nbsp;<c:out value="${pair.second}"/>&nbsp;
		<c:if test="${field.alignment eq 'vertical'}"><br/></c:if>
	</c:forEach>
</c:if>
<c:if test="${field.fieldType eq 103}">
	<webapp:namedList id="nl" domain="${field.optionsMapDomain}" name="${field.optionsMapName}"  nlFromFormDefinition="${namedListMap[field.optionsMapDomain][field.optionsMapName]}"/>
	<c:forEach var="pair" items="${nl.pairIterator}" varStatus="checkboxCount">
		<c:set var="checkboxCountInteger" value="${checkboxCount.count}"/>
		<% 
			Integer checkboxCountInteger=(Integer)pageContext.getAttribute("checkboxCountInteger");
		%>
		<input type="hidden" id="includesCount_<%=field.getName() + checkboxCountInteger%>" value="<%=field.getName()%>"/>
		<smvc:checkbox disabled="${disabled}" path='<%="multiValue[" + field.getName() + "]"%>' value="${pair.first}" id="<%=field.getName() + checkboxCountInteger%>"/>&nbsp;<c:out value="${pair.second}"/>&nbsp;
		<c:if test="${field.alignment eq 'vertical'}"><br/></c:if>
	</c:forEach>
</c:if>
<%-- END LIST EDIT --%>