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