<script language="JavaScript" src="../scripts/ESR-Script.js"></script>
<%@ taglib uri="/tags/fw" prefix="fw" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html-el" %>
<%@ taglib uri="/tags/struts-bean-el" prefix="bean-el" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/tags/esr-core" prefix="esrcore" %>
<%@ page import='gov.va.med.esr.ui.common.util.JspUtils' %>

<c:set var="setNameLabel"><bean-el:message key="label.setName"/></c:set>
<c:set var="setDescriptionLabel"><bean-el:message key="label.setDescription"/></c:set>
<c:set var="activeDateLabel"><bean-el:message key="label.activeDate"/></c:set>
<c:set var="inactiveDateLabel"><bean-el:message key="label.inactivedate"/></c:set>
<c:set var="requiredText"><bean-el:message key="label.required"/></c:set>
<c:set var="selectLabel" value="Select" />

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShell" role="presentation">
<c:set var ="edit" value="true"/>
<c:if test="${empty capabilitySetForm.capabilitySetId}">
	<c:set var ="edit" value="false"/>
</c:if>
<c:set var="capabilityText" scope="page"><bean-el:message key="label.capability"/></c:set>
<c:set var="mmddyyyyText" scope="page"><bean-el:message key="label.mmddyyyy"/></c:set>

