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

<%-- Queue picker lives in the shell's shared state toolbar (<shell:state moveSelector>), same
     row as the title, exactly like /user/process/queue's own layout. The process preview dialog
     saves/restores that shared area around itself (pl.kanban.js openPreview) so its own
     process.jsp content - which touches the same shared area - can't silently wipe this out. --%>

<c:set var="queues" value="${frd.queues}"/>

<c:choose>
	<c:when test="${empty queues}">
		${l.l("The user doesn't have allowed queues")}
	</c:when>
	<c:otherwise>
		<c:set var="queue" value="${frd.queue}"/>

		<c:set var="queueSelectUiid" value="${u:uiid()}"/>
		<ui:combo-single id="${queueSelectUiid}"
			value="${queue.id}"
			widthTextValue="18em"
			prefixText="${l.l('Очередь')}:"
			list="${queues}"
			onSelect="$$.ajax.loadContent('/user/plugin/kanban/board.do?method=show&queueId=' + this.value, this)"/>

		<shell:state moveSelector="#${queueSelectUiid}"/>

		<c:choose>
			<c:when test="${empty queue}">
				${l.l('Нет доступа к очереди')}
			</c:when>
			<c:otherwise>
				<c:set var="typeList" value="${frd.typeList}"/>
				<c:set var="selectedTypeId" value="${frd.selectedTypeId}"/>
				<c:set var="columns" value="${frd.columns}"/>
				<c:set var="cardsByStatus" value="${frd.cardsByStatus}"/>

				<div class="mt1 mb1"><%@ include file="filter.jsp"%></div>

				<c:choose>
					<c:when test="${selectedTypeId le 0}">
						${l.l('Выберите тип процесса')}
					</c:when>
					<c:otherwise>
						<c:set var="uiid" value="${u:uiid()}"/>
						<c:set var="canDrag" value="${ctxUser.checkPerm('/user/process:processStatusUpdate')}"/>
						<c:set var="previewEnabled" value="${frd.previewEnabled}"/>
						<c:set var="colorConfig" value="${ctxSetup.getConfig('org.bgerp.plugin.kanban.config.KanbanStatusColorConfig')}"/>

						<div id="${uiid}" class="kanban-board">
							<c:forEach var="status" items="${columns}" varStatus="colLoop">
								<c:set var="cards" value="${cardsByStatus[status.id]}"/>
								<div class="kanban-column" data-status-id="${status.id}">
									<div class="kanban-column-head" style="background-color: ${colorConfig.getColor(status.id, colLoop.index)}">
										${status.title} <span class="kanban-count">[${cards.size()}]</span>
									</div>
									<div class="kanban-column-body">
										<c:forEach var="card" items="${cards}">
											<%@ include file="card.jsp"%>
										</c:forEach>
									</div>
								</div>
							</c:forEach>
						</div>

						<script>
							$(function () {
								$$.kanban.initBoard($('#${uiid}'));
							});
						</script>
					</c:otherwise>
				</c:choose>
			</c:otherwise>
		</c:choose>
	</c:otherwise>
</c:choose>

<shell:title text="${l.l('Канбан')}${not empty queue ? ': '.concat(queue.title) : ''}"/>
