<%@ 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"/>
	<p:check action="/user/plugin/inventory/item:create">
		<c:url var="url" value="${form.requestURI}">
			<c:param name="method" value="create"/>
			<c:param name="returnUrl" value="${form.requestUrl}"/>
		</c:url>
		<ui:button type="add" styleClass="mr1" onclick="$$.ajax.load('${url}', $('#${uiid}').parent(), {control: this})"/>
	</p:check>

	<ui:toggle name="showDeleted" value="${frd.showDeleted}" prefixText="${l.l('Показать удалённые')}"
		styleClass="ml1" onChange="$$.ajax.load(this.form, $('#${uiid}').parent())"/>
</html:form>

<table id="${uiid}" class="data mt1 hl">
	<tr>
		<td width="1em">&nbsp;</td>
		<td>ID</td>
		<td>${l.l('Наименование')}</td>
	</tr>
	<c:forEach var="item" items="${frd.itemList}">
		<c:set var="menuUiid" value="${u:uiid()}"/>
		<tr class="${item.deleted ? 'inv-deleted' : ''}">
			<td>
				<ui:popup-menu id="${menuUiid}">
					<p:check action="/user/plugin/inventory/item:delete">
						<c:if test="${not item.deleted}">
							<c:url var="delUrl" value="${form.requestURI}">
								<c:param name="method" value="delete"/>
								<c:param name="id" value="${item.id}"/>
							</c:url>
							<li><a href="#"
								onclick="if ($$.confirm.del()) $$.ajax.post('${delUrl}', {control: this}).done(() => $$.ajax.load('${form.requestUrl}', $('#${uiid}').parent())); return false;">
								<i class="ti-trash"></i> ${l.l('Удалить')}</a></li>
						</c:if>
					</p:check>
				</ui:popup-menu>
				<ui:button type="more" styleClass="btn-small" onclick="$$.ui.menuInit($(this), $('#${menuUiid}'), 'left', true);"/>
			</td>
			<td>${item.id}</td>
			<td>${item.title}</td>
		</tr>
	</c:forEach>
</table>
