<%--
 * Copyright by Intland Software
 *
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Intland Software. ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Intland.
 *
 * $Revision$ $Date$
--%>

<%@ taglib uri="jstl-c" prefix="c" %>
<%@ taglib uri="jstl-fmt" prefix="fmt" %>
<%@ taglib uri="jstl-fn" prefix="fn" %>

<%@ taglib uri="struts-html" prefix="html" %>


<%@ taglib uri="taglib" prefix="tag" %>

<%@ taglib uri="uitaglib" prefix="ui" %>

<%--
	This JSP fragment shows the meta data about the current document/wiki page like revision number and last change date and user.

	This JSP fragment expects the ArtifactDto in the "Artifact" request parameter; this is either the current
	WikiPage or Document to show the meta data for...

	Also expected scope variables:
	${docComments} The list of comments/attachments for the document
	${pageChildren} The list of child pages, only for wiki documents
%>
<%-- get the artifact from request --%>
<c:set var="artifact" value="${requestScope.Artifact}" />
<%-- the url for properties of this page --%>
<c:set var="infoURL" value="${param.infoURL}" />
<%-- the prefix for ditchnet-tab, either "wiki-page" or "document" --%>
<c:set var="ditchnetPrefix" value="${param.ditchnetPrefix}" />
<%-- unlock URL or blank if user can not unlock --%>
<c:set var="unlockArtifactUrl" value="${param.unlockArtifactUrl}" />

<c:if test="${! empty artifact}">
	<div>
		<c:url var="pageInfoURL" value="${infoURL}" >
			<c:param name="doc_id" value="${artifact.id}" />
		</c:url>

		<%-- hard lock info --%>
		<c:if test="${! empty artifact.additionalInfo.lockedBy}">
			<span class="main high" title="Locking information">Currently locked by <tag:userLink user_id="${artifact.additionalInfo.lockedBy.id}" />.<c:if test="${! empty unlockArtifactUrl}"><a class="action" href="${unlockArtifactUrl}" title="Unlock">Unlock</a></c:if></span>
			<span class="pipe">|</span>
		</c:if>

		<%-- soft lock info --%>
		<c:if test="${PAGE_LOCKER.id gt 0}">
			<span class="main high" title="Editing information">Currently edited by <tag:userLink user_id="${PAGE_LOCKER.id}" />.</span>
			<span class="pipe">|</span>
		</c:if>

		<c:if test="${! empty artifact.additionalInfo.revision}">
			<c:if test="${artifact.age != -1 && artifact.age < 24*60*60*1000}">
				<a href="${pageInfoURL}&orgDitchnetTabPaneId=${ditchnetPrefix}-history"><img src="<c:url value="/images/new_tablet.gif"/>" title="Recently Updated"/></a>&nbsp;
			</c:if>

			<span class="main" title="Displayed version" >
				<a href="${pageInfoURL}&orgDitchnetTabPaneId=${ditchnetPrefix}-history">Version ${displayedRevision}</a>
			</span>

			<c:if test="${userCanDiffRevisions}">
				<span class="main">
				<c:url var="compareRevisionsUrl" value="/proj/wiki/compareWikiPageRevisions.spr">
					<c:param name="doc_id" value="${artifact.id}" />
					<c:param name="revision1" value="${displayedRevision}" />
					<c:param name="revision2" value="${displayedRevision - 1}" />
				</c:url>
				<c:set var="compare_versions_onclick" value="launch_url('${compareRevisionsUrl}',true);return false;" />
				(<a href="${compareRevisionsUrl}" onclick="${compare_versions_onclick}" title="Changes in this version">diff</a>)
				</span>
			</c:if>
		</c:if>

		<c:if test="${artifact.file}">
			&nbsp;
			<span class="low" title="Last modified by">
				(<tag:formatDate value="${displayedRevisionModifiedAt}" /> by <tag:userLink user_id="${displayedRevisionModifiedBy}" />)
			</span>
		</c:if>

		<c:if test="${isArtifactApprovalLicensed && artifact.approvalSupported}">
			<span class="pipe">|</span>
			<span class="main" title="Approval workflow">
				<a href="${pageInfoURL}&orgDitchnetTabPaneId=${ditchnetPrefix}-approvals">
					<c:choose>
						<c:when test="${!empty artifact.additionalInfo.approvalWorkflow}">
							Approval workflow &quot;<c:out value="${artifact.additionalInfo.approvalWorkflow.name}" />&quot;
						</c:when>
						<c:otherwise>
							No approval workflow
						</c:otherwise>
					</c:choose>
				</a>
			</span>
		</c:if>

		<c:if test="${docComments ne null}">
			<c:if test="${artifact.file}">
				<span class="pipe">|</span>
			</c:if>
			<span class="main" title="Comments and attachments">
				<a href="${pageInfoURL}&orgDitchnetTabPaneId=${ditchnetPrefix}-comments">
					<c:choose>
						<c:when test="${fn:length(docComments) > 1}">
							${fn:length(docComments)} comments and attachments
						</c:when>
						<c:when test="${fn:length(docComments) == 1}">
							1 comment and attachment
						</c:when>
						<c:otherwise>
							No comments or attachments
						</c:otherwise>
					</c:choose>
				</a>
			</span>
			<c:if test="${fn:length(docComments) > 0}">
				&nbsp;<span class="low" title="Last comment/attachment added">
						(<tag:formatDate value="${docComments[0].submittedAt}" />
							by <tag:userLink user_id="${docComments[0].submitter.id}" />)
						</span>
			</c:if>
		</c:if>

		<c:if test="${pageChildren ne null}">
			<span class="pipe">|</span>
			<span class="main" title="Children of page">
				<a href="${pageInfoURL}&orgDitchnetTabPaneId=${ditchnetPrefix}-children">
					<c:choose>
						<c:when test="${fn:length(pageChildren) > 1}">
							${fn:length(pageChildren)} child pages
						</c:when>
						<c:when test="${fn:length(pageChildren) == 1}">
							1 child page
						</c:when>
						<c:otherwise>
							No child pages
						</c:otherwise>
					</c:choose>
				</a>
			</span>
		</c:if>
	</div>
</c:if>