Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
130 lines (125 sloc) 6.54 KB
{{/*<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2016. Georg Beier. All rights reserved.
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->*/}}
<!-- {{/*
A reuseable template for form input fields formatted with bootstrap. The template is
called with a map or struct with the following keys or fields:
id: unique html element id
flabel: bootstrap formatting classes for the label part (optional)
finput: bootstrap formatting classes for the input part (optional)
caption: label caption for input field
title: html title attribute (optional)
icon: last part of the bootstrap glyphicon name to be used
itype: html type attribute for the input field
dot: the go template . (dot) value of the enclosing template (optional, if value is set)
value: preset value of input field. if value is empty, dot.id is used (optional, if dot is set)
tx: transcription of the value (optional)
style: additional style attributes (optional)
validate: validation attributes like 'required', 'min', 'pattern' etc. WARNING: this parameter is
escaped with HTMLAttr, so beware of letting user input get into it. This could easily be exploited!
def: define placeholder text for input fields (optional). If empty, caption parameter will be used for
field types "text" "tel" "email".
disabled: make input field disabled
default bootstrap formats:
label: $cfl := "control-label col-xs-4 col-sm-2 col-md-2 col-lg-1"
input: $cfi := "col-xs-8 col-sm-4 col-md-4 col-lg-2"
*/}} -->
{{define "forminput"}}
{{$cfl := "control-label col-xs-4 col-sm-2 col-md-2 col-lg-1" -}}
{{$cfi := "col-xs-8 col-sm-4 col-md-4 col-lg-2" -}}
<label for="{{.id}}" class="{{if .flabel}}{{.flabel}}{{else}}{{$cfl}}{{end}}">
{{.caption}}:
</label>
<div class="{{if .finput}}{{.finput}}{{else}}{{$cfi}}{{end}}" {{if .title}}title="{{.title}}" {{end -}}>
<div class="form-group">
<div class="input-group">
<span id="{{.id}}-icon" class="input-group-addon"><span class="glyphicon glyphicon-{{.icon}}"></span></span>
<input type="{{.itype}}" class="form-control"
value="{{if .value}}{{.value}}{{else if .dot}}{{index .dot .id}}{{end}}"
id="{{.id}}" name="{{.id}}" {{if .disabled}}{{safeatt .disabled}}{{end}}
{{if .validate}}{{safeatt .validate}} {{end -}} {{if .style}}style="{{.style}}" {{end -}}
{{if or .def (eq .itype "text" "tel" "email") }}
placeholder="{{if .def }}{{.def}}{{else}}{{.caption}}{{end}}"{{end -}}>
</div>
{{ if .tx }}<div style="padding: 4px 0px 0px 4em; font-weight: bold;">{{.tx}}</div>{{end -}}
<div class="help-block with-errors"></div>
</div>
</div>
{{end}}
{{/*
A reuseable template for form select fields formatted with bootstrap. The template is
called with a map or struct with the following keys or fields:
id: unique html element id, also index of value field of "dot"
range: index of range field of "dot"
flabel: bootstrap formatting classes for the label part (optional)
finput: bootstrap formatting classes for the input part (optional)
caption: label caption for input field
icon: last part of the bootstrap glyphicon name to be used
dot: the go template . (dot) value of the enclosing template (optional, if value is set)
value: preset value of input field. if value is empty, dot.id is used (optional, if dot is set)
style: additional style attributes (optional)
validate: validation attributes like 'required', 'min', 'pattern' etc. WARNING: this parameter is
escaped with HTMLAttr, so beware of letting user input get into it. This could easily be exploited!
disabled: make input field disabled
default bootstrap formats:
label: $cfl := "control-label col-xs-4 col-sm-2 col-md-2 col-lg-1"
input: $cfi := "col-xs-8 col-sm-4 col-md-4 col-lg-2"
*/}}
{{define "formselect"}}
{{$cfl := "control-label col-xs-4 col-sm-2 col-md-2 col-lg-1"}}
{{$cfi := "col-xs-8 col-sm-4 col-md-4 col-lg-2"}}
<label for="{{.id}}" class="{{if .flabel}}{{.flabel}}{{else}}{{$cfl}}{{end}}">
{{.caption}}:
</label>
<div class="{{if .finput}}{{.finput}}{{else}}{{$cfi}}{{end}}">
<div class=" form-group input-group">
<span id="{{.id }}-icon" class="input-group-addon"><span class="glyphicon glyphicon-{{.icon}}"></span></span>
<Select class="form-control" value="{{index .dot .id}}" id="{{ .id}}" name="{{.id}}"
{{if .validate}}{{safeatt .validate}} {{end -}} {{if .style}}style="{{.style}}" {{end -}}
{{if .disabled}}{{safeatt .disabled}}{{end}}>
{{if .validate}}
<option value="">------------</option>
{{end}}
{{ range $key, $val := (index .dot .range) }}
{{if iskind $val "struct" -}}
<option value="{{$val.ID}}" {{if eq $val.ID (index $.dot $.id)}} selected="true" {{end}}>
{{$val.Name}}
</option>
{{- else -}}
<option value="{{$key}}" {{if eq $key (index $.dot $.id)}} selected="true" {{end}}>{{$val}}</option>
{{- end -}}
{{end}}
</select>
</div>
</div>
{{end}}
{{define "csrf"}}
<input type="hidden" id="{{if .csrfid}}{{.csrfid}}{{else}}csrf_id{{end}}"
name="{{if .csrffield}}{{.csrffield}}{{else}}csrf_token{{end}}"
value="{{.csrftoken}}">
{{end}}
{{define "appid"}}
<input type="hidden" id="{{if .appid_id}}{{.appid_id}}{{else}}appid{{end}}"
name="{{if .appidfield}}{{.appidfield}}{{else}}appid{{end}}"
value="{{.appid}}">
{{end}}