/
Datagrid.blocks.latte
158 lines (144 loc) · 4.47 KB
/
Datagrid.blocks.latte
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
{**
* This file is part of the Nextras community extensions of Nette Framework
*
* @license MIT
* @link https://github.com/nextras
*}
{define table-open-tag}
<table>
{/define}
{define table-close-tag}
</table>
{/define}
{define global-filter-actions}
{input filter}
{if $showCancel}
{input cancel}
{/if}
{/define}
{define row-head-columns}
<tr class="grid-columns">
{foreach $columns as $column}
<th class="grid-col-{$column->name}">
{if $column->canSort()}
<a href="{link sort! orderColumn => $column->name, orderType => $column->getNewState()}" class="ajax">{$column->label}</a>
{if $column->isAsc()}
<span class="grid-sort-symbol grid-sort-symbol-asc"><em>▲</em></span>
{elseif $column->isDesc()}
<span class="grid-sort-symbol grid-sort-symbol-desc"><em>▼</em></span>
{else}
<span class="grid-sort-symbol grid-sort-symbol-no"></span>
{/if}
{else}
{$column->label}
{/if}
</th>
{/foreach}
{if $hasActionsColumn}
<th class="grid-col-actions">{ifset #global-actions}{include #global-actions}{/ifset}</th>
{/if}
</tr>
{/define}
{define col-filter}
{input $column->name}
{/define}
{define row-head-filter}
<tr class="grid-filters">
{formContainer filter}
{foreach $columns as $column}
<th class="grid-col-{$column->name}">
{if isset($form['filter'][$column->name])}
{ifset #col-filter-{$column->name}}
{include #"col-filter-{$column->name}" column => $column}
{else}
{include #col-filter column => $column}
{/ifset}
{/if}
</th>
{/foreach}
<th class="grid-col-actions">
{include #global-filter-actions showCancel => $showFilterCancel}
</th>
{/formContainer}
</tr>
{/define}
{define row-actions-edit}
{input save}
{input cancel}
{/define}
{define row-actions-edit-link}
<a href="{link edit! $primary}" class="ajax" data-datagrid-edit>{$control->translate(Edit)}</a>
{/define}
{define row}
<tr id={$rowId}>
{include #row-inner row => $row}
</tr>
{/define}
{define row-inner}
{var $primary = $control->getter($row, $rowPrimaryKey)}
{php if (!$sendOnlyRowParentSnippet): $this->global->snippetDriver->enter("rows-$primary", "dynamic"); endif;}
{var $editRow = $editRowKey == $primary && $primary !== NULL && $editRowKey !== NULL}
{foreach $columns as $column}
{var $cell = $control->getter($row, $column->name, FALSE)}
{if $editRow && $column->name != $rowPrimaryKey && isset($form['edit'][$column->name])}
<td class="grid-col-{$column->name}">
{formContainer edit}
{input $column->name}
{if $form[edit][$column->name]->hasErrors()}
<p class="error" n:foreach="$form[edit][$column->name]->getErrors() as $error">{$error}</p>
{/if}
{/formContainer}
</td>
{else}
{ifset #col-$column->name}
{include #"col-{$column->name}" row => $row, cell => $cell, iterator => $iterator}
{else}
<td class="grid-col-{$column->name}">
{ifset #cell-$column->name}
{include #"cell-{$column->name}" row => $row, cell => $cell, iterator => $iterator}
{else}
{$cell}
{/ifset}
</td>
{/ifset}
{/if}
{/foreach}
{if $hasActionsColumn}
<td class="grid-col-actions">
{if $editRow}
{formContainer edit}
{input $rowPrimaryKey class => 'grid-primary-value'}
{include #row-actions-edit}
{/formContainer}
{else}
{ifset #row-actions}
{include #row-actions row => $row, primary => $primary}
{elseif $control->getEditFormFactory()}
{include #row-actions-edit-link row => $row, primary => $primary}
{/ifset}
{/if}
</td>
{/if}
{php if (!$sendOnlyRowParentSnippet): $this->global->snippetDriver->leave(); endif;}
{/define}
{define pagination}
<div class="grid-paginator">
{if $paginator->isFirst()}
<span>« {$control->translate(First)}</span>
<span>« {$control->translate(Previous)}</span>
{else}
<a href="{link paginate!, 'page' => 1}" class="ajax">« {$control->translate(First)}</a>
<a href="{link paginate!, 'page' => $paginator->page - 1}" class="ajax">« {$control->translate(Previous)}</a>
{/if}
<span>
<span>{$paginator->page}</span> / <span>{$paginator->pageCount}</span>
</span>
{if $paginator->isLast()}
<span>{$control->translate(Next)} »</span>
<span>{$control->translate(Last)} »</span>
{else}
<a href="{link paginate!, 'page' => $paginator->page + 1}" class="ajax">{$control->translate(Next)} »</a>
<a href="{link paginate!, 'page' => $paginator->pageCount}" class="ajax">{$control->translate(Last)} »</a>
{/if}
</div>
{/define}