<!-- Same jsp is used for both edit and Andd -->
<html-el:form action="/editCapabilitySet" method="post">
 <%@ include file="/admin/csrfgentoken.jsp" %>
 <tr>
  <td>
   <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTable" role="presentation">
    <tr>
     <td>

	  <!-- add/edit capabilitySet heading -->
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTableHead" role="presentation">
       <tr>
        <td class="moduleBlueBox"><img alt=""  src="../images/spacer.gif" width="28" height="23"/></td>
			<c:choose>
				<c:when test="${edit == true}">
					<td nowrap class="moduleHeadline"> <bean-el:message key="label.editCapabilitySet"/></td>
					<td width="100%"><img alt=""  src="../images/spacer.gif"></td>
					<td nowrap class="moduleBlueLink" style="padding: 1 8 1 8">
						<!-- TODO need set the capability set id as parameter -->
						<fw:link action="/viewCapabilitySetHistory?methodName=DISPLAY&amp;history=viewHistoricalCapabilitySet&amp;returnPath=returnToEdit"
							paramId="entityId" paramName="capabilitySetForm" paramProperty="capabilitySetId">
						<bean-el:message key="label.link.viewHistoricalCapabilitySet"/>
						</fw:link>
					</td>
				</c:when>
				<c:otherwise>
					<td nowrap class="moduleHeadline"> <bean-el:message key="label.addCapabilitySet"/>
					</td>
				</c:otherwise>
			</c:choose>
        </tr>
      </table>

     </td>
    </tr>

    <tr>
     <td>
	  <!-- capabilitySet content -->
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
        <tr>
            <td><html-el:hidden name="capabilitySetForm" property="capabilitySetId"/></td>
			<td></td>
        </tr>
		<c:choose>
			<c:when test="${edit == true}">
				<!-- read only fields in edit mode-->
				<tr>
					<td width="45%" class="moduleLabel"><bean-el:message key="label.setName"/>:</td>
					<td width="55%" class="moduleValue">
						<c:out value="${capabilitySetForm.name}"/>
						<html-el:hidden name="capabilitySetForm" property="name" />
					</td>
				</tr>
			    <tr>
					<td width="45%" class="moduleLabel"><bean-el:message key="label.setDescription"/>:</td>
					<td width="55%" class="moduleValue">
						<c:out value="${capabilitySetForm.description}"/>
						<html-el:hidden name="capabilitySetForm" property="description" />
					</td>
				</tr>
			</c:when>
			<c:otherwise>
                <tr>
                    <td colspan="2">
                      <%@ include file="/tiles/common/instructionalText.jsp" %>
                    </td>
                </tr>
				<tr>
					<td nowrap width="45%" class="moduleLabel"><fw:label required="true" property="name" forId="txtName"><bean-el:message key="label.setName"/>:</fw:label></td>
					<td nowrap width="55%" class="moduleValue"><html-el:text title="${requiredText}, ${setNameLabel}" property="name" styleId="txtName" size="65" maxlength="100" /></td>
				</tr>
				<tr>
					<td width="45%" class="moduleLabel"><fw:label property="description" forId="txtDescription"><bean-el:message key="label.setDescription"/>:</fw:label></td>
					<td width="55%" class="moduleValue"><html-el:textarea title="${setDescriptionLabel}" property="description" styleId="txtDescription" cols="50" rows="3" /></td>
				</tr>
			</c:otherwise>
		</c:choose>

	    <!-- editable fields of the set-->
        <tr>
            <td width="45%" class="moduleLabel"><fw:label property="activeDate" forId="txtActiveDate"><bean-el:message key="label.activeDate"/>:</fw:label></td>
            <td width="55%" class="moduleValue"><html-el:text title="${activeDateLabel} ${mmddyyyyText}" property="activeDate" styleId="txtActiveDate" size="20" maxlength="10" />&nbsp;<bean-el:message key="label.mmddyyyy"/></td>
        </tr>
        <tr>
            <td width="45%" class="moduleLabel"><fw:label property="inactiveDate" forId="txtInactiveDate"><bean-el:message key="label.inactivedate"/>:</fw:label></td>
            <td width="55%" class="moduleValue"><html-el:text title="${inactiveDateLabel} ${mmddyyyyText}" property="inactiveDate" styleId="txtInactiveDate" size="20" maxlength="10" />&nbsp;<bean-el:message key="label.mmddyyyy"/></td>
        </tr>
	  </table>
	 </td>
	</tr>

	<!-- Assigned Capabilities (saved or in the process -->
    <c:if test="${not empty capabilitySetForm.assignedCapabilityNameList}">
	<tr>
	 <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableHead" role="presentation">
        <tr>
			<td class="moduleBrownBox"><img alt=""  src="../images/spacer.gif" width="28" height="23"/></td>
			<td nowrap class="moduleHeadline"><bean-el:message key="label.assignedCapabilitiestoSet"/></td>
			<td width="100%" class="moduleHeadline"><img alt=""  src="../images/spacer.gif"/></td>
		</tr>
	  </table>
	 </td>
	</tr>
	<tr>
	 <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
        <c:forEach var="capability" items="${capabilitySetForm.assignedCapabilityNameList}" varStatus="status">
			<c:set var="counter" value="${status.count - 1}" />
			<tr>
                <td width="2%" class="moduleValue" style="padding-left: 50">                	
					<html-el:checkbox title="${selectLabel} ${capabilitySetForm.assignedCapabilityNameList[counter]}" name="capabilitySetForm" property="assignedCapabilityInd[${counter}]" styleId="assignedCapabilityInd${counter}"/>
					<html-el:hidden name="capabilitySetForm" property="assignedCapabilityCode[${counter}]" />
				</td>
				<td width="2%" class="moduleValue"><html-el:img alt="${capabilityText}"  src="../images/capability.gif"/></td>
				<td nowrap class="moduleValue">
					<html-el:hidden name="capabilitySetForm" property="assignedCapabilityName[${counter}]" />
					<fw:label property="capabilitySetForm" forId="assignedCapabilityInd${counter}"><c:out value="${capabilitySetForm.assignedCapabilityNameList[counter]}"/></fw:label>
				</td>
				<td witdh="100%"><img alt=""  src="../images/spacer.gif"/></td>
			</tr>
		</c:forEach>
	  </table>
	 </td>
	</tr>
    </c:if>

    <!-- Available Capabilities assignedcpabilityInd-->
    <tr>
	 <td>
	  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableHead">
		<tr>
			<td class="moduleBrownBox"><img alt=""  src="../images/spacer.gif" width="28" height="23"/></td>
			<td nowrap class="moduleHeadline"><bean-el:message key="label.availableCapabilitiestoSet"/></td>
		</tr>
	  </table>
	 </td>
	</tr>
	<tr>
	 <td>
	  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="moduleShellTableBody" role="presentation">
       <c:set var="rowColor" value="darkValue" />
        <c:forEach var="capability" items="${capabilitySetForm.capabilityNameList}" varStatus="status">
			<c:set var="counter" value="${status.count - 1}" />
			<tr>
                <td width="2%" class="moduleValue" style="padding-left: 50">                	
					<html-el:checkbox title="${selectLabel} ${capabilitySetForm.capabilityNameList[counter]}" property="capabilityInd[${counter}]" styleId="capabilityInd${counter}"/>
					<html-el:hidden property="capabilityCode[${counter}]" />
				</td>
				<td width="2%" class="moduleValue"><html-el:img alt="${capabilityText}"  src="../images/capability.gif"/></td>
				<td class="moduleValue">
					<html-el:hidden property="capabilityName[${counter}]" />
					<fw:label property="capabilitySetForm" forId="capabilityInd${counter}"><c:out value="${capabilitySetForm.capabilityNameList[counter]}"/></fw:label>
				</td>
				<td witdh="100%"><img alt=""  src="../images/spacer.gif"/></td>
			</tr>
		</c:forEach>
			<tr>
				<td height = "25"/>
			</tr>
	  </table>
	 </td>
	</tr>

	<%-- Button Row --%>
    <tr>
     <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="moduleShellTableBody" role="presentation">
              <tr>
                <td width="45%"><img alt=""  src="../images/spacer.gif"/></td>
                <td><img alt=""  src="../images/buttonEndLeft.gif"/></td>
				<c:choose>
					<c:when test="${edit == true}">
						<td>
							<html-el:submit property="methodName"
								style="width:50; vertical-align: top;" styleClass="buttonText">
							<bean-el:message key="button.update"/>
							</html-el:submit>
						</td>
					</c:when>
					<c:otherwise>
						<td>
							<html-el:submit property="methodName"
								style="width:50; vertical-align: top;" styleClass="buttonText">
							<bean-el:message key="button.add"/>
							</html-el:submit>
						</td>
					</c:otherwise>
				</c:choose>
                <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
                <td width="1%"><img alt=""  src="../images/spacer.gif"/></td>
                <td><img alt=""  src="../images/buttonEndLeft.gif"/></td>
                <td><html-el:submit property="methodName" style="width:50; vertical-align: top;" styleClass="buttonText"><bean-el:message key="button.cancel"/></html-el:submit></td>
                <td><img alt=""  src="../images/buttonEndRight.gif"/></td>
                <td width="45%"><img alt=""  src="../images/spacer.gif"/></td>
              </tr>
		  	  <tr>
				<td height = "25"/>
			  </tr>
      </table>
     </td>
    </tr>
   </table>
  </td>
 </tr>
</html-el:form>
</table>
