7 |
|
|
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
|
10 |
template '/pictures' => page { |
use Jifty::View::Declare::CRUD; |
11 |
my $fc = Arh::Model::PictureCollection->new; |
Jifty::View::Declare::CRUD->mount_view('Materials'); |
12 |
$fc->unlimit; |
Jifty::View::Declare::CRUD->mount_view('UnitPictures'); |
13 |
my $present; |
Jifty::View::Declare::CRUD->mount_view('Units'); |
14 |
form { |
Jifty::View::Declare::CRUD->mount_view('Units', 'Arh::View::Units', '/units/bulk' ); |
15 |
if ( $fc->count ) { |
#Jifty::View::Declare::CRUD->mount_view('locations'); |
16 |
h1 { _("Pictures available in system") }; |
|
17 |
} |
template '/units' => page { |
18 |
table { |
h1 { _("Units available in system") }; |
19 |
while ( my $f = $fc->next ) { |
|
20 |
$present->{ $f->filename }++; |
my $search = Arh::Model::UnitCollection->new; |
21 |
my $delete = new_action( class => 'DeletePicture' ); |
$search->unlimit; |
22 |
my $update = new_action( class => 'UpdatePicture', record => $f ); |
|
23 |
row { |
show( 'toggle_edit' ) if $search->count; |
24 |
cell { |
|
25 |
attr { class => 'picture' }; |
set( search_collection => $search ); |
26 |
img { attr { src => "static/pics/" . $f->filename } } |
render_region( |
27 |
div { tt{ $f->filename } } |
name => 'units', |
28 |
} |
path => '/units/list', |
29 |
cell { |
defaults => { |
30 |
attr { class => 'picture-description' }; |
page => 1, |
31 |
render_param( $update => 'campaign', render_mode => 'read' ); |
per_page => get('per_page'), |
|
render_param( $update => 'type', render_mode => 'read' ); |
|
|
if ( $f->current_user_can('write') ) { |
|
|
div { |
|
|
$delete->button( |
|
|
submit => $delete, |
|
|
label => _('Delete'), |
|
|
arguments => { |
|
|
id => $f->id, |
|
|
} |
|
|
) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
row { |
|
|
cell { attr { colspan => 2 } h1 { _('Pending pictures') } } |
|
|
}; |
|
|
warn "## present = ",dump( $present ); |
|
|
foreach my $f ( Arh::Model::Picture->all_filenames ) { |
|
|
next if $present->{$f}; |
|
|
my $create = new_action( class => 'CreatePicture' ); |
|
|
row { |
|
|
cell { |
|
|
attr { class => 'picture' }; |
|
|
img { attr { src => "static/pics/$f" } } |
|
|
div { tt{ $f } } |
|
|
} |
|
|
cell { |
|
|
attr { class => 'picture-description' }; |
|
|
render_param( $create => 'campaign' ); |
|
|
render_param( $create => 'type' ); |
|
|
$create->button( |
|
|
submit => $create, |
|
|
label => _('Add'), |
|
|
arguments => { |
|
|
filename => $f, |
|
|
} |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
32 |
} |
} |
33 |
|
); |
34 |
|
|
35 |
|
}; |
36 |
|
|
37 |
|
template 'toggle_edit' => sub { |
38 |
|
my $self = shift; |
39 |
|
|
40 |
|
# don't show editing for anonymous users |
41 |
|
return unless $self->current_user->id; |
42 |
|
|
43 |
|
my $toggleedit = new_action( |
44 |
|
class => 'ToggleEdit', |
45 |
|
# moniker => 'toggle-edit', |
46 |
|
); |
47 |
|
|
48 |
|
my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing"); |
49 |
|
|
50 |
|
warn "## $label\n"; |
51 |
|
|
52 |
|
form { |
53 |
|
outs_raw( $toggleedit->button( |
54 |
|
label => $label, |
55 |
|
submit => $toggleedit, |
56 |
|
)); |
57 |
} |
} |
58 |
|
|
59 |
}; |
}; |
60 |
|
|
61 |
template '/units' => page { |
template 'raw_pic' => sub { |
62 |
h1 { _("Units available in system") }; |
my $filename = get('filename') or die "no filename?"; |
63 |
|
my $image = Arh::Model::Picture->new; |
64 |
|
$image->load_by_cols( filename => $filename ); |
65 |
|
if ( $image->id ) { |
66 |
|
Jifty->handler->apache->content_type('image/jpg'); |
67 |
|
Jifty->web->out($image->content); |
68 |
|
} else { |
69 |
|
die "can't find picture $filename"; |
70 |
|
} |
71 |
|
}; |
72 |
|
|
73 |
|
template '/index.html' => page { |
74 |
my $units = Arh::Model::UnitCollection->new; |
my $units = Arh::Model::UnitCollection->new; |
75 |
$units->unlimit; |
$units->unlimit; |
76 |
|
$units->order_by( column => 'id', order => 'DESC' ); |
77 |
|
|
78 |
|
my $last = get('last') || 15; |
79 |
|
|
80 |
|
h1 { _("Last %1 units entered", $last) }; |
81 |
|
|
82 |
while ( my $u = $units->next ) { |
div { |
83 |
unit( $u ); |
outs _('Limit:'); |
84 |
|
foreach my $new_last ( 15, 50, 100 ) { |
85 |
|
outs_raw ' '; |
86 |
|
if ( $new_last == $last ) { |
87 |
|
b { $new_last } |
88 |
|
} else { |
89 |
|
hyperlink( |
90 |
|
label => $new_last, |
91 |
|
url => '/?last=' . $new_last, |
92 |
|
); |
93 |
|
} |
94 |
|
} |
95 |
} |
} |
|
}; |
|
96 |
|
|
97 |
sub unit { |
ol { |
98 |
my $unit = shift || die "no unit?"; |
class is 'units'; |
99 |
my $a = new_action( class => 'UpdateUnit', record => $unit ); |
for ( 1 .. $last ) { |
100 |
warn "## current_user = ",dump( current_user ); |
my $unit = $units->next || last; |
101 |
form { |
li { |
102 |
foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) { |
outs( $unit->name, ' ' ); |
103 |
if ( $f eq 'material' ) { |
hyperlink( |
104 |
my $material = $unit->material; |
label => $unit->unit_id, |
105 |
while ( my $um = $material->next ) { |
url => '/units/single?id=' . $unit->id, |
106 |
my $m = new_action( class => 'UpdateMaterial', record => $um->material ); |
); |
107 |
render_param( $m => 'name', label => _("Material"), render_mode => 'read' ); |
span { class is 'unit details'; |
108 |
|
outs join(', ', grep(defined($_), |
109 |
|
$unit->subcategory, |
110 |
|
$unit->category->name, |
111 |
|
$unit->location->name, |
112 |
|
$unit->site->name, |
113 |
|
)); |
114 |
} |
} |
|
} else { |
|
|
my %opt; |
|
|
$opt{render_mode} = 'read'; # unless |
|
|
warn "write $f ",$unit->current_user_can('write',$f) ? 'ok' : 'DENIED'; |
|
|
render_param( $a => $f, %opt ); |
|
115 |
} |
} |
116 |
} |
} |
117 |
} |
} |
118 |
} |
|
119 |
|
}; |
120 |
|
|
121 |
1; |
1; |