<%@ 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" %>

<div class="FLOATFORMULAR">
	<c:if test="${requestScope.Attribute.version > requestScope.Rating.ratedVersion}">
		<span class="HINWEIS">Sie haben eine &auml;ltere Version dieses Attributs bewertet. Bitte pr&uuml;fen Sie, ob Ihre Bewertung noch zutrifft.</span><br>
	</c:if>
	<html:form action="changeattributerating?id=${requestScope.Topic.id}&amp;attrid=${requestScope.Attribute.id}">
		Ich stimme diesem Attribut
		<html:radio property="attrrating" value="YES">zu</html:radio>
		<html:radio property="attrrating" value="NO">nicht zu</html:radio>
		<html:radio property="attrrating" 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>

<h2>Attribut "${requestScope.Attribute.name}"</h2>
<p>(f&uuml;r Topic "<html:link action="topicview?id=${requestScope.Topic.id}">${requestScope.Topic.name}</html:link>")</p>

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

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


<div class="FORMULAR">

	<html:errors/>
	
	<div class="FLOATNOTE">
		Das Framework erlaubt auch das &Auml;ndern von Typ und Name des Attributs, die Beispielanwendung nutzt diese Methoden
		allerdings nicht. Hier m&uuml;sste das Attribut gel&ouml;scht (s.u.) und neu angelegt werden.
	</div>
	
	<html:form action="attributechange?id=${requestScope.Topic.id}&amp;attrid=${requestScope.Attribute.id}" focus="attrvalue">
		<p>Wert des Attributs:
		<br><html:text property="attrvalue"/>

		<p>Kommentar:
		<br><html:text property="attrcomment" size="60"/>
		
		<html:hidden property="attrid"/>
		<html:hidden property="topicid"/></p>
		
		<hr>

		<p><html:submit>&Auml;ndern</html:submit></p>
	</html:form>
	
	<p align="right"><html:link action="attributedelete?id=${requestScope.Topic.id}&amp;attrid=${requestScope.Attribute.id}">Dieses Attribut l&ouml;schen</html:link></p>
	
</div>


<c:if test="${requestScope.Attribute.ratingsCount > 0}">
	<p>&nbsp;</p>
	
	<p>Alle Bewertungen zu diesem Attribut:</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.Attribute.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 diesem Attribut:</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>
