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

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

<h3 class="mb1">${l.l('Маппинг монтажников')} — ${inst.title}</h3>

<p:check action="/admin/plugin/sync1c/instance:mappingCreate">
	<c:url var="addUrl" value="/admin/plugin/sync1c/instance.do">
		<c:param name="method" value="mappingCreate"/>
		<c:param name="instanceId" value="${inst.id}"/>
		<c:param name="returnUrl" value="${form.requestUrl}"/>
	</c:url>
	<ui:button type="add" styleClass="mr1" onclick="$$.ajax.loadContent('${addUrl}')"/>
</p:check>

<c:url var="backUrl" value="/admin/plugin/sync1c/instance.do"/>
<button type="button" class="btn-white"
	onclick="$$.ajax.loadContent('${backUrl}')">&larr; ${l.l('Назад')}</button>

<table id="${uiid}" class="data mt1 hl">
	<tr>
		<td width="1em">&nbsp;</td>
		<td>ID</td>
		<td>${l.l('Монтажник')}</td>
		<td>${l.l('ID склада (1С)')}</td>
		<td>${l.l('Наименование склада (1С)')}</td>
		<td>${l.l('Локация (1С)')}</td>
		<td>${l.l('Склад ERP')}</td>
	</tr>
	<c:forEach var="ew" items="${frd.mappingList}">
		<c:set var="menuUiid" value="${u:uiid()}"/>
		<tr>
			<td>
				<ui:popup-menu id="${menuUiid}">
					<c:if test="${inst.protocol ne 'file'}">
						<p:check action="/admin/plugin/sync1c/instance:importNow">
							<c:url var="importUrl" value="/admin/plugin/sync1c/instance.do">
								<c:param name="method" value="importNow"/>
								<c:param name="ewId" value="${ew.id}"/>
							</c:url>
							<li><a href="#" onclick="
								$$.ajax.post('${importUrl}', {control: this}).done((r) => {
									if (r.data.error) { alert(r.data.error); }
									else { alert('OK: ' + r.data.synced + ' ${l.l('Позиций синхронизировано')}'); }
								}); return false;">
								<i class="ti-reload"></i> ${l.l('Импортировать сейчас')}</a></li>
						</p:check>
					</c:if>

					<p:check action="/admin/plugin/sync1c/instance:mappingDelete">
						<c:url var="delUrl" value="/admin/plugin/sync1c/instance.do">
							<c:param name="method" value="mappingDelete"/>
							<c:param name="id" value="${ew.id}"/>
						</c:url>
						<li><a href="#" onclick="
							if ($$.confirm.del()) $$.ajax.post('${delUrl}', {control: this}).done(() =>
								$$.ajax.loadContent('${form.requestUrl}')); return false;">
							<i class="ti-trash"></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>
			<td>${ew.id}</td>
			<td><ui:user-link id="${ew.userId}"/></td>
			<td><small>${ew.warehouseId}</small></td>
			<td>${ew.warehouseName}</td>
			<td>${ew.locationName}</td>
			<td>
				<c:choose>
					<c:when test="${ew.storeId gt 0}">#${ew.storeId}</c:when>
					<c:otherwise><span class="hint">— создастся при импорте</span></c:otherwise>
				</c:choose>
			</td>
		</tr>
	</c:forEach>
	<c:if test="${empty frd.mappingList}">
		<tr><td colspan="7" class="center">${l.l('Нет данных')}</td></tr>
	</c:if>
</table>

<shell:title text="${l.l('Маппинг монтажников')}"/>
