add category form, template rework, comments
This commit is contained in:
parent
d8f2c326a4
commit
3a18696bdf
|
@ -1,22 +1,35 @@
|
||||||
{{define "body"}}
|
{{define "body"}}
|
||||||
<h2 class="form-categories-heading">Categories</h2>
|
<h2 class="form-categories-heading">Categories</h2>
|
||||||
{{template "flashes" .}}
|
{{template "flashes" .}}
|
||||||
|
{{range $category := .categories}}
|
||||||
|
{{template "row-category" dict "category" $category "categories" $.categories}}
|
||||||
{{range $category := .categories}}
|
{{end}}
|
||||||
{{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>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
<!--
|
||||||
|
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
|
||||||
|
-->
|
||||||
{{define "row-category"}}
|
{{define "row-category"}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
|
|
||||||
<div class="col-xs-2">
|
<div class="col-xs-2">
|
||||||
{{stringTimes .category.Depth "- "}}
|
{{stringTimes .category.Depth "- "}}
|
||||||
|
|
||||||
|
|
||||||
{{.category.Name}}
|
{{.category.Name}}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-1">
|
<div class="col-xs-1">
|
||||||
|
@ -24,16 +37,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-3">
|
<div class="col-xs-3">
|
||||||
<form action="/categories/change-parent?cid={{.category.Id}}" method="POST">
|
<form action="/categories/change-parent?cid={{.category.Id}}" method="POST">
|
||||||
<select class="form-control category-change-parent" name="parent" >
|
{{if $.category.Parent.Valid }}
|
||||||
<option value="none" {{if not .category.Parent.Valid}} selected="true"{{end}}>-- None --</option>
|
{{template "select-category" dict "categories" .categories "id" $.category.Parent.Value}}
|
||||||
{{range $category := .categories}}
|
{{else}}
|
||||||
{{if $.category.Parent.Valid }}
|
{{template "select-category" dict "categories" .categories "id" -1}}
|
||||||
{{template "option-category" dict "category" $category "id" $.category.Parent.Value}}
|
{{end}}
|
||||||
{{else}}
|
|
||||||
{{template "option-category" dict "category" $category "id" -1}}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
</select>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,9 +52,27 @@
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
<!--
|
||||||
|
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
|
||||||
|
-->
|
||||||
{{define "option-category"}}
|
{{define "option-category"}}
|
||||||
<option value="{{.category.Id}}" {{if eq .id .category.Id}}selected="true"{{end}}>{{.category.ToString}}</option>
|
<option value="{{.category.Id}}" {{if eq .id .category.Id}}selected="true"{{end}}>{{.category.ToString}}</option>
|
||||||
{{range $child := .category.Children}}
|
{{range $child := .category.Children}}
|
||||||
{{template "option-category" dict "category" $child "id" $.id}}
|
{{template "option-category" dict "category" $child "id" $.id}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in New Issue