<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	  xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
      layout:decorator="layout/mainLayout">
      
      <head>
        <title>Users - New</title>
    </head>
    <body>
    	<div layout:fragment="pageHeader">
          	<section class="content-header">
	        	<h1>
	            	Manage Users
	          	</h1>
	        </section>
        </div>
        
    	<div layout:fragment="content">
	        
              <div class="box box-warning">
                <div class="box-header with-border">
                  <h3 class="box-title">Create New User</h3>
                </div><!-- /.box-header -->
                <div class="box-body">
                  <form role="form" th:action="@{/users}" th:object="${user}" method="post">
                  	<p th:if="${#fields.hasErrors('global')}" th:errors="*{global}" th:class="text-red">Incorrect data</p>
                    <!-- text input -->
                    <div class="form-group" th:classappend="${#fields.hasErrors('name')}? 'has-error'">
                      <label>Name</label>
                      <input type="text" class="form-control" name="name" th:field="*{name}" placeholder="Enter User Name"/>
                      <p th:if="${#fields.hasErrors('name')}" th:errors="*{name}" th:class="text-red">Incorrect data</p>
                    </div>
                    
                    <div class="form-group" th:classappend="${#fields.hasErrors('email')}? 'has-error'">
                      <label>Email</label>
                      <input type="text" class="form-control" name="email" th:field="*{email}" placeholder="Enter User Email"/>
                      <p th:if="${#fields.hasErrors('email')}" th:errors="*{email}" th:class="text-red">Incorrect data</p>
                    </div>
                    
                    <div class="form-group" th:classappend="${#fields.hasErrors('password')}? 'has-error'">
                      <label>Password</label>
                      <input type="password" class="form-control" name="password" th:field="*{password}"  placeholder="Enter password"/>
                      <p th:if="${#fields.hasErrors('password')}" th:errors="*{password}" th:class="text-red">Incorrect data</p>
                    </div>
					
					<div class="form-group">
						<label>Roles</label>
						<div>
						  <p th:each="role,rowStat : ${rolesList}">
						    <input type="checkbox" th:field="*{roles[__${rowStat.index}__].id}" th:value="${role.id}" />
						    <label th:text="${role.name}">Role</label>
						  </p>
						</div>
						
    				</div>
    				
					<div class="box-footer">
	                    <button type="submit" class="btn btn-primary">Submit</button>
	                </div>
                  </form>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
    	</div>
    	
    </body>
    
</html>