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('locations'); |
15 |
if ( $fc->count ) { |
|
16 |
h1 { _("Pictures available in system") }; |
template '/units' => page { |
17 |
} |
h1 { _("Units available in system") }; |
18 |
table { |
|
19 |
while ( my $f = $fc->next ) { |
my $search = Arh::Model::UnitCollection->new; |
20 |
$present->{ $f->filename }++; |
$search->unlimit; |
21 |
my $delete = new_action( class => 'DeletePicture' ); |
|
22 |
my $update = new_action( class => 'UpdatePicture', record => $f ); |
show( 'toggle_edit' ) if $search->count; |
23 |
row { |
|
24 |
cell { |
set( search_collection => $search ); |
25 |
attr { class => 'picture' }; |
render_region( |
26 |
img { attr { src => "static/pics/" . $f->filename } } |
name => 'units', |
27 |
div { tt{ $f->filename } } |
path => '/units/list', |
28 |
} |
defaults => { |
29 |
cell { |
page => 1, |
|
attr { class => 'picture-description' }; |
|
|
render_param( $update => 'campaign', render_mode => 'read' ); |
|
|
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, |
|
|
} |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
30 |
} |
} |
31 |
} |
); |
32 |
|
|
33 |
}; |
}; |
34 |
|
|
35 |
template '/units' => page { |
template 'toggle_edit' => sub { |
36 |
h1 { _("Units available in system") }; |
my $self = shift; |
37 |
|
|
38 |
|
# don't show editing for anonymous users |
39 |
|
return unless $self->current_user->id; |
40 |
|
|
41 |
|
my $toggleedit = new_action( |
42 |
|
class => 'ToggleEdit', |
43 |
|
# moniker => 'toggle-edit', |
44 |
|
); |
45 |
|
|
46 |
my $units = Arh::Model::UnitCollection->new; |
my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing"); |
|
$units->unlimit; |
|
47 |
|
|
48 |
while ( my $u = $units->next ) { |
warn "## $label\n"; |
49 |
unit( $u ); |
|
50 |
|
form { |
51 |
|
outs_raw( $toggleedit->button( |
52 |
|
label => $label, |
53 |
|
submit => $toggleedit, |
54 |
|
)); |
55 |
} |
} |
56 |
|
|
57 |
}; |
}; |
58 |
|
|
59 |
sub unit { |
template 'raw_pic' => sub { |
60 |
my $unit = shift || die "no unit?"; |
my $filename = get('filename') or die "no filename?"; |
61 |
my $a = new_action( class => 'UpdateUnit', record => $unit ); |
my $image = Arh::Model::Picture->new; |
62 |
warn "## current_user = ",dump( current_user ); |
$image->load_by_cols( filename => $filename ); |
63 |
form { |
if ( $image->id ) { |
64 |
foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) { |
Jifty->handler->apache->content_type('image/jpg'); |
65 |
if ( $f eq 'material' ) { |
Jifty->web->out($image->content); |
66 |
my $material = $unit->material; |
} else { |
67 |
while ( my $um = $material->next ) { |
die "can't find picture $filename"; |
|
my $m = new_action( class => 'UpdateMaterial', record => $um->material ); |
|
|
render_param( $m => 'name', label => _("Material"), render_mode => 'read' ); |
|
|
} |
|
|
} else { |
|
|
my %opt; |
|
|
$opt{render_mode} = 'read'; # unless |
|
|
warn "write $f ",$unit->current_user_can('write',$f) ? 'ok' : 'DENIED'; |
|
|
render_param( $a => $f, %opt ); |
|
|
} |
|
|
} |
|
68 |
} |
} |
69 |
} |
}; |
70 |
|
|
71 |
1; |
1; |