Files
old-backend/app/views/qor/index/table.tmpl
2023-09-07 13:04:34 +02:00

57 lines
2.5 KiB
Cheetah

{{$context := .}}
{{$resource := .Resource}}
{{if len .Result}}
<table class="mdl-data-table mdl-js-data-table qor-table qor-js-table">
<thead>
<tr>
{{$order_by := $context.Request.URL.Query.Get "order_by"}}
{{$metas := convert_sections_to_metas $resource index_sections}}
{{range $index, $meta := $metas}}
{{$dbName := $meta.DBName}}
{{$is_sorted := eq $order_by $dbName}}
{{$is_desc_sorted := eq $order_by (print $dbName "_desc")}}
<th class="mdl-data-table__cell--non-numeric {{if is_sortable_meta $meta}}{{if (or $is_sorted $is_desc_sorted)}}is-sorted{{end}}{{end}}" data-heading="{{$meta.Name}}" {{if is_sortable_meta $meta}}{{if $is_sorted}}data-order-by="{{$dbName}}_desc"{{else}}data-order-by="{{$dbName}}"{{end}}{{end}}>{{meta_label $meta}}</th>
{{end}}
<th class="mdl-data-table__cell--non-numeric qor-table__actions"></th>
</tr>
</thead>
<tbody>
{{range $result := .Result}}
{{$primaryKey := primary_key_of $result}}
{{$uniqueKey := unique_key_of $result}}
<tr data-primary-key="{{$primaryKey}}" data-url="{{url_for $result $resource}}">
{{range $meta := $metas}}
{{$value := render_meta $result $meta}}
<td class="mdl-data-table__cell--non-numeric" data-heading="{{$meta.Name}}">
<div class="qor-table__content">{{$value}}</div>
</td>
{{end}}
<td class="mdl-data-table__cell--non-numeric qor-table__actions">
{{$allowed_actions := allowed_actions $resource.GetActions "menu_item" $result}}
{{if $allowed_actions}}
<button id="actions-for-{{$uniqueKey}}" class="mdl-button mdl-js-button mdl-button--icon qor-button--actions">
<i class="material-icons">more_vert</i>
</button>
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu" for="actions-for-{{$uniqueKey}}">
{{range $action := $allowed_actions}}
<li class="mdl-menu__item" qor-icon-name="{{$action.Name}}">
{{render_with "shared/action_item" (to_map "Action" $action "Result" $result "Context" $context "Resource" $resource "Mode" "menu_item")}}
</li>
{{end}}
</ul>
{{end}}
</td>
</tr>
{{end}}
</tbody>
</table>
{{else}}
<h2 class="qor-page__tips">{{t (printf "%v.tables.no_items" $resource.ToParam) (printf "No %v to show." (lower (plural $resource.Name)))}}</h2>
{{end}}