<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>

<br/>
<sec:authorize access="hasRole('ADMIN')">
<smvc:form action="../admin/groups.form" modelAttribute="groupsForm">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<input type="hidden" name="method" value="delete" id="dispatchMethod"/>
	<table cellspacing="0">
		<tr>
			<td colspan="5" class="tableTitleBar">Groups</td>
		</tr>
		<tr>
			<td width="100%">
				<table width="100%" cellspacing="0" class="table">
					<tr class="tableHeader">
						<th width="1" class="tableColHeader"></th>
						<th class="tableColHeader">Name</th>
						<th class="tableColHeader">Members</th>
					</tr>
					<c:forEach items="${groupsForm.groups}" var="group" varStatus="index" >
						<c:set var="indexInteger" value="${index.count}"/>
						<% 
							Integer i = (Integer )pageContext.getAttribute("indexInteger");
							String rowClass = i % 2 == 0 ? "evenRow" : "oddRow";
						%>
						<tr>
							<td><smvc:checkbox path="selected" value='${group.id }'/></td>
							<td><a href="../admin/group.form?id=<c:out value="${group.id }"/>" title="Click to edit group"><c:out value="${group.name }"/></a></td>
							<td>
								<c:forEach var="username" items="${group.members }">
									<c:out value="${username }"/>
								</c:forEach>
							</td>
						</tr>
					</c:forEach>
					<tr>
						<td align="right" colspan="3">
							<input type="submit" value="Delete Selected" onclick="return confirmAndDispatch('delete', 'Are you sure you wish to remove the selected groups?')"/>
							&nbsp;
							<input type="button" value="Create group" onclick="document.location='../admin/group.form?id=new'"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</smvc:form></sec:authorize>
