<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<script type="text/javascript">
	function openFileUpload(){
		document.getElementById('my_file').click();
	}
	function updateLabelUrl(){
		var selectedfileName=document.getElementById('selectedfileName').value;
		if(!selectedfileName || 0 === selectedfileName.length){
			alert("please select a file")
			document.getElementById('selectedfileName').focus();
			return;
		}
		var baseurl=document.getElementById('webShareBaseUrl').value;
		document.getElementById('labelUrl').value=baseurl+selectedfileName;
	}
	function uploadWebShareFile(){
		var data = new FormData();
		data.append( 'file', $( '#my_file' )[0].files[0] );
		var csrfdata=document.getElementById("csrfparameterName").value;
		csrfdata=csrfdata+"="+document.getElementById("csrfparametervalue").value;
		$.ajax({
			type: "POST",
		   	url: "../emdt/ajaxUploadWebShareFiles.form?" + csrfdata,
		   	enctype: 'multipart/form-data',
		   	data : data,
		   	processData: false,
          	contentType: false,
		   	success: function(msg){
		   		$('#selectedfileName').empty(); //remove all child nodes
		   		var emptyOption = $('<option value=""></option>');
		        $('#selectedfileName').append(emptyOption);	
		   	for(var index=0;index<msg.fileSize; index++){
		        var filenameoption = $('<option value="'+msg.fileList[index]+'">'+msg.fileList[index]+'</option>');
		        $('#selectedfileName').append(filenameoption);
		   	} 
//		    $('#selectedfileName').trigger("chosen:updated");
		  			
		   }
	  });
	}
</script>
<%-- THIS FILE IS INCLUDED FROM editFormObjectLayout.jsp --%>
<c:set var="inputType" value="${formObject.inputType}"/>
<tr>
	<td class="label">Required ?</td>
	<td class="input"><smvc:checkbox path="formField.required" title="Check this box if the user is required to enter a value"/></td>
</tr>
<tr>
	<td colspan="2"><hr/></td>
</tr>
<tr>
	<td class="label">Label&nbsp;Type</td>
	<td class="input">
		<smvc:select path="formObject.labelType" onchange="update()" title="The label can be either a text label or a separator, which is a horizontal line">
			<smvc:option value="text">Text</smvc:option>
			<smvc:option value="separator">Separator</smvc:option>
		</smvc:select>
	</td>
</tr>


<tr>
	<td class="label">Label Style and Colour</td>

	<td>
		<table>
			<tr>
				<td><smvc:hidden id="styleId"  path="formField.style" /> 
			<%-- 	<smvc:hidden styleId="labelTextId" path="formObject.name" /> --%>
				<input type="hidden" id="boldId" value="0" /> <a onclick="setStyle('bold');"><img src="images/16x16/bold.png" /></a></td>
				<td width="10"></td>
				<td><input type="hidden" id="italicId" value="0" /> <a onclick="setStyle('italic');"><img src="images/16x16/italic.png" /></a></td>
				<td width="10"></td>
				<td><input type="hidden" id="underlineId" value="0" /> <a onclick="setStyle('underline');"><img src="images/16x16/underline.png" /></a></td>
				<td width="10"></td>
				<td><select id="textSizeId" onchange="setStyle('textSize');">
						<option value="10">10</option>
						<option value="11">11</option>
						<option value="12">12</option>
						<option value="13">13</option>
						<option value="14">14</option>
						<option value="15">15</option>
						<option value="16">16</option>
						<option value="17">17</option>
						<option value="18">18</option>
				</select></td>
				<td width="10"></td>
				<td><select id="textColorId" onchange="setStyle('textColor');">
						<option value="#000000" style="background-color: Black; color: #FFFFFF;">Black</option>
						<option value="#808080" style="background-color: Gray;">Gray</option>
						<option value="#A9A9A9" style="background-color: DarkGray;">DarkGray</option>
						<option value="#D3D3D3" style="background-color: LightGrey;">LightGray</option>
						<option value="#FFFFFF" style="background-color: White;">White</option>
						<option value="#7FFFD4" style="background-color: Aquamarine;">Aquamarine</option>
						<option value="#0000FF" style="background-color: Blue;">Blue</option>
						<option value="#000080" style="background-color: Navy; color: #FFFFFF;">Navy</option>
						<option value="#800080" style="background-color: Purple; color: #FFFFFF;">Purple</option>
						<option value="#FF1493" style="background-color: DeepPink;">DeepPink</option>
						<option value="#EE82EE" style="background-color: Violet;">Violet</option>
						<option value="#FFC0CB" style="background-color: Pink;">Pink</option>
						<option value="#006400" style="background-color: DarkGreen; color: #FFFFFF;">DarkGreen</option>
						<option value="#008000" style="background-color: Green; color: #FFFFFF;">Green</option>
						<option value="#9ACD32" style="background-color: YellowGreen;">YellowGreen</option>
						<option value="#FFFF00" style="background-color: Yellow;">Yellow</option>
						<option value="#FFA500" style="background-color: Orange;">Orange</option>
						<option value="#FF0000" style="background-color: Red;">Red</option>
						<option value="#A52A2A" style="background-color: Brown;">Brown</option>
						<option value="#DEB887" style="background-color: BurlyWood;">BurlyWood</option>
						<option value="#F5F5DC" style="background-color: Beige;">Beige</option>
				</select></td>
			</tr>
		</table>
	</td>
