<!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>Categories - Edit</title>
    </head>
    <body>
    	        
    	<div layout:fragment="content">	        
              <div class="box box-warning">
                <div class="box-header">
                  <h3 class="box-title">Edit Categories</h3>
                  <div class="box-tools">
                    <div class="input-group" style="width: 150px;">
                    	<a class="btn btn-sm btn-default" th:href="@{/subcategory/new(id=${category.id})}"><i class="fa fa-plus-circle"></i> New Sub-Category</a>
                    </div>
                  </div>
                </div><!-- /.box-header --><!-- /.box-header -->
                <div class="box-body">
                  <form role="form" th:action="@{/categories/{id}(id=${category.id})}" th:object="${category}" method="post">
                  <p th:if="${#fields.hasErrors('global')}" th:errors="*{global}" th:class="text-red">Incorrect data</p>
                    <!-- text input -->
                    <div class="form-group">
                      <label>Id</label>
                      <input type="text" class="form-control" name="Id" th:field="*{id}" readonly="readonly"/>
                    </div>   
                    <div class="form-group">
                      <label>Name</label>
                      <input type="text" class="form-control" name="name" th:field="*{name}" />
                    </div> 
                    <div class="form-group">
                      <label>Description</label>
                      <textarea class="form-control" rows="3" name="description" th:field="*{description}" placeholder="Enter Category Description"></textarea>
                    </div>                                   		
					<div class="box-footer">
	                    <button type="submit" class="btn btn-primary">update</button>
	                </div>
                  </form> 
                  <div class="form-group">                  
                  <table class="table table-hover">
                    <tr>
                      <th style="width:80px">#</th>                      
                      <th>Sub-Category Name</th>
                    </tr>
                    </table>
                    <div th:each="cat,iterStat : ${subcategory}">
                    <form role="form" th:action="@{/subcategories/{id}(id=${cat.id})}" th:object="${subcategory}" method="post">
                      <input type="text" name="id" th:value="${cat.id}" readonly="readonly" size="5"/>
                      <input type="text" name="name" th:value="${cat.name}"/>                     
                      <button type="submit" class="btn btn-sm btn-default"><i class="fa fa-edit"></i>Update</button>
                    </form> 
                    </div>                   
                  </div>              
                </div><!-- /.box-body -->
              </div><!-- /.box -->
    	</div>
    	
    </body>
    
</html>