<%-- 
    Document   : importConditions
    Created on : 21.1.2018, 19:59:33
    Author     : themi
--%>
<%@page import="java.util.List"%>
<%@page import="cz.csu.sdmx.validation.model.LogicCondition"%>
<%@page import="cz.csu.sdmx.web.security.User"%>
<%@page import="cz.csu.sdmx.constants.URL"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<jsp:include page="reusable/header.jsp">
    <jsp:param name="title" value="Conditions" />
</jsp:include>
    <h2>Import conditions</h2>
    <c:url var="post_url"  value="<%= URL.CONDITIONS_IMPORT_SUBMIT%>" />
    <form:form action="${post_url}" method="POST" enctype="multipart/form-data" modelAttribute="importConditionsForm">
        <div class="input-group">
                <label class="input-group-btn">
                    <span class="btn btn-primary">
                        Browse&hellip; <form:input path="ConditionsFile" type="file" style="display:none"/>
                    </span>
                </label>
                <input id="fileCopy" type="text" class="form-control" readonly/>
                <script>
                $("#ConditionsFile").change(e => {
                    $("#fileCopy").val(e.target.files[0].name);
                });
                </script>
        </div>
        <input class="btn btn-primary form-control" type="submit" value="Import conditions" />
        <form:errors path="*" cssClass="error" />
    </form:form>
    <hr>
    <c:forEach var="importResult" items="${importResults}" varStatus="status">
        <div class="panel">

            <c:set var="hasErrors" value="${importResult.errorCount != 0}" />
            <c:if test="${hasErrors}" ><c:set var="resultClass" value="hasErrors" /><c:set var="resultText" value="Not imported" /></c:if>
            <c:if test="${!hasErrors}" ><c:set var="resultClass" value="noErrors" /><c:set var="resultText" value="Imported" /></c:if>
            <!--<div class="btn-group result">-->
                <button class="btn ${resultClass} form-control" data-toggle="collapse" data-parent="#results" href="#${status.index}">
                <span class="pull-left">${importResult.expression}</span><span class="pull-right">${resultText}</span>
                </button>
            <!--</div>-->
            <div id="${status.index}" class="panel panel-collapse collapse" style="background-color: gainsboro">
                <div class="panel-body">
                    <c:forEach var="text" items="${importResult.errors}">
                    <div>${text}</div>
                    </c:forEach>
                </div>
                <c:if test="${hasErrors}" ><hr></c:if>
                
                <span style="white-space: pre-wrap">${importResult.json}</span>
            </div>
        </div>  
    </c:forEach>
<jsp:include page="reusable/footer.jsp" />