</tr>


<tr>
	<td class="label">Label&nbsp;Alignment</td>
	<td class="input">
		<smvc:select path="formObject.labelAlign" onchange="update()" title="Specify how the label should be positioned">
			<smvc:option value="left">Left</smvc:option>
			<smvc:option value="center">Centre</smvc:option>
			<smvc:option value="right">Right</smvc:option>
		</smvc:select>
	</td>
</tr>
<tr>
	<td class="label">Label URL</td>
	<td class="input">
		<input type="hidden" id="webShareBaseUrl" value="<c:out value="${webapp.webShareBaseUrl}"/>" >
		<smvc:input path="formObject.labelUrl" title="Entering a URL here will turn this label into a link (optional)"/>&nbsp;&nbsp;
		<img src="../images/16x16/link_go.png" border="0" onclick="updateLabelUrl();" style="cursor: pointer;" title="Use link to this file" />&nbsp;&nbsp;
		<select id="selectedfileName" class="chosen" title="Pick a file to link to">
			<option value=""></option>
			<c:forEach var="file" items="${webapp.webShareFiles}">
				<option value="<c:out value="${file.name}"/>"><c:out value="${file.name}"/></option>
			</c:forEach>
		</select>&nbsp;&nbsp;
		<img src="../images/add.png" alt="upload file" border="0" onclick="openFileUpload();" style="cursor: pointer;" title="Upload a file"/>
		&nbsp;&nbsp;
		<form action="../emdt/webShareFiles.form?${_csrf.parameterName}=${_csrf.token}" method="post" enctype="multipart/form-data" name="fileinfo">
			<input type="file"  name="file" id="my_file" style="display:none"  onchange="setFileSize(this);uploadWebShareFile();"/>
		</form>
	</td>
</tr>
<tr>
	<td colspan="2"><hr/></td>
</tr>
<tr>
	<td class="label"><b>Field Type</b></td>
	<td class="input">
		<smvc:select path="formField.inputType" onchange="update()" title="Choose a type of input field appropriate to what you want the user to enter">
			<smvc:option value="0">None</smvc:option>
			<smvc:option value="1">Text</smvc:option>
			<smvc:option value="2">Number</smvc:option>
			<smvc:option value="3">Floating point number</smvc:option>
			<smvc:option value="4">Date</smvc:option>
			<smvc:option value="7">Time</smvc:option>
			<smvc:option value="5">List</smvc:option>
			<smvc:option value="6">URL</smvc:option>
			<smvc:option value="8">Button</smvc:option>
			<smvc:option value="9">File Uploader</smvc:option>
			<smvc:option value="10">Metadata</smvc:option>
			<smvc:option value="11">Traffic light</smvc:option>
		</smvc:select>
    <c:if test="${formObject.inputType eq 5}">
    <b>&nbsp;&nbsp;&nbsp;Filter&nbsp;</b> 
    <smvc:select name="formObjectForm" path="selectedFilterFieldId" title="Choose the filter Field">
        <smvc:option value="0">NONE</smvc:option>
        <webapp:forEach id="child" items="${formFieldsTypeList}" >
            <smvc:option value="${child.id}"><c:out value="${child.name}"/></smvc:option>
        </webapp:forEach>
    </smvc:select>
    
    </c:if>
	</td>
	
