<%@page import="com.ardeo.entities.reports.PatientSummary"%>
<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<script type="text/javascript">
    function remove(index) {
        var mutex = false;
        if(!mutex) {
            mutex = true;
                if(confirmAndDispatch("removeForm", "Are you sure you wish to remove this form?")) {
                    document.getElementById("matchIndex").value = index;
                    document.getElementById("patientSummaryForm").submit();
                }
            mutex = false;
        }
    }
    
    function move(index, amount) { 
        var mutex = false;        
        if(!mutex) {
            mutex = true;
            dispatch("move");
            document.getElementById("matchIndex").value = index;
            document.getElementById("moveMatchAmmount").value = amount
            document.getElementById("patientSummaryForm").submit();
        }
    }
    
    function cancelAddForm() {
        var submit = false;
        submit = dispatch("cancel");
        return submit;
    }
    
    function addForm() {
        var submit = false;
        submit = dispatch("addForm");
        return submit;
    }
</script>

<div class="breadcrumb">
You are here: <a href="../emdt/emdtHome.form"><img src="../emdt/images/16x16/icon.png" style="vertical-align: top;"/> eMDT</a> &gt; <a href="../emdt/reportMenu.jsp">Reports</a> &gt; <a href="../emdt/patientSummaryActions.form">Patient Summaries</a> &gt; <a class="selected">Edit Summary</a>
</div>

<br/>
<smvc:form id="patientSummaryForm" action="../emdt/patientSummaryActions.form" modelAttribute="patientSummaryForm">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<c:set var="currentPatientSummary" value="${patientSummaryForm.patientSummary}"></c:set>
	<%
		PatientSummary currentPatientSummary = (PatientSummary)pageContext.getAttribute("currentPatientSummary");
	    session.setAttribute("currentPatientSummary",currentPatientSummary) ;
	 %>
	 <c:if test="${patientSummaryForm.patientSummary.id ne null}">
	 	<smvc:hidden path="patientSummary.id"/>
	 </c:if>
	<input type="hidden" name="method" value="save" id="dispatchMethod"/>
	<input type="hidden" name="matchIndex" id="matchIndex"/>
	<input type="hidden" name="moveMatchAmmount" id="moveMatchAmmount"/>
	<table>
		<tr>
			<td align="center">
				<tags:dialogBox title="Edit Patient Summary">
					<table>
						<tr>
							<td class="label" style="width: 100px;">Title</td>
							<td class="input"><smvc:input path="patientSummary.title" size="40"/></td>
						</tr>
						<tr>
							<td class="label" style="width: 100px;">Forms</td>
							<td class="input" style="vertical-align: top">
								<table cellpadding="4">
								<c:forEach var="sf" items="${patientSummary.summaryForms}" varStatus="s">
									<tr>
									    <td width="30">
                                            <img onclick="move(${s.index}, -1)" onmouseover="this.style.cursor = cursorPointer" src="../images/up.gif" title="Move Up" />
                                            <img onclick="move(${s.index}, 1)" onmouseover="this.style.cursor = cursorPointer" src="../images/down.gif" title="Move Down" />
                                        </td>
										<td width="200"><webapp:formLabel name="${sf.formName}"/></td>
										<td><a href="summaryFormActions.form?sf_index=<c:out value="${s.index}"/>" title="Select form fields to include in this summary"><img src="../images/page_white_edit.png" alt="edit"/> Choose fields</a></td>
										<td><a href="javaScript:remove('<c:out value="${s.index}"/>');" title="Remove this form and its fields from the summary"><img src="../images/delete.png" alt="remove"/> &#160;Remove</a></td>
                                    </tr>
								</c:forEach>
								</table>
								<br/>
								Add form to summary<br/>		
								<smvc:select path="newFormName">
									<smvc:option value=""></smvc:option>
									<c:forEach var="group" items="${emdt.formDomain.children}">
										<optgroup label="<c:out value="${group.label}"/>">
											<c:forEach var="formDef" items="${group.children}">
												<c:if test="${formDef.liveStatus != 0}">
													<smvc:option value="${formDef.path}"><c:out value="${formDef.label}"/></smvc:option>
												</c:if>
											</c:forEach>
										</optgroup>
									</c:forEach>
								</smvc:select>
								<input type="submit" value="Add" onclick="return addForm()"/>
							</td>
						</tr>
					</table>
				</tags:dialogBox>
				<br/>
               <input type="button" value="Cancel" onclick="location.href='patientSummaryActions.form?method=list'"/>&nbsp;<input type="submit"  value="Save"/>
			</td>
		</tr>
	</table>
</smvc:form>
