<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jspf/taglibs.jsp"%>

<c:set var="uiid" value="${u:uiid()}"/>
<c:set var="reloadScript">$$.ajax.loadContent('${form.requestUrl}');</c:set>

<%-- Add form (hidden by default) --%>
<html:form action="/admin/plugin/inventory/store" styleId="addAccess${uiid}" styleClass="in-mb1-all" style="display: none;">
	<input type="hidden" name="method" value="accessAdd"/>
	<input type="hidden" name="storeId" value="${frd.store.id}"/>

	<table>
		<tr>
			<td nowrap="nowrap">${l.l('Пользователь')}:</td>
			<td class="pl05">
				<ui:select-single name="userId" list="${ctxUserList}" style="width: 250px;"/>
			</td>
		</tr>
		<tr>
			<td nowrap="nowrap" class="pt05">${l.l('Период с')}:</td>
			<td class="pl05 pt05">
				<ui:date-time name="dateFrom" value="0"/>
				${l.l('по')}:
				<ui:date-time name="dateTo"/>
			</td>
		</tr>
	</table>

	<ui:button type="ok" onclick="$$.ajax.post(this).done(() => { ${reloadScript} })"/>
	<ui:button type="cancel" onclick="$('#addAccess${uiid}').hide(); $('#showAccess${uiid}').show();" styleClass="ml1"/>
</html:form>

<%-- Close period form (hidden by default) --%>
<html:form action="/admin/plugin/inventory/store" styleId="closeAccess${uiid}" style="display: none;" styleClass="in-inline-block">
	<input type="hidden" name="method" value="accessClose"/>
	<input id="closeId${uiid}" type="hidden" name="id" value=""/>

	${l.l('Закрыть с даты')}:
	<ui:date-time name="closeTo" value="0"/>

	<div class="in-ml1 ml1">
		<ui:button type="ok" onclick="$$.ajax.post(this).done(() => { ${reloadScript} })"/>
		<ui:button type="cancel" onclick="$('#closeAccess${uiid}').hide(); $('#showAccess${uiid}').show();"/>
	</div>
</html:form>

<%-- Main view --%>
<div id="showAccess${uiid}">
	<h4>${l.l('Доступ исполнителей')}
		<span class="normal">
			<p:check action="/admin/plugin/inventory/store:accessAdd">
				[<a href="#" onclick="$('#showAccess${uiid}').hide(); $('#addAccess${uiid}').show(); return false;">${l.l('Добавить')}</a>]
			</p:check>
		</span>
	</h4>

	<c:if test="${not empty frd.accessList}">
		<table class="data hl">
			<tr>
				<td width="80">&#160;</td>
				<td width="120">${l.l('Период с')}</td>
				<td width="120">${l.l('по')}</td>
				<td width="100%">${l.l('Пользователь')}</td>
			</tr>
			<c:forEach var="a" items="${frd.accessList}">
				<c:url var="deleteUrl" value="/admin/plugin/inventory/store.do">
					<c:param name="method" value="accessDelete"/>
					<c:param name="id" value="${a.id}"/>
				</c:url>
				<tr>
					<td nowrap="nowrap">
						<p:check action="/admin/plugin/inventory/store:accessDelete">
							<ui:button type="del" styleClass="btn-small"
								onclick="$$.ajax.post('${deleteUrl}', {control: this}).done(() => { ${reloadScript} })"/>
						</p:check>
						<p:check action="/admin/plugin/inventory/store:accessClose">
							<button type="button" class="btn-white btn-small icon" title="${l.l('Закрыть период')}"
								onclick="$('#closeId${uiid}').val(${a.id}); $('#showAccess${uiid}').hide(); $('#closeAccess${uiid}').show();"
							><i class="ti-control-skip-forward"></i></button>
						</p:check>
					</td>
					<td nowrap="nowrap">${tu.format(a.dateFrom, 'ymd')}</td>
					<td nowrap="nowrap">
						<c:choose>
							<c:when test="${not empty a.dateTo}">${tu.format(a.dateTo, 'ymd')}</c:when>
							<c:otherwise>${l.l('бессрочно')}</c:otherwise>
						</c:choose>
					</td>
					<td><ui:user-link id="${a.userId}"/></td>
				</tr>
			</c:forEach>
		</table>
	</c:if>
</div>
