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

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

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

<table id="${uiid}" class="data mt1 hl">
	<tr>
		<td width="1em">&nbsp;</td>
		<td>ID</td>
		<td>${l.l('Наименование')}</td>
		<td>URL API</td>
		<td>${l.l('Активна')}</td>
	</tr>
	<c:forEach var="inst" items="${frd.instanceList}">
		<c:set var="menuUiid" value="${u:uiid()}"/>
		<tr class="${inst.enabled ? '' : 'inv-deleted'}">
			<td>
				<ui:popup-menu id="${menuUiid}">
					<p:check action="/admin/plugin/sync1c/instance:update">
						<c:url var="editUrl" value="/admin/plugin/sync1c/instance.do">
							<c:param name="method" value="create"/>
							<c:param name="id" value="${inst.id}"/>
							<c:param name="returnUrl" value="${form.requestUrl}"/>
						</c:url>
						<li><a href="#" onclick="$$.ajax.loadContent('${editUrl}'); return false;">
							<i class="ti-pencil"></i> ${l.l('Редактировать инстанцию')}</a></li>
					</p:check>

					<p:check action="/admin/plugin/sync1c/instance:testConnection">
						<c:url var="testUrl" value="/admin/plugin/sync1c/instance.do">
							<c:param name="method" value="testConnection"/>
							<c:param name="id" value="${inst.id}"/>
						</c:url>
						<li><a href="#" onclick="
							$$.ajax.post('${testUrl}', {control: this}).done((r) => {
								alert(r.data.error ? r.data.error : '${l.l('Соединение успешно')}');
							}); return false;">
							<i class="ti-plug"></i> ${l.l('Проверить соединение')}</a></li>
					</p:check>

					<p:check action="/admin/plugin/sync1c/instance:mappingList">
						<c:url var="mappingUrl" value="/admin/plugin/sync1c/instance.do">
							<c:param name="method" value="mappingList"/>
							<c:param name="instanceId" value="${inst.id}"/>
						</c:url>
						<li><a href="#" onclick="$$.ajax.loadContent('${mappingUrl}'); return false;">
							<i class="ti-user"></i> ${l.l('Маппинг монтажников')}</a></li>
					</p:check>

					<p:check action="/admin/plugin/sync1c/instance:importLog">
						<c:url var="logUrl" value="/admin/plugin/sync1c/instance.do">
							<c:param name="method" value="importLog"/>
							<c:param name="instanceId" value="${inst.id}"/>
						</c:url>
						<li><a href="#" onclick="$$.ajax.loadContent('${logUrl}'); return false;">
							<i class="ti-list"></i> ${l.l('Лог импортов')}</a></li>
					</p:check>

					<p:check action="/admin/plugin/sync1c/instance:exportLog">
						<c:url var="exportLogUrl" value="/admin/plugin/sync1c/instance.do">
							<c:param name="method" value="exportLog"/>
							<c:param name="instanceId" value="${inst.id}"/>
						</c:url>
						<li><a href="#" onclick="$$.ajax.loadContent('${exportLogUrl}'); return false;">
							<i class="ti-list"></i> ${l.l('Лог экспорта')}</a></li>
					</p:check>

					<p:check action="/admin/plugin/sync1c/instance:exportQueue">
					<c:url var="exportQueueUrl" value="/admin/plugin/sync1c/instance.do">
						<c:param name="method" value="exportQueue"/>
						<c:param name="instanceId" value="${inst.id}"/>
					</c:url>
					<li><a href="#" onclick="$$.ajax.loadContent('${exportQueueUrl}'); return false;">
						<i class="ti-arrow-up"></i> ${l.l('Очередь экспорта')}</a></li>
				</p:check>

				<p:check action="/admin/plugin/sync1c/instance:importPending">
					<c:url var="pendingUrl" value="/admin/plugin/sync1c/instance.do">
						<c:param name="method" value="importPending"/>
						<c:param name="instanceId" value="${inst.id}"/>
					</c:url>
					<li><a href="#" onclick="$$.ajax.loadContent('${pendingUrl}'); return false;">
						<i class="ti-download"></i> ${l.l('Ожидающие поступления')}</a></li>
				</p:check>

				<p:check action="/admin/plugin/sync1c/instance:delete">
						<c:url var="delUrl" value="/admin/plugin/sync1c/instance.do">
							<c:param name="method" value="delete"/>
							<c:param name="id" value="${inst.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>${inst.id}</td>
			<td>${inst.title}</td>
			<td>${inst.apiUrl}</td>
			<td>${inst.enabled ? '✓' : '—'}</td>
		</tr>
	</c:forEach>
	<c:if test="${empty frd.instanceList}">
		<tr><td colspan="5" class="center">${l.l('Нет данных')}</td></tr>
	</c:if>
</table>

<shell:title text="${l.l('Синхронизация с 1С')}"/>
