<%@ 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)"/>

	<ui:combo-single name="equipTypeId" value="${frd.equipTypeId}" widthTextValue="15em" styleClass="ml1"
		prefixText="${l.l('Тип оборудования')}:"
		onSelect="$$.ajax.loadContent(this.form, this)">
		<jsp:attribute name="valuesHtml">
			<li value="0">${l.l('Все')}</li>
			<c:forEach var="t" items="${frd.equipTypeMap}">
				<li value="${t.key}">${t.value.title}</li>
			</c:forEach>
		</jsp:attribute>
	</ui:combo-single>
</html:form>

<p:check action="/admin/plugin/inventory/device:deviceGet">
	<c:url var="addUrl" value="${form.requestURI}">
		<c:param name="method" value="deviceGet"/>
		<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>
		<td>${l.l('IP-адрес')}</td>
		<td>${l.l('Серийный номер')}</td>
	</tr>
	<c:forEach var="d" items="${frd.deviceList}">
		<c:url var="editUrl" value="${form.requestURI}">
			<c:param name="method" value="deviceGet"/>
			<c:param name="id" value="${d.id}"/>
			<c:param name="returnUrl" value="${form.requestUrl}"/>
		</c:url>
		<c:url var="deleteUrl" value="${form.requestURI}">
			<c:param name="method" value="deviceDelete"/>
			<c:param name="id" value="${d.id}"/>
		</c:url>
		<c:url var="restoreUrl" value="${form.requestURI}">
			<c:param name="method" value="deviceRestore"/>
			<c:param name="id" value="${d.id}"/>
		</c:url>
		<tr class="${d.deleted ? 'deleted' : ''}">
			<td nowrap="nowrap">
				<ui:button type="edit" styleClass="btn-small" onclick="$$.ajax.loadContent('${editUrl}', this)"/>
				<c:choose>
					<c:when test="${d.deleted}">
						<button type="button" class="btn-white icon btn-small" title="${l.l('Восстановить')}"
							onclick="$$.ajax.post('${restoreUrl}', {control: this}).done((r) => {
								if (r.data.error) { alert(r.data.error); } else { $$.ajax.loadContent('${form.requestUrl}', this); }
							}); return false;"><i class="ti-reload"></i></button>
					</c:when>
					<c:otherwise>
						<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:otherwise>
				</c:choose>
			</td>
			<td>${d.id}</td>
			<td>${d.name}</td>
			<td>${d.deviceTypeTitle}</td>
			<td>
				<c:choose>
					<c:when test="${d.status eq 'planned'}">${l.l('Планируется')}</c:when>
					<c:when test="${d.status eq 'active'}">${l.l('Активен')}</c:when>
					<c:when test="${d.status eq 'maintenance'}">${l.l('На обслуживании')}</c:when>
					<c:when test="${d.status eq 'decommissioned'}">${l.l('Выведен из эксплуатации')}</c:when>
					<c:otherwise>${d.status}</c:otherwise>
				</c:choose>
			</td>
			<td>${d.storeTitle}</td>
			<td>${d.ip}</td>
			<td>${d.serialNumber}</td>
		</tr>
	</c:forEach>
</table>

<shell:title text="${l.l('Оборудование')}"/>
