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

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

<div class="mb1">
	<c:url var="rootUrl" value="${form.requestURI}">
		<c:param name="method" value="typeList"/>
		<c:param name="parentId" value="0"/>
	</c:url>
	<a href="#" onclick="$$.ajax.loadContent('${rootUrl}', this); return false;">${l.l('Типы номенклатуры')}</a>
	<c:forEach var="item" items="${frd.typePath}">
		<c:url var="pathUrl" value="${form.requestURI}">
			<c:param name="method" value="typeList"/>
			<c:param name="parentId" value="${item.id}"/>
		</c:url>
		/ <a href="#" onclick="$$.ajax.loadContent('${pathUrl}', this); return false;">${item.title}</a>
	</c:forEach>
</div>

<p:check action="/admin/plugin/inventory/itemType:typeGet">
	<c:url var="addUrl" value="${form.requestURI}">
		<c:param name="method" value="typeGet"/>
		<c:param name="parentId" value="${frd.parentId}"/>
		<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>
	</tr>
	<c:forEach var="item" items="${frd.typeList}">
		<c:url var="editUrl" value="${form.requestURI}">
			<c:param name="method" value="typeGet"/>
			<c:param name="id" value="${item.id}"/>
			<c:param name="parentId" value="${frd.parentId}"/>
			<c:param name="returnUrl" value="${form.requestUrl}"/>
		</c:url>
		<c:url var="deleteUrl" value="${form.requestURI}">
			<c:param name="method" value="typeDelete"/>
			<c:param name="id" value="${item.id}"/>
		</c:url>
		<c:url var="childUrl" value="${form.requestURI}">
			<c:param name="method" value="typeList"/>
			<c:param name="parentId" value="${item.id}"/>
		</c:url>
		<c:url var="propsUrl" value="${form.requestURI}">
			<c:param name="method" value="properties"/>
			<c:param name="id" value="${item.id}"/>
			<c:param name="returnUrl" value="${form.requestUrl}"/>
		</c:url>
		<tr>
			<td nowrap="nowrap">
				<ui:button type="edit" styleClass="btn-small" onclick="$$.ajax.loadContent('${editUrl}', this)"/>
				<ui:button type="del" styleClass="btn-small" onclick="
					if ($$.confirm.del()) $$.ajax.post('${deleteUrl}', {control: this}).done((r) => {
						if (r.data.error) { alert(r.data.error); } else { $$.ajax.loadContent('${form.requestUrl}', this); }
					}); return false;"/>
			</td>
			<td>${item.id}</td>
			<td>
				<a href="#" onclick="$$.ajax.loadContent('${childUrl}', this); return false;">${item.title}</a>
			</td>
			<td>${item.childCount}</td>
			<td>
				<c:choose>
					<c:when test="${item.useParentProperties}">[${l.l('наследуется')}]</c:when>
					<c:otherwise>
						<a href="#" onclick="$$.ajax.loadContent('${propsUrl}', this); return false;">[${l.l('свойства')}]</a>
					</c:otherwise>
				</c:choose>
			</td>
		</tr>
	</c:forEach>
</table>

<shell:title text="${l.l('Типы номенклатуры')}"/>
