2015-05-22 01:34:14 +00:00
|
|
|
{{define "body"}}
|
2015-07-05 05:20:01 +00:00
|
|
|
<h2 class="form-categories-heading">Categories</h2>
|
|
|
|
{{template "flashes" .}}
|
|
|
|
{{range $category := .categories}}
|
|
|
|
{{template "row-category" dict "category" $category "categories" $.categories}}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<form method="POST" action="/categories/add">
|
|
|
|
<div class="col-xs-3">
|
|
|
|
<input name="name" class="form-control" placeholder="Name" />
|
|
|
|
</div>
|
|
|
|
<div class="col-xs-3">
|
|
|
|
{{template "select-category" dict "categories" .categories "id" -1}}
|
|
|
|
</div>
|
|
|
|
<div class="col-xs-2">
|
|
|
|
<input type="submit" class="add-submit btn btn-primary btn-block" value="Add Category" />
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2015-05-22 01:34:14 +00:00
|
|
|
{{end}}
|
|
|
|
|
2015-07-05 05:20:01 +00:00
|
|
|
<!--
|
|
|
|
Print a category admin option row including it's name, delete option and
|
|
|
|
new category select
|
|
|
|
category: a category object - the current top level category to handle
|
|
|
|
categories: flat map of all categories, sorted by parents
|
|
|
|
-->
|
2015-05-22 01:34:14 +00:00
|
|
|
{{define "row-category"}}
|
2015-05-23 17:49:27 +00:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-xs-2">
|
|
|
|
{{stringTimes .category.Depth "- "}}
|
|
|
|
{{.category.Name}}
|
|
|
|
</div>
|
|
|
|
<div class="col-xs-1">
|
2015-07-09 04:44:55 +00:00
|
|
|
<a href="/categories/delete?id={{.category.Id}}" class="cat-delete">delete</a>
|
2015-05-23 17:49:27 +00:00
|
|
|
</div>
|
|
|
|
<div class="col-xs-3">
|
2015-06-21 18:42:05 +00:00
|
|
|
<form action="/categories/change-parent?cid={{.category.Id}}" method="POST">
|
2015-07-05 05:20:01 +00:00
|
|
|
{{if $.category.Parent.Valid }}
|
|
|
|
{{template "select-category" dict "categories" .categories "id" $.category.Parent.Value}}
|
|
|
|
{{else}}
|
|
|
|
{{template "select-category" dict "categories" .categories "id" -1}}
|
|
|
|
{{end}}
|
2015-06-21 18:42:05 +00:00
|
|
|
</form>
|
2015-05-23 17:49:27 +00:00
|
|
|
</div>
|
2015-05-22 05:55:59 +00:00
|
|
|
</div>
|
2015-05-22 06:04:30 +00:00
|
|
|
|
2015-05-23 17:49:27 +00:00
|
|
|
{{range $child := .category.Children}}
|
|
|
|
{{template "row-category" dict "category" $child "categories" $.categories}}
|
2015-05-22 01:34:14 +00:00
|
|
|
{{end}}
|
2015-05-22 06:04:30 +00:00
|
|
|
|
2015-05-22 05:55:59 +00:00
|
|
|
{{end}}
|
|
|
|
|
2015-07-05 05:20:01 +00:00
|
|
|
<!--
|
|
|
|
Print a full <select> of categories with one selected
|
|
|
|
categories: a flat map of categories ordered by parent
|
|
|
|
id: the category id that should be selected (or -1 for none)
|
|
|
|
-->
|
|
|
|
{{define "select-category"}}
|
|
|
|
<select class="form-control category-change-parent" name="parent" >
|
|
|
|
<option value="none" {{if not .category.Parent.Valid}} selected="true"{{end}}>-- None --</option>
|
|
|
|
{{range $category := .categories}}
|
|
|
|
{{template "option-category" dict "category" $category "id" $.id}}
|
|
|
|
{{end}}
|
|
|
|
</select>
|
|
|
|
{{end}}
|
|
|
|
<!--
|
|
|
|
print all the <option> inside a select for a category and its children
|
|
|
|
category: the category to print as an option (and it's nested children)
|
|
|
|
id: the category id that should be selected
|
|
|
|
-->
|
2015-05-22 05:55:59 +00:00
|
|
|
{{define "option-category"}}
|
2015-05-23 17:49:27 +00:00
|
|
|
<option value="{{.category.Id}}" {{if eq .id .category.Id}}selected="true"{{end}}>{{.category.ToString}}</option>
|
|
|
|
{{range $child := .category.Children}}
|
|
|
|
{{template "option-category" dict "category" $child "id" $.id}}
|
2015-07-05 05:20:01 +00:00
|
|
|
{{end}}
|
2015-05-22 01:34:14 +00:00
|
|
|
{{end}}
|