7 |
|
|
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
|
10 |
template '/pictures' => page { |
use Jifty::View::Declare::CRUD; |
11 |
h1 { _("Pictures available in system") }; |
Jifty::View::Declare::CRUD->mount_view('materials'); |
12 |
my $fc = Arh::Model::PictureCollection->new; |
Jifty::View::Declare::CRUD->mount_view('UnitPictures'); |
13 |
$fc->unlimit; |
Jifty::View::Declare::CRUD->mount_view('units'); |
14 |
my $present; |
#Jifty::View::Declare::CRUD->mount_view('locations'); |
15 |
form { |
|
16 |
table { |
template '/units' => page { |
17 |
while ( my $f = $fc->next ) { |
h1 { _("Units available in system") }; |
18 |
$present->{ $f->filename }++; |
|
19 |
my $delete = new_action( class => 'DeletePicture' ); |
my $search = Arh::Model::UnitCollection->new; |
20 |
row { |
$search->unlimit; |
21 |
cell { |
|
22 |
img { attr { src => "static/pics/" . $f->filename } } |
show( 'toggle_edit' ) if $search->count; |
23 |
div { tt{ $f->filename } } |
|
24 |
} |
set( search_collection => $search ); |
25 |
cell { |
render_region( |
26 |
ul { |
name => 'units', |
27 |
li { _("Part of campaign"), ': ', $f->campaign->name; } |
path => '/units/list', |
28 |
li { _("Type of picture"), ': ', $f->type->name } |
defaults => { |
29 |
div { $delete->button( |
page => 1, |
|
submit => $delete, |
|
|
label => _('Delete'), |
|
|
arguments => { |
|
|
id => $f->id, |
|
|
} |
|
|
) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
row { |
|
|
cell { attr { colspan => 4 } outs _('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 { |
|
|
img { attr { src => "static/pics/$f" } } |
|
|
div { tt{ $f } } |
|
|
} |
|
|
cell { |
|
|
render_param( $create => 'campaign' ); |
|
|
render_param( $create => 'type' ); |
|
|
$create->button( |
|
|
submit => $create, |
|
|
label => _('Add'), |
|
|
arguments => { |
|
|
filename => $f, |
|
|
} |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
30 |
} |
} |
31 |
|
); |
32 |
|
|
33 |
|
}; |
34 |
|
|
35 |
|
template 'toggle_edit' => sub { |
36 |
|
my $self = shift; |
37 |
|
|
38 |
|
my $toggleedit = new_action( |
39 |
|
class => 'ToggleEdit', |
40 |
|
# moniker => 'toggle-edit', |
41 |
|
); |
42 |
|
|
43 |
|
my $label = $self->current_user->editing ? _("Disable editing") : _("Enable editing"); |
44 |
|
|
45 |
|
warn "## $label\n"; |
46 |
|
|
47 |
|
form { |
48 |
|
outs_raw( $toggleedit->button( |
49 |
|
label => $label, |
50 |
|
submit => $toggleedit, |
51 |
|
)); |
52 |
} |
} |
53 |
|
|
54 |
}; |
}; |
55 |
|
|
56 |
|
template 'raw_pic' => sub { |
57 |
|
my $filename = get('filename') or die "no filename?"; |
58 |
|
my $image = Arh::Model::Picture->new; |
59 |
|
$image->load_by_cols( filename => $filename ); |
60 |
|
if ( $image->id ) { |
61 |
|
Jifty->handler->apache->content_type('image/jpg'); |
62 |
|
Jifty->web->out($image->content); |
63 |
|
} else { |
64 |
|
die "can't find picture $filename"; |
65 |
|
} |
66 |
|
}; |
67 |
|
|
68 |
1; |
1; |