<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<script>
function uncheckAll(field){	
	for (i = 0; i < field.length; i++)
	    field[i].checked = false ;
}
function submitForm(value){
	uncheckAll(document.messagingForm.selectedEmailNotifications);
	location.href="../admin/messaging.form?selectedUser="+value;
}
</script>
<body>
<smvc:form modelAttribute="messagingForm" method="POST" enctype="multipart/form-data" name="messagingForm" action="../admin/messaging.form?${_csrf.parameterName}=${_csrf.token}">
	<input type="hidden" name="redirectParams" value="${requestScope['javax.servlet.forward.query_string']}" />
	<table width="52%">
	<tr>
		<td>
			<fieldset class="nobg">
				<legend>User Messaging Preferences</legend>
					<fieldset>
					<table width="100%">
						<tr>
							<th align="left" style="font-size: 10pt;">User</th>
						</tr>
						<tr>
							<td align="left">
								<smvc:select path="selectedUser"  onchange="submitForm(this.options[this.selectedIndex].value)">
									<c:forEach var="usersByHospitalMap" items="${webapp.usersByHospitalIdMap}">
										<optgroup label="${webapp.hospMap[usersByHospitalMap.key]}">
											<c:forEach var="userId" items="${usersByHospitalMap.value}">
												<smvc:option value="${userId}"><c:out value="${webapp.userIdNameMap[userId]}"/></smvc:option>
											</c:forEach>
										</optgroup>
									</c:forEach>
								</smvc:select>
							</td>
						</tr>
						</table>
				  </fieldset>
			  <fieldset>
				<table width="100%">
						<tr>
							<td colspan="4">
								<img src="../images/16x16/information.png"/>&nbsp;Select the events for which this user would like notification<br/>
								<hr/>							
							</td>
						</tr>
				        <tr>
							<td align="left"><c:if test="${!empty saveSuccessMessage}"><span class="info"><c:out value="${saveSuccessMessage}"/></span></c:if></td>
							<td align="left">&nbsp;</td>
							<td align="left">&nbsp;</td>
							<td align="left">&nbsp;</td>
						</tr>
						<tr>
							<td align="right" colspan="4" style="padding-right: 25px;">
								Select: <a href="javascript:select('all')">All</a> | <a href="javascript:select('none')">None</a> | <a href="javascript:select('invert')">Invert</a>
							</td>
						</tr>
						<tr>
							<td align="left"><b>Type of Event</b></td>
							<td align="center"><b>Email</b></td>
							<td align="center"><b>Inbox</b></td>
							<td align="left">&nbsp;</td>
						</tr>
						
						<c:forEach var="amw" items="${activeMessagingWays}">
							<tr>
							<td align="left"><c:out value="${amw.messagingDescription}"/></td>
							<td align="center">
								<smvc:checkbox path="selectedEmailNotifications" value="${amw.messagingId}" cssClass="allNonInvert"/>&nbsp;<br/>
							</td>
							<td align="center">	
								<smvc:checkbox path="selectedInboxNotifications" value="${amw.messagingId}" cssClass="allNonInvert"/>&nbsp;<br/>
							</td>
							<td align="left">&nbsp;</td>
							</tr>
						</c:forEach>
						
						<tr>
							<td align="left">&nbsp;</td>
							<td align="center" colspan="3">&nbsp;<input type="submit" value="Save" /></td>
						</tr>
				</table>
			  </fieldset>
		</fieldset>
		</td>
		</tr>
</table>
</smvc:form>