<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<link rel="stylesheet" href="../css/draggable.css" type="text/css" />
<script src="../js/ReferralsDefinition.js" type="text/javascript"></script>

	<script type="text/javascript">
 		$(document).ready(function(){
// SPIRE-297 hide Q3 pagination for initial rollout
//		$('#referralsPathwayTblId').DataTable();
			nullifyId();
		});
	</script>
<sec:authorize access="hasRole('ADMIN')">
	<smvc:form id="referralsDefinitionForm" action="../emdt/referralsDefinition.form"  method="POST" >
		<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
		<input type="hidden" id="pathwayorder" name="pathwayorder" />
		<br/>
		<br/>
		<c:choose>
			<c:when
				test="${requestScope.successMsg != null || requestScope.errorMsg != null}">
				<c:if test="${requestScope.successMsg != null}">
					<span class="info">
						<c:out value="${requestScope.successMsg}"/>
					</span>
				</c:if>
				<c:if test="${requestScope.errorMsg != null}">
					<span class="error">
						<c:out value="${requestScope.errorMsg}"/>
					</span>
					<br />
				</c:if>
			</c:when>
			<c:otherwise>
			</c:otherwise>
		</c:choose>
		<c:if test="${referralDefinitionErrorMessages!=null}">
			<c:forEach var="errorMsg" items="${referralDefinitionErrorMessages}">
				<span class="error">
					<c:out value="${errorMsg}"/></span>
				<br />
			</c:forEach>
		</c:if>
		<c:if test="${referralDefinitionSuccessMessages!=null}">
			<c:forEach var="successMsg"
				items="${referralDefinitionSuccessMessages}">
				<span class="info">
					<c:out value="${successMsg}"/>
				</span>
				<br />
			</c:forEach>
		</c:if>
		<smvc:errors />
		<input type="hidden" name="mode" id="mode" value="" />
		<fieldset style="width: 70%;" class="nobg">
			<legend>Referral Pathways</legend>
			<fieldset>
				<input type="hidden" name="task" id="task" /> <input type="hidden"
					name="referralsDefinitionId" id="referralsDefinitionId" />
				<c:choose>
					<c:when
						test="${referralsDefinitionList!=null and fn:length(referralsDefinitionList)>0}">
						<table>
							<tr>
								<td colspan="10"><B>List of Referral Pathways</B></td>
							</tr>
							<tr>
								<td colspan="10">&#160;</td>
							</tr>
						</table>
						<table width="100%" border="1" bordercolor="#F8F8FF" cellspacing="0" id="referralsPathwayTblId" cellpadding="4" class="display">
							<thead>
								<tr>
									<th style="display: none"></th>
									<th><!-- Seq --></th>
									<th align="left">Title</th>
									<th align="left" width="30%">Speciality</th>
									<th align="left">Published</th>
									<th align="left">Edit</th>
									<th align="left">Delete</th>
								</tr>
							</thead>
							<tbody>
								<c:set var="referralsDefinitionListLength">${fn:length(referralsDefinitionList)}</c:set>
								<c:set var="index"/>
								<%
									int rowLenth = Integer.parseInt(pageContext.getAttribute("referralsDefinitionListLength").toString());
									for (int index = 0; index <= rowLenth; index++) {
									pageContext.setAttribute("index", index);
								%>

								<c:forEach var="referralsDefinition"  items="${referralsDefinitionList}" varStatus="s">
									<c:if test="${referralsDefinition.orderIndex==index}">
										<tr id="referralsPathwayRow${s.count}" class="grabableRow">
											<td style="display: none"><c:out value="${referralsDefinition.id}"/></td>
											<td class="grabable" title="Drag and drop to change ordering" width="6px"><!-- <c:out value="${s.count}"/> --></td>
											<td class="grabableTitle"><c:out value="${referralsDefinition.title}"/></td>
											<td class="grabableTitle"><c:out value="${referralsDefinition.speciality}"/></td>
											<c:choose>
												<c:when test="${referralsDefinition.published eq true}">
													<td>Yes</td>
												</c:when>
												<c:otherwise>
													<td>No</td>
												</c:otherwise>
											</c:choose>
											<td><a
												onclick="processEditDelete(3, ${referralsDefinition.id});return false;"
												title="Edit Referral Pathway"
												onmouseover="this.style.cursor = cursorPointer; "> <img
													src="../images/page_white_edit.png" border="0" alt="Edit" /></a></td>
											<td><a
												onclick="processEditDelete(4, ${referralsDefinition.id});return false;"
												title="Delete Referral Pathway"
												onmouseover="this.style.cursor = cursorPointer; "> <img
													src="../images/delete.png" border="0" alt="Delete" /></a></td>
										</tr>
									</c:if>
								</c:forEach>
								<%
									}
								%>
							</tbody>
						</table>
					</c:when>
					<c:otherwise>
						<table width="100%" cellspacing="0" cellpadding="4">
							<tr>
								<th>-- No Referral Pathways defined --</th>
							</tr>
						</table>
					</c:otherwise>
				</c:choose>
			</fieldset>
		<fieldset class="buttonFieldset">
			<input type="submit" id="btnSubmit" value="Save changes..." onclick="processPathwayOrder();" />
			<input type="button" value="Add a Referral Pathway..." onclick="createNewReferralsDefinitionForm(1);" />
		</fieldset>
	</smvc:form>

	<smvc:form id="importReferralsDefinitionForm" action="importReferralsDefinition.form?${_csrf.parameterName}=${_csrf.token}" enctype="multipart/form-data" method="post" onsubmit="return verifyBeforeImport();">
		<input type="hidden" id="${_csrf.parameterName}" value="${_csrf.token}" />

			<fieldset>
				<div>
					<b>Import Referral Pathways</b>
				</div>
				<br />
				<div>
					XML File:&nbsp;<input type="file" id="document" name="document"
						size="50" title="Select an XML file containing Referral Pathways" onchange="setFileSize(this);"/>
				</div>
				<br /> <input type="submit" value="import.." />
			</fieldset>
		</fieldset>
	</smvc:form></sec:authorize>
	<script type="text/javascript">
		$('#referralsPathwayTblId tbody').sortable({
			opacity: 0.5
		});
	</script>
