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

<c:set var="queue" value="${frd.queue}"/>
<c:set var="searchResult" value="${frd.searchResult}"/>
<c:set var="columns" value="${queue.properties.columns}"/>

<c:set var="pageFormSelector" value="#storeQueueFilter form"/>
<c:set var="nextCommand" value="; $$.ajax.load($('${pageFormSelector}'), $('#storeQueueData'), {control: this});"/>
<ui:page-control pageFormSelector="${pageFormSelector}" nextCommand="${nextCommand}"/>

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

<table class="data hl mt05" id="${tableUiid}">
	<tr>
		<td width="1em">&#160;</td>
		<c:forEach var="col" items="${columns}">
			<td>${col.title}</td>
		</c:forEach>
	</tr>
	<c:forEach var="row" items="${searchResult.list}">
		<c:set var="storeId" value="${row[0]}"/>
		<c:url var="showUrl" value="${form.requestURI}">
			<c:param name="method" value="show"/>
			<c:param name="id" value="${storeId}"/>
		</c:url>
		<c:set var="menuUiid" value="${u:uiid()}"/>
		<tr store-id="${storeId}">
			<td>
				<ui:popup-menu id="${menuUiid}">
					<p:check action="/user/plugin/inventory/store:show">
						<li><a href="#"
							onclick="$$.ajax.load('${showUrl}', $('#storeQueueData'), {control: this}); return false;">
							<i class="ti-eye"></i> ${l.l('Просмотр')}</a></li>
					</p:check>
					</ui:popup-menu>
				<ui:button type="more" styleClass="btn-small" onclick="$$.ui.menuInit($(this), $('#${menuUiid}'), 'left', true);"/>
			</td>
			<c:forEach var="col" items="${columns}" varStatus="colStatus">
				<td>
					<c:choose>
						<c:when test="${col.type eq 'deleted'}">
							<c:choose>
								<c:when test="${row[colStatus.index + 1] eq '1'}">${l.l('Да')}</c:when>
								<c:otherwise>${l.l('Нет')}</c:otherwise>
							</c:choose>
						</c:when>
						<c:otherwise>${row[colStatus.index + 1]}</c:otherwise>
					</c:choose>
				</td>
			</c:forEach>
		</tr>
	</c:forEach>
	<c:if test="${empty searchResult.list}">
		<tr><td colspan="${columns.size() + 1}" style="text-align: center;">${l.l('Нет данных')}</td></tr>
	</c:if>
</table>

<div>
	<ui:page-control pageFormSelector="${pageFormSelector}" nextCommand="${nextCommand}"/>
</div>

<script>
	$(function () {
		$$.ui.tableRowHl($('#${tableUiid}'));
		$$.doOnClick($('#${tableUiid}'), 'tr:gt(0)', function ($row) {
			var storeId = $row.attr('store-id');
			if (storeId) {
				var url = '${form.requestURI}?method=show&id=' + storeId;
				$$.ajax.load(url, $('#storeQueueData'));
			}
		});
	})
</script>
