<%-- 
    Document   : updateUser
    Created on : 21.1.2018, 19:59:33
    Author     : themi
--%>
<%@ page import="cz.csu.sdmx.constants.*"%>
<%@ 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="scripts" value="jquery-ui.js" />
    <jsp:param name="stylesheets" value="jquery-ui.css" />
    <jsp:param name="title" value="Conditions" />
</jsp:include>
<h2>Update User</h2>
    <c:url var="post_url"  value="<%= URL.USER_UPDATE_SUBMIT%>" />
    <form:form action="${post_url}" method="POST" modelAttribute="user">
        <div class="form-group">
            <form:label path="personalNumber">Personal number</form:label>
            <form:input path="personalNumber" cssClass="form-control" readonly="true"/>
        </div>
        <div class="dimensions">
            <form:checkboxes items="${permissions}" path="permissions" element="p"/>
        </div>
        <hr class="hr-primary" />     
        <div class="input-group col-lg-5">
            <input type="text" id="urn" class="form-control" placeholder="Urn to add" value="">
            <div class="input-group-btn">
              <button id="addUrn" class="btn btn-default" style="width: 100px;" type="submit">
                <i class="glyphicon glyphicon-plus"></i>
              </button>
            </div>
        </div>
        <div class="allowedUrns">
            <c:forEach var="allowedUrn" items="${user.allowedUrns}">
                <div class="chip">
                    <form:input path="allowedUrns" hidden="true" value="${allowedUrn}" />
                    <c:out value="${allowedUrn}" />
                    <span class="closeChip" onclick="$(this).parent().remove();">&times;</span>
                </div>
            </c:forEach>
        </div>
        <input class="btn btn-primary form-control" type="submit" value="Update User" />
        <form:errors path="*" cssClass="error" />
    </form:form>
        ${updateResult}
    <script>
        $("#addUrn").click(e => {
            e.preventDefault();

           var urn = $("#urn").val();
           $(".allowedUrns").append(
                "<div class='chip'>"+
                    "<input id='allowedUrns' name='allowedUrns' hidden='true' value='"+urn+"'/>"+
                    urn+
                    "<span class='closeChip' onclick='$(this).parent().remove();'>&times;</span>"+
                "</div>"); 
        });
    </script>
<jsp:include page="reusable/footer.jsp" />


