Core

/views/components/edit/TableEdit.html (2.4 KB)

 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
{% import "{{{ .Package }}}/app/util" %}

{% func TableEditor(key string, columns util.FieldDescs, values util.ValueMap, action string, method string, title string) %}
<form action="{%s action %}" method="{%s method %}">
{%= TableEditorNoForm(key, columns, values, "", "", title) %}
</form>
{% endfunc %}

{% func TableEditorNoForm(key string, columns util.FieldDescs, values util.ValueMap, name string, value string, title string) %}
<div class="overflow full-width">
<table class="mt min-200 expanded">
<tbody>
{%= TableEditorNoTable(key, columns, values) %}
<tr>
{%- if name == "" -%}
<td colspan="2"><button type="submit">{%s title %}</button></td>
{%- else -%}
<td colspan="2"><button name="{%s name %}" value="{%s value %}" type="submit">{%s title %}</button></td>
{%- endif -%}
</tr>
</tbody>
</table>
</div>
{% endfunc %}

{% func TableEditorNoTable(key string, columns util.FieldDescs, values util.ValueMap) %}{% stripspace %}
{%- for _, arg := range columns -%}
{%- switch arg.Type -%}
{%- case "bool" -%}
{%= BoolTable(arg.Key, arg.TitleSafe(), values.GetBoolOr(arg.Key, arg.DefaultBool(), true), 3, arg.Description) %}
{%- case "textarea" -%}
{%= TextareaTable(arg.Key, "", arg.TitleSafe(), 12, values.GetStringOr(arg.Key, arg.Default, true), 3, arg.Description) %}
{%- case "number", "int" -%}
{%= IntTable(arg.Key, "", arg.TitleSafe(), values.GetIntOr(arg.Key, arg.DefaultInt(), true), 3, arg.Description) %}
{%- case "float" -%}
{%= FloatTable(arg.Key, "", arg.TitleSafe(), values.GetFloatOr(arg.Key, arg.DefaultFloat(), true), 3, arg.Description) %}
{%- case "uuid" -%}
{%- code u, _ := values.ParseUUID(arg.Key, true, true) -%}
{%= UUIDTable(arg.Key, "", arg.TitleSafe(), u, 3, arg.Description) %}
{%- case "select" -%}
{%= SelectTable(arg.Key, "", arg.TitleSafe(), values.GetStringOr(arg.Key, arg.Default, true), arg.Choices, nil, 3, arg.Description) %}
{%- case "radio" -%}
{%= RadioTable(arg.Key, arg.TitleSafe(), values.GetStringOr(arg.Key, arg.Default, true), arg.Choices, nil, 3, arg.Description) %}
{%- default -%}
{%= DatalistTable(arg.Key, "", arg.TitleSafe(), values.GetStringOr(arg.Key, arg.Default, true), arg.Choices, nil, 3, arg.Description) %}
{%- endswitch -%}
{%- endfor -%}
{% endstripspace %}{% endfunc %}