1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
| {% import ( "github.com/samber/lo"
"{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/views/components" ) %}
{% func Select(key string, id string, value string, opts []string, titles []string, indent int) %}{% stripspace %} <select name="{%s key %}"{% if id != `` %}{% space %}id="{%s id %}"{% endif %}> {% for idx, opt := range opts %} {% code title := opt if idx < len(titles) { title = titles[idx] } %} {%= components.Indent(true, indent + 1) %} {% if opt == value %} <option selected="selected" value="{%s opt %}">{%s title %}</option> {% else %} <option value="{%s opt %}">{%s title %}</option> {% endif %} {% endfor %} {%= components.Indent(true, indent) %} </select> {% endstripspace %}{% endfunc %}
{% func SelectVertical(key string, id string, title string, value string, opts []string, titles []string, indent int, help ...string) %}{% stripspace %} {%- code id = cutil.CleanID(key, id) -%} <div class="mb expanded"> {%= components.Indent(true, indent + 1) %} <label for="{%s id %}"><em class="title">{%s title %}</em></label> {%= components.Indent(true, indent + 1) %} <div class="mt">{%= Select(key, id, value, opts, titles, indent) %}</div> {%= components.Indent(true, indent) %} </div> {% endstripspace %}{% endfunc %}
{% func SelectTable(key string, id string, title string, value string, opts []string, titles []string, indent int, help ...string) %}{% stripspace %} {%- code id = cutil.CleanID(key, id) -%} <tr> {%= components.Indent(true, indent + 1) %} <th class="shrink"><label for="{%s id %}"{%= components.TitleFor(help) %}>{%s title %}</label></th> {%= components.Indent(true, indent + 1) %} <td>{%= Select(key, id, value, opts, titles, indent) %}</td> {%= components.Indent(true, indent) %} </tr> {% endstripspace %}{% endfunc %}
{% func Datalist(key string, id string, value string, opts []string, titles []string, indent int, placeholder ...string) %}{% stripspace %} {%= components.Indent(true, indent ) %} <input id="{%s id %}" list="{%s id %}-list" name="{%s key %}" value="{%s value %}"{%= components.PlaceholderFor(placeholder) %} /> {%= components.Indent(true, indent ) %} {%- if len(opts) > 0 -%} <datalist id="{%s id %}-list"> {% for idx, opt := range opts %} {% code title := opt if idx < len(titles) { title = titles[idx] } %} {%= components.Indent(true, indent + 1) %} <option value="{%s opt %}">{%s title %}</option> {% endfor %} {%= components.Indent(true, indent) %} </datalist> {%- endif -%} {% endstripspace %}{% endfunc %}
{% func DatalistVertical(key string, id string, title string, value string, opts []string, titles []string, indent int, help ...string) %}{% stripspace %} {%- code id = cutil.CleanID(key, id) -%} <div class="mb expanded"> {%= components.Indent(true, indent + 1) %} <label for="{%s id %}"><em class="title">{%s title %}</em></label> {%= components.Indent(true, indent + 1) %} <div class="mt">{%= Datalist(key, id, value, opts, titles, indent) %}</div> {%= components.Indent(true, indent) %} </div> {% endstripspace %}{% endfunc %}
{% func DatalistTable(key string, id string, title string, value string, opts []string, titles []string, indent int, help ...string) %}{% stripspace %} {%- code id = cutil.CleanID(key, id) -%} <tr> {%= components.Indent(true, indent + 1) %} <th class="shrink"><label for="{%s id %}"{%= components.TitleFor(help) %}>{%s title %}</label></th> {%= components.Indent(true, indent + 1) %} <td>{%= Datalist(key, id, value, opts, titles, indent) %}</td> {%= components.Indent(true, indent) %} </tr> {% endstripspace %}{% endfunc %}
{% func Radio(key string, value string, opts []string, titles []string, indent int) %}{% stripspace %} {% for idx, opt := range opts %} {% code title := opt if idx < len(titles) { title = titles[idx] } %} {%= components.Indent(true, indent) %} {% if opt == value %} <label class="radio-label"><input type="radio" name="{%s key %}" value="{%s opt %}" checked="checked" />{% space %}{%s title %}</label> {% else %} <label class="radio-label"><input type="radio" name="{%s key %}" value="{%s opt %}" />{% space %}{%s title %}</label> {% endif %} {% endfor %} {% endstripspace %}{% endfunc %}
{% func RadioVertical(key string, title string, value string, opts []string, titles []string, indent int, help ...string) %}{% stripspace %} <div class="mb expanded"> {%= components.Indent(true, indent + 1) %} <div>{%= components.TitleFor(help) %}>{%s title %}</div> {%= components.Indent(true, indent + 1) %} <div class="mt"> {%= Radio(key, value, opts, titles, indent + 2) %} {%= components.Indent(true, indent + 1) %} </div> {%= components.Indent(true, indent) %} </div> {% endstripspace %}{% endfunc %}
{% func RadioTable(key string, title string, value string, opts []string, titles []string, indent int, help ...string) %}{% stripspace %} <tr> {%= components.Indent(true, indent + 1) %} <th class="shrink"><label {%= components.TitleFor(help) %}>{% space %}{%s title %}</label></th> {%= components.Indent(true, indent + 1) %} <td> {%= Radio(key, value, opts, titles, indent + 2) %} {%= components.Indent(true, indent + 1) %} </td> {%= components.Indent(true, indent) %} </tr> {% endstripspace %}{% endfunc %}
{% func Checkbox(key string, values []string, opts []string, titles []string, indent int) %}{% stripspace %} {% for idx, opt := range opts %} {% code title := opt if idx < len(titles) { title = titles[idx] } %} {%= components.Indent(true, indent) %} {% if lo.Contains(values, opt) %} <label><input type="checkbox" name="{%s key %}" value="{%s opt %}" checked="checked" />{% space %}{%s title %}</label> {% else %} <label><input type="checkbox" name="{%s key %}" value="{%s opt %}" />{% space %}{%s title %}</label> {% endif %} {% endfor %} {% endstripspace %}{% endfunc %}
{% func CheckboxVertical(key string, title string, values []string, opts []string, titles []string, indent int, help ...string) %}{% stripspace %} <div class="mb expanded"> {%= components.Indent(true, indent + 1) %} <div>{%s title %}</div> {%= components.Indent(true, indent + 1) %} <div class="mt"> {%= Checkbox(key, values, opts, titles, indent + 2) %} {%= components.Indent(true, indent + 1) %} </div> {%= components.Indent(true, indent) %} </div> {% endstripspace %}{% endfunc %}
{% func CheckboxTable(key string, title string, values []string, opts []string, titles []string, indent int, help ...string) %}{% stripspace %} <tr> {%= components.Indent(true, indent + 1) %} <th class="shrink"><label>{%s title %}</label></th> {%= components.Indent(true, indent + 1) %} <td class="checkboxes"> {%= Checkbox(key, values, opts, titles, indent + 2) %} {%= components.Indent(true, indent + 1) %} </td> {%= components.Indent(true, indent) %} </tr> {% endstripspace %}{% endfunc %}
|