<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<script>
	$(function() {
		$("input#formObjectName").on("keydown", function(e) {
			return e.which !== 32;
		});
		$("input#formObjectNameNew").on("keydown", function(e) {
			return e.which !== 32;
		});
	});
</script>
<script>
	var moving = false;
	function update() {
	     document.getElementById("form").submit();
        fullScreenPleaseWait();
    }

	function moveItem(id, amount) {

		if(!moving) {
			moving = true;
			document.getElementById("dispatchMethod").value = "move";
			document.getElementById("moveId").value = id;
			document.getElementById("moveAmount").value = amount;
			document.getElementById("form").submit();
		}
	}
	
	function popupImport() {
		window.open("importFormObject.jsp",'importForm','scrollbars=1,toolbar=0,status=1,menubar=1,resizable=1,location=0,directories=0,width=700,height=500,left=0,top=0');
	}
	
	function disabled1(selected) {
	var chks = document.getElementsByName(selected.name);
	var chkCount = 0;
	for (i = 0; i < chks.length; i++)
	{
		if (chks[i].checked)
		{
			chkCount++;
		}
	}
	if (chkCount > 0)
	{
		document.getElementById("removeSelected").disabled = false;
	} else{
		document.getElementById("removeSelected").disabled = true;
	}
}	
	function setCheckBoxes(){
		if(document.getElementById('showNotes') != null)	{
			if (document.getElementById('showNotes').checked){
				document.getElementById('showNotesName').value="true";
				// UI toggling
				document.getElementById('allowNotesAttachment').disabled = false;
				document.getElementById('allowNotification').disabled = false;
				if(document.getElementById('allowNotification').checked && document.getElementById('notifyingUsers') != null) {
					document.getElementById('notifyingUsers').disabled = false;
				}
			}else{
				document.getElementById('showNotesName').value="false";
				// UI toggling
				document.getElementById('allowNotesAttachment').disabled = true;
				document.getElementById('allowNotification').disabled = true;
				if(document.getElementById('allowNotification').checked && document.getElementById('notifyingUsers') != null) {
					document.getElementById('notifyingUsers').disabled = true;
				}
			}
			if(document.getElementById('allowNotesAttachment').checked){
				document.getElementById('allowNotesAttachmentName').value="true";
			}else{
				document.getElementById('allowNotesAttachmentName').value="false";
			}
			if(document.getElementById('allowNotification').checked){
				document.getElementById('allowNotificationName').value="true";
				if (document.getElementById('notifyingUsers') != null)
					document.getElementById('notifyingUsers').disabled = false;
			}else{
				document.getElementById('allowNotificationName').value="false";
				if (document.getElementById('notifyingUsers') != null)
					document.getElementById('notifyingUsers').disabled = true;
			}
		} 
	}
	function removeBanding(selectedBandingDataIndex){
		document.getElementById('selectedBandingDataIndex').value=selectedBandingDataIndex;
		document.getElementById("dispatchMethod").value = "removeBanding";
		document.getElementById("form").submit();
	}
</script>

<br/>
<sec:authorize access="hasRole('ADMIN')">
<smvc:form action="../emdt/formObject.form" id="form" modelAttribute="formObjectForm">
<%@ include file="../../tiles/colorPickerPopup.jsp" %>
	<input type="hidden" id="csrfparameterName" value="<c:out value="${_csrf.parameterName}"/>" />
	<input type="hidden" id="csrfparametervalue" value="<c:out value="${_csrf.token}"/>" />
	<input type="hidden" name="${_csrf.parameterName}" value="<c:out value="${_csrf.token}"/>" />
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<table width="100%">
	       <c:if test="${successMsg ne null }">
                <span class="info"><spring:message code="${ successMsg}" text="Saved" /></span><br>
        	</c:if>
        	<c:if test="${errors ne null }">
                <span class="error"><c:out value="${ errors}"/></span><br>
        	</c:if>
		<tr>
			<td align="left">
				<tiles:insertTemplate template ="domainNavigator.jsp"/><a href="../help/form-admin.html#Overview" title="Help - Form Editor Overview" target="_help"><img src="../images/16x16/help.png" alt="Help icon" border="0"/></a>
				<br/>
				<br/>
			</td>
		</tr>
		<c:if test="${formObjectForm.customForm eq true}">
		<tr>
			<td align="left"><span class="info">Please note that this form has a custom web page and should be edited with caution.</span><br></td>
		</c:if>
		<tr>
			<td align="left" valign="top" width="45%" style="padding: 0 5px 0 0">
				<tiles:insertTemplate template ="editFormObject.jsp"/>
				<br/>
			</td>
		</tr>
		<tr>			
			<td align="left" valign="top" style="padding: 0 0 0 5px">
				<table border="0">
					<tr>
						<td>
							<c:if test="${ formObject.childClass ne null}" >
								<tiles:insertTemplate template ="listFormObjectChildren.jsp"/>
								<br/>
								<tiles:insertTemplate template ="addFormObjectChild.jsp"/>
							</c:if>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<c:set var="formType" value="${formObject.getClass().simpleName}"/>
<tiles:insertTemplate template ="forms/preview${formType}.jsp"/>
</smvc:form></sec:authorize>