transmet/templates/pages/categories.html

59 lines
2.2 KiB
HTML

{{define "body"}}
<h2 class="form-categories-heading">Categories</h2>
{{template "flashes" .}}
{{range $category := .categories}}
{{template "row-category" dict "category" $category "categories" $.categories "csrfField" $.csrfField}}
{{end}}
<div class="row">
<form method="POST" action="/categories/add" class="add-category">
<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 "fieldName" "parent"}}
</div>
<div class="col-xs-2">
{{ .csrfField }}
<input type="submit" class="add-submit btn btn-primary btn-block" value="Add Category" />
</div>
</form>
</div>
{{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"}}
<div class="row">
<div class="col-xs-2">
{{stringTimes .category.Depth "- "}}
{{.category.Name}}
</div>
<div class="col-xs-1">
<form method="POST" action="/categories/{{.category.Id}}/delete" class="cat-delete">{{ $.csrfField }}
<input type="submit" class="btn btn-default btn-sm btn-block" value="Delete" />
</form>
</div>
<div class="col-xs-3">
<form action="/categories/{{.category.Id}}/change-parent" method="POST" class="change-parent">
{{ .csrfField }}
<!-- select-category defined in layout -->
{{if $.category.Parent.Valid }}
{{template "select-category" dict "categories" .categories "id" $.category.Parent.Value "fieldName" "parent"}}
{{else}}
{{template "select-category" dict "categories" .categories "id" -1 "fieldName" "parent"}}
{{end}}
</form>
</div>
</div>
{{range $child := .category.Children}}
{{template "row-category" dict "category" $child "categories" $.categories "csrfField" $.csrfField}}
{{end}}
{{end}}