6 |
use base 'Jifty::View::Declare::CRUD'; |
use base 'Jifty::View::Declare::CRUD'; |
7 |
use Jifty::View::Declare -base; |
use Jifty::View::Declare -base; |
8 |
|
|
9 |
|
use Data::Dump qw/dump/; |
10 |
|
|
11 |
sub object_type { 'Unit' }; |
sub object_type { 'Unit' }; |
12 |
|
|
13 |
|
sub per_page { |
14 |
|
my $per_page = get('per_page') || 5; |
15 |
|
warn "## Units per_page = $per_page\n"; |
16 |
|
return $per_page; |
17 |
|
}; |
18 |
|
|
19 |
sub display_columns { |
sub display_columns { |
20 |
my $self = shift; |
my $self = shift; |
21 |
return ( qw/ |
return ( qw/ |
38 |
toplogy |
toplogy |
39 |
technique |
technique |
40 |
description |
description |
41 |
contstruction |
construction |
42 |
iconography |
iconography |
43 |
decoration |
decoration |
44 |
motifs |
motifs |
56 |
sources |
sources |
57 |
bibliography |
bibliography |
58 |
copyright |
copyright |
59 |
|
material |
60 |
/ ); |
/ ); |
61 |
} |
} |
62 |
|
|
63 |
#private template search_region => sub {}; |
#private template search_region => sub {}; |
64 |
|
|
65 |
|
=for later |
66 |
|
|
67 |
|
template 'index.html' => page { |
68 |
|
my $self = shift; |
69 |
|
title is $self->object_type; |
70 |
|
form { |
71 |
|
render_region( |
72 |
|
name => $self->object_type.'-list', |
73 |
|
path => $self->fragment_base_path.'/list' |
74 |
|
); |
75 |
|
}; |
76 |
|
}; |
77 |
|
|
78 |
|
template 'list' => sub { |
79 |
|
my $self = shift; |
80 |
|
|
81 |
|
my ( $page ) = get('page'); |
82 |
|
|
83 |
|
my $item_path = get('item_path') || $self->fragment_for("view"); |
84 |
|
my $collection = $self->_current_collection(); |
85 |
|
|
86 |
|
if ( $self->per_page == 1 ) { |
87 |
|
warn "## bulk import get to last page\n"; |
88 |
|
$page = $collection->pager->last_page; |
89 |
|
} |
90 |
|
|
91 |
|
div { |
92 |
|
{class is 'crud-'.$self->object_type}; |
93 |
|
|
94 |
|
show('./search_region'); |
95 |
|
show( './paging_top', $collection, $page ); |
96 |
|
show( './paging_bottom', $collection, $page ); |
97 |
|
show( './list_items', $collection, $item_path ); |
98 |
|
show( './paging_bottom', $collection, $page ); |
99 |
|
|
100 |
|
show( './new_item_region'); |
101 |
|
} |
102 |
|
|
103 |
|
}; |
104 |
|
|
105 |
|
=cut |
106 |
|
|
107 |
|
private template 'paging_top' => sub { |
108 |
|
my $self = shift; |
109 |
|
my $collection = shift; |
110 |
|
my $page = shift || 1; |
111 |
|
|
112 |
|
if ( $collection->pager->last_page > 1 ) { |
113 |
|
span { |
114 |
|
{ class is 'page-count' }; |
115 |
|
outs( |
116 |
|
_( "Found %1 units, showing %2-%3 on page %4/%5", |
117 |
|
$collection->pager->total_entries, |
118 |
|
$collection->pager->first, |
119 |
|
$collection->pager->last, |
120 |
|
$page, |
121 |
|
$collection->pager->last_page |
122 |
|
) |
123 |
|
); |
124 |
|
} |
125 |
|
} |
126 |
|
}; |
127 |
|
|
128 |
|
|
129 |
template 'view' => sub :CRUDView { |
template 'view' => sub :CRUDView { |
130 |
my $self = shift; |
my $self = shift; |
131 |
my $id = get('id'); |
my $id = get('id'); |
145 |
|
|
146 |
div { { class is 'unit' } |
div { { class is 'unit' } |
147 |
|
|
148 |
if ( $editing ) { |
if ( $editing ) { |
|
form { |
|
149 |
outs_raw($delete->button( |
outs_raw($delete->button( |
150 |
label => _('Delete unit'), |
label => _('Delete unit'), |
151 |
class => 'float-crud-button button-delete', |
class => 'float-crud-button button-delete', |
159 |
}, |
}, |
160 |
)); |
)); |
161 |
}; |
}; |
|
}; |
|
|
|
|
162 |
|
|
|
form { |
|
163 |
foreach my $f ( $self->display_columns ) { |
foreach my $f ( $self->display_columns ) { |
164 |
if ( $f eq 'material' ) { |
if ( $f eq 'material' ) { |
165 |
set( search_collection => $record->material ); |
set( search_collection => $record->material ); |
173 |
); |
); |
174 |
} else { |
} else { |
175 |
my %opt; |
my %opt; |
176 |
$opt{render_mode} = 'read' if ! $editing; |
if ( ! $editing ) { |
177 |
|
$opt{render_mode} = 'read'; |
178 |
|
# skip fields without values |
179 |
|
$opt{render_as} = 'hidden' if ! defined( $update->record->$f ); |
180 |
|
} |
181 |
render_param( $update => $f, %opt ); |
render_param( $update => $f, %opt ); |
182 |
} |
} |
183 |
}; |
}; |
190 |
submit => $update, |
submit => $update, |
191 |
refresh_self => 1, |
refresh_self => 1, |
192 |
}, |
}, |
193 |
) |
); |
194 |
}; |
} |
195 |
} |
} |
|
}; |
|
196 |
|
|
197 |
}; # div class unit |
}; # div class unit |
198 |
|
|
205 |
my $self = shift; |
my $self = shift; |
206 |
return unless $self->current_user->editing; |
return unless $self->current_user->editing; |
207 |
|
|
208 |
my ( $object_type, $id ) = ( $self->object_type, get('id') ); |
my ( $object_type, $id ) = ( $self->object_type, get('id') ); |
209 |
my $record_class = $self->record_class; |
my $record_class = $self->record_class; |
210 |
my $create = $record_class->as_create_action; |
my $create = $record_class->as_create_action; |
211 |
|
|
212 |
h1 { _("New unit") }; |
h1 { _("New unit") }; |
213 |
|
|
214 |
form { |
div { |
215 |
|
|
216 |
foreach my $f ( $self->display_columns ) { |
foreach my $f ( $self->display_columns ) { |
217 |
# last if $f eq 'material' && ! $id; |
# last if $f eq 'material' && ! $id; |
218 |
render_param( $create => $f ); # unless $f eq 'material'; |
render_param( $create => $f ) unless $f eq 'material'; |
219 |
warn "## $f"; |
#warn "## $f"; |
220 |
} |
} |
221 |
|
|
222 |
div { |
div { |
242 |
], |
], |
243 |
as_button => 1, |
as_button => 1, |
244 |
); |
); |
245 |
} |
}; |
246 |
|
|
247 |
}; |
}; |
248 |
}; |
}; |