<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"      prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://struts.apache.org/tags-html"     prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"       prefix="fmt" %>
<%@ taglib uri="http://struts.apache.org/tags-bean"     prefix="bean" %>

<h2>Assoziation "${requestScope.Association.name}"</h2>

<div class="FLOATFORMULAR">
	<c:if test="${requestScope.Association.version > requestScope.Rating.ratedVersion}">
		<span class="HINWEIS">Sie haben eine &auml;ltere Version dieser Assoziation bewertet. Bitte pr&uuml;fen Sie, ob Ihre Bewertung noch zutrifft.</span><br>
	</c:if>
	<html:form action="changeassociationrating?id=${requestScope.Association.id}">
		Ich stimme dieser Assoziation
		<html:radio property="assocrating" value="YES">zu</html:radio>
		<html:radio property="assocrating" value="NO">nicht zu</html:radio>
		<html:radio property="assocrating" value="NEUTRAL">keine Meinung</html:radio>
		&nbsp;&nbsp;<input type="submit" value="Bewerten">
		<br>Kommentar: <html:text property="ratingcomment" size="30"/>
		<c:if test="${not empty requestScope.Rating.comment}">
			<br>(Derzeitiger Kommentar: "${requestScope.Rating.comment}")
		</c:if>
	</html:form>
</div>

<p>
<c:if test="${not empty requestScope.Association.creator}">
	Angelegt von
	<c:choose>
		<c:when test="${requestScope.Association.creator.username == sessionScope.User.username}">
			Ihnen selbst!
		</c:when>
		<c:otherwise>
			${requestScope.Association.creator.firstname} ${requestScope.Association.creator.lastname} (${requestScope.Association.creator.username}).
		</c:otherwise>
	</c:choose>
	<br>
</c:if>
${requestScope.Association.version}</p>
<p>
<c:choose>
	<c:when test="${requestScope.Association.ratingsCount > 0}">
		<jsp:include page="/WEB-INF/content/rating.jsp">
			<jsp:param name="wert" value="${requestScope.Association.averageRatingValue}"/>
			<jsp:param name="anzahl" value="${requestScope.Association.ratingsCount}"/>
		</jsp:include>
	</c:when>
	<c:otherwise>
		Noch keine Bewertungen.
	</c:otherwise>
</c:choose>

<p>Typ:
	<c:choose>
		<c:when test="${not empty requestScope.Association.type}">
			"<html:link action="topicview?id=${requestScope.Association.type.id}">${requestScope.Association.type.name}</html:link>"
		</c:when>
		<c:otherwise>
			keiner.
		</c:otherwise>
	</c:choose>
</p>

<c:if test="${not empty requestScope.AssociationRoles}">
	<p>Rollen und Spieler:</p>
	<ul>
		<c:forEach items="${requestScope.AssociationRoles}" var="rb">
			<li> Rolle
				<c:choose>
					<c:when test="${not empty rb.role.type}">
						"<html:link action="topicview?id=${rb.role.type.id}">${rb.role.name}</html:link>"
					</c:when>
					<c:otherwise>
						ohne Typ
					</c:otherwise>
				</c:choose>
				<c:if test="${not empty rb.topics}">
					<ul>
						<c:forEach items="${rb.topics}" var="t">
							<li> Topic "<html:link action="topicview?id=${t.id}">${t.name}</html:link>" </li>
						</c:forEach>
					</ul>
				</c:if>
			</li> 
		</c:forEach>
	</ul>
</c:if>

<div class="FORMULAR">

	<html:errors/>

	<div class="FLOATNOTE">
		In dieser Beispielanwendung werden die 10 zuletzt angesehenen Topics als m&ouml;gliche Typen angeboten.
		Denkbar w&auml;re aber auch, dass eine Anwendung eine spezielle Liste mit Assoziations-Typen verwaltet.
	</div>
	
	<html:form action="associationchange" focus="assocname">
		<p>Typ der Assoziation:
		<br> <html:radio property="assoctypeid" value=""> keiner </html:radio>
		<c:if test="${not empty sessionScope.LastTopics}">
			<c:forEach items="${sessionScope.LastTopics}" var="i">
				<br> <html:radio property="assoctypeid" value="${i.id}"> ${i.name} </html:radio>
			</c:forEach>
		</c:if>
		</p>
		
		<p><bean:message key="assocchangeform.assocname"/>: <html:text property="assocname"/></p>
		
		<hr>

		<p><html:submit><bean:message key="assocchangeform.submit"/></html:submit> <html:hidden property="associd"/></p>
	</html:form>
	
</div>


<c:if test="${requestScope.Association.ratingsCount > 0}">
	<p>&nbsp;</p>
	
	<p>Alle Bewertungen zu dieser Assoziation:</p>

	<table border="1" cellpadding="2" cellspacing="2">
		<tr>
			<th>&nbsp;</th> <th>Benutzer</th> <th>Bewertung</th> <th>Version der Bewertung</th> <th>Kommentar</th>
		</tr>

		<c:forEach items="${requestScope.Association.ratings}" var="rating" varStatus="nr">
			<tr>
				<td align="right"> ${nr.count} </td>
				<td>
					<c:choose>
						<c:when test="${rating.creator.username == sessionScope.User.username}">
							Sie selbst!
						</c:when>
						<c:otherwise>
							${rating.creator}
						</c:otherwise>
					</c:choose>
				</td>
				<td align="right"> <fmt:formatNumber value="${rating.value}" maxFractionDigits="2"/> </td>
				<td> ${rating.version} </td>
				<td> ${rating.comment} </td>
			</tr>
		</c:forEach>
	</table>
	<br>
</c:if>


<c:if test="${not empty requestScope.RatingHistory}">
	<p>&nbsp;</p>
	
	<p>Ihre alten Bewertungen zu dieser Assoziation:</p>

	<table border="1" cellpadding="2" cellspacing="2">
		<tr>
			<th>&nbsp;</th> <th>Bewertung</th> <th>Version der Bewertung</th> <th>Kommentar</th>
		</tr>

		<c:forEach items="${requestScope.RatingHistory}" var="rating" varStatus="nr">
			<tr>
				<td align="right"> ${nr.count} </td>
				<td align="right"> <fmt:formatNumber value="${rating.value}" maxFractionDigits="2"/> </td>
				<td> ${rating.version} </td>
				<td> ${rating.comment} </td>
			</tr>
		</c:forEach>
	</table>	
	<br>
</c:if>