</tr>
<tiles:insertTemplate template ="editFieldType${inputType}.jsp" />
<c:if test="${formObject.inputType ne 0}">
	<c:if test="${formObject.inputType ne 8}">
	<tr> 
		<td colspan="2">
			<hr/>
			<b>&nbsp;Default field value</b>
		</td>
	</tr>
	<tr>
		<td class="label">
			<smvc:radiobutton path="formField.defaultValueMode" value="0"/>&nbsp;No default (blank)
		</td>
		<td></td>
	</tr>
	<tr>
		<td class="label" title="Copy field value from previous/older form of this type">
			<smvc:radiobutton path="formField.defaultValueMode" value="2"/>&nbsp;From previous form
		</td>
		<td></td>
	</tr>
	<tr>
		<td class="label"><smvc:radiobutton path="formField.defaultValueMode" value="1"/>&nbsp;Text</td>
		<td class="input"><smvc:input path="formField.defaultValueText"/></td>
	</tr>
	<tr>
		<td class="label">
			<smvc:radiobutton path="formField.defaultValueMode" value="3"/>&nbsp;From another form
		</td>
		<td class="input">
			<smvc:select path="formField.externalReferenceForm" onchange="update()">
				<smvc:option value="">None</smvc:option>
				<smvc:option value="com.ardeo.entities.Patient">Patient</smvc:option>
				<smvc:option value="com.ardeo.entities.CareSpell">Carespell</smvc:option>
				<c:forEach var="grp" items="${emdt.formDomain.children }">
					<optgroup label="<c:out value="${grp.label}"/>"> 
					<c:forEach var="def" items="${grp.children }">
							<smvc:option value="${def.path}"><c:out value="${def.label}"/></smvc:option>
						</c:forEach>
					</optgroup>
				</c:forEach>
			</smvc:select>
			<smvc:select path="formField.externalReferenceField">
				<smvc:option value="" />
				<c:if test="${formObject.externalReferenceForm != null }">
					<c:choose>
						<c:when test="${formObject.externalReferenceForm == 'com.ardeo.entities.Patient' }">
							<smvc:option value="address">Address</smvc:option>
							<smvc:option value="assessmentPlan">Assessment Plan</smvc:option>
							<smvc:option value="country">Country</smvc:option>
							<smvc:option value="currentAge">Current Age</smvc:option>
							<smvc:option value="dateOfBirth">Date Of Birth</smvc:option>
							<smvc:option value="dateOfDeath">Date Of Death</smvc:option>
							<smvc:option value="emailAddress">Email Address</smvc:option>
							<smvc:option value="ethnicity">Ethnicity</smvc:option>
							<smvc:option value="forename">Forename</smvc:option>
							<smvc:option value="fullName">Full Name</smvc:option>
							<smvc:option value="gpFaxNumber">GP Fax Number</smvc:option>
							<smvc:option value="gpForename">GP Forename</smvc:option>
							<smvc:option value="gpPostcode">GP Postcode</smvc:option>
							<smvc:option value="gpSurgeryAddress">GP Surgery Address</smvc:option>
							<smvc:option value="gpSurname">GP Surname</smvc:option>
							<smvc:option value="gpTelephoneNumber">GP Telephone Number</smvc:option>
							<smvc:option value="gpEmailAddress">GP Email Address</smvc:option>
							<smvc:option value="gpGMPCode">GP GMP Code</smvc:option>
							<smvc:option value="gpPracticeCode">GP Practice Code</smvc:option>
							<smvc:option value="homePhoneNumber">Home Phone Number</smvc:option>
							<smvc:option value="hospitalNumber">Hospital Number</smvc:option>
							<smvc:option value="imageUrl">Image URL</smvc:option>
							<smvc:option value="language">Language</smvc:option>
							<smvc:option value="maritalStatus">Marital Status</smvc:option>
							<smvc:option value="middleNames">Middle Names</smvc:option>
							<smvc:option value="mobilePhoneNumber">Mobile Phone Number</smvc:option>
							<smvc:option value="nationality">Nationality</smvc:option>
							<smvc:option value="nhsNumber">NHS Number</smvc:option>
							<smvc:option value="nokAddress">NokAddress</smvc:option>
							<smvc:option value="nokCountry">NokCountry</smvc:option>
							<smvc:option value="nokForenames">NokForenames</smvc:option>
							<smvc:option value="nokPostcode">NokPostcode</smvc:option>
							<smvc:option value="nokSurname">NokSurname</smvc:option>
							<smvc:option value="nokTelephoneNumber1">Nok Telephone Number 1</smvc:option>
							<smvc:option value="nokTelephoneNumber2">Nok Telephone Number 2</smvc:option>
							<smvc:option value="nokRelationship">Next of Kin Relationship</smvc:option>
							<smvc:option value="occupation">Occupation</smvc:option>
							<smvc:option value="overseasVisitor">Overseas Visitor</smvc:option>
							<smvc:option value="postcode">Postcode</smvc:option>
							<smvc:option value="primaryTumourGroup">Primary Tumour Group</smvc:option>
							<smvc:option value="registeredDisabled">Registered Disabled</smvc:option>
							<smvc:option value="religion">Religion</smvc:option>
							<smvc:option value="sex">Sex</smvc:option>
							<smvc:option value="surname">Surname</smvc:option>
							<smvc:option value="title">Title</smvc:option>
						</c:when>
						<c:when test="${formObject.externalReferenceForm == 'com.ardeo.entities.CareSpell' }">
							<smvc:option value="keyWorker">Key Worker</smvc:option>
							<smvc:option value="primarySite">Primary Site</smvc:option>
							<smvc:option value="primaryClinician">Primary Clinician</smvc:option>
							<smvc:option value="status">Status</smvc:option>
						</c:when>
						<c:otherwise>
							<c:forEach var="grp" items="${emdt.formDomain.children}">
								<c:forEach var="def" items="${grp.children}">
									<c:if test="${def.path ==  formObject.externalReferenceForm}">
										<c:forEach var="pge" items="${def.children}">
											<c:forEach var="section" items="${pge.children}">
												<c:forEach var="fld" items="${section.children}">
													<smvc:option value="${fld.name}"><c:out value="${fld.label} [${fld.name}]"/></smvc:option>
												</c:forEach>
											</c:forEach>
										</c:forEach>
									</c:if>
								</c:forEach>
							</c:forEach>
						</c:otherwise>
					</c:choose>
				</c:if>
			</smvc:select>
			<smvc:hidden path="newName"/><smvc:hidden path="newLabel"/>
		</td>
	</tr>
	<tr>
		<td class="label"><smvc:radiobutton path="formField.defaultValueMode" value="4"/>&nbsp;Sequence</td>
		<td class="input">
			<smvc:select path="formField.defaultSequenceName">
				<smvc:options path="sequenceNames"/>
			</smvc:select>
		</td>
	</tr>
	<c:if test="${formObject.externalReferenceForm != null }">
		<tr>
			<td class="label">Allow to update other form?</td>
			<td class="input">
				<smvc:radiobutton path="formField.syncWithReference" value="true"/>&nbsp;Yes&nbsp;
				<smvc:radiobutton path="formField.syncWithReference" value="false"/>&nbsp;No
			</td>
		</tr>
	</c:if>
  </c:if>
</c:if>