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

<c:set var="uiid" value="${u:uiid()}"/>

<html:form action="${form.requestURI}">
	<html:hidden property="method"/>
	<ui:toggle name="showDeleted" value="${frd.showDeleted}" prefixText="${l.l('Показать удалённые')}"
		onChange="$$.ajax.loadContent(this.form, this)"/>
</html:form>

<p:check action="/admin/plugin/inventory/store:storeGet">
	<c:url var="addUrl" value="${form.requestURI}">
		<c:param name="method" value="storeGet"/>
		<c:param name="returnUrl" value="${form.requestUrl}"/>
	</c:url>
	<ui:button type="add" onclick="$$.ajax.loadContent('${addUrl}', this)"/>
</p:check>

<table id="${uiid}" class="data mt1 hl">
	<tr>
		<td width="30">&#160;</td>
		<td width="40">ID</td>
		<td width="100%">${l.l('Наименование')}</td>
		<td>${l.l('Тип склада')}</td>
		<td>${l.l('Статус')}</td>
		<td>${l.l('Владелец')}</td>
	</tr>
	<c:forEach var="s" items="${frd.storeList}">
		<c:url var="editUrl" value="${form.requestURI}">
			<c:param name="method" value="storeGet"/>
			<c:param name="id" value="${s.id}"/>
			<c:param name="returnUrl" value="${form.requestUrl}"/>
		</c:url>
		<c:url var="deleteUrl" value="${form.requestURI}">
			<c:param name="method" value="storeDelete"/>
			<c:param name="id" value="${s.id}"/>
		</c:url>
		<tr class="${s.deleted ? 'deleted' : ''}">
			<td nowrap="nowrap">
				<ui:button type="edit" styleClass="btn-small" onclick="$$.ajax.loadContent('${editUrl}', this)"/>
				<c:if test="${not s.deleted}">
					<ui:button type="del" styleClass="btn-small" onclick="$$.ajax.post('${deleteUrl}', {control: this}).done((r) => {
						if (r.data.error) { alert(r.data.error); } else { $$.ajax.loadContent('${form.requestUrl}', this); }
					})"/>
				</c:if>
			</td>
			<td>${s.id}</td>
			<td>${s.title}</td>
			<td>${empty frd.typeMap[s.storeTypeId] ? '' : frd.typeMap[s.storeTypeId].title}</td>
			<td>${empty frd.statusMap[s.statusId] ? '' : frd.statusMap[s.statusId].title}</td>
			<td>
				<c:choose>
					<c:when test="${s.userId gt 0}"><ui:user-link id="${s.userId}"/></c:when>
					<c:otherwise>${l.l('Общий склад')}</c:otherwise>
				</c:choose>
			</td>
		</tr>
	</c:forEach>
</table>

<shell:title text="${l.l('Склады')}"/>
