<%-- 
    Document   : detectDsd
    Created on : 21.1.2018, 19:59:33
    Author     : themi
--%>
<%@ 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="DSD detection" />
</jsp:include>

<h2>Detect DSD</h2>
Upload DSD to detect DSD dimensions and DSD uri.
<c:url var="post_url"  value="<%= URL.DSD_DETECT_SUBMIT%>" />
<form:form action="${post_url}" method="POST" enctype="multipart/form-data" modelAttribute="detectDsdForm">
    <div class="input-group">
            <label class="input-group-btn">
                <span class="btn btn-primary">
                    Browse&hellip; <form:input path="DsdFile" type="file" style="display:none"/>
                </span>
            </label>
            <input id="fileCopy" type="text" class="form-control" readonly/>
            <script>
            $("#DsdFile").change(e => {
                $("#fileCopy").val(e.target.files[0].name);
            });
            </script>
    </div>
    <input class="btn btn-primary form-control" type="submit" value="Detect DSD" />
    <form:errors path="*" cssClass="error" />
</form:form>
    <c:if test="${validationResult ne null}"> 
        <hr class="hr-primary" />      
        <h4 style="color: red">Found errors in uploaded file. Cannot parse.</h4>
        <table class="table table-striped">
            <thead>
                <tr>
                  <th>Level</th>
                  <th>ErrorCode</th>
                  <th>Text</th>
                  <th>Line number</th>
                </tr>
            </thead>
            <c:forEach var="error" items="${validationResult.errors}">
                <tr>
                  <td>${error.type}</td>
                  <td>${error.errorCode}</td>
                  <td>${error.text}</td>
                  <td>${error.lineNumber}</td>
                </tr>     
            </c:forEach> 
        </table>
    </c:if>
<script>
    $("#detectDsdForm").submit(e => {
        setLoadingText("Detecting..");
        showLoading();
    });
</script>
<jsp:include page="reusable/footer.jsp" />