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('Units', 'Arh::View::Units', '/units/bulk' ); |
15 |
|
#Jifty::View::Declare::CRUD->mount_view('locations'); |
16 |
|
|
17 |
|
template '/units' => page { |
18 |
|
h1 { _("Units available in system") }; |
19 |
|
|
20 |
|
my $search = Arh::Model::UnitCollection->new; |
21 |
|
$search->unlimit; |
22 |
|
|
23 |
|
show( 'toggle_edit' ) if $search->count; |
24 |
|
|
25 |
|
set( search_collection => $search ); |
26 |
|
render_region( |
27 |
|
name => 'units', |
28 |
|
path => '/units/list', |
29 |
|
defaults => { |
30 |
|
page => 1, |
31 |
|
per_page => get('per_page'), |
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 { |
form { |
53 |
table { |
outs_raw( $toggleedit->button( |
54 |
row { |
label => $label, |
55 |
cell { _('Part of campaign') } |
submit => $toggleedit, |
56 |
cell { _('Picture filename') } |
)); |
57 |
cell { _('Type of picture') } |
} |
58 |
cell {} |
|
59 |
}; |
}; |
60 |
while ( my $f = $fc->next ) { |
|
61 |
$present->{ $f->filename }++; |
template 'raw_pic' => sub { |
62 |
my $delete = new_action( class => 'DeletePicture' ); |
my $filename = get('filename') or die "no filename?"; |
63 |
row { |
my $image = Arh::Model::Picture->new; |
64 |
cell { $f->campaign->name } |
$image->load_by_cols( filename => $filename ); |
65 |
cell { |
if ( $image->id ) { |
66 |
img { attr { src => "static/pics/" . $f->filename } } |
Jifty->handler->apache->content_type('image/jpg'); |
67 |
div { tt{ $f->filename } } |
Jifty->web->out($image->content); |
68 |
} |
} else { |
69 |
cell { $f->type->name } |
die "can't find picture $filename"; |
70 |
cell { |
} |
71 |
$delete->button( |
}; |
72 |
submit => $delete, |
|
73 |
label => _('Delete'), |
template '/index.html' => page { |
74 |
arguments => { |
my $units = Arh::Model::UnitCollection->new; |
75 |
id => $f->id, |
$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 |
|
div { |
83 |
|
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 |
row { |
} |
95 |
cell { attr { colspan => 4 } outs _('Pending pictures') } |
} |
96 |
}; |
|
97 |
warn "## present = ",dump( $present ); |
ol { |
98 |
foreach my $f ( Arh::Model::Picture->all_filenames ) { |
class is 'units'; |
99 |
next if $present->{$f}; |
for ( 1 .. $last ) { |
100 |
my $create = new_action( class => 'CreatePicture' ); |
my $unit = $units->next || last; |
101 |
row { |
li { |
102 |
cell { render_param( $create => 'campaign' ) } |
outs( $unit->name, ' ' ); |
103 |
cell { |
hyperlink( |
104 |
img { attr { src => "static/pics/$f" } } |
label => $unit->unit_id, |
105 |
div { tt{ $f } } |
url => '/units/single?id=' . $unit->id, |
106 |
} |
); |
107 |
cell { render_param( $create => 'type' ) } |
span { class is 'unit details'; |
108 |
cell { |
outs join(', ', grep(defined($_), |
109 |
$create->button( |
$unit->subcategory, |
110 |
submit => $create, |
$unit->category->name, |
111 |
label => _('Add'), |
$unit->location->name, |
112 |
arguments => { |
$unit->site->name, |
113 |
filename => $f, |
)); |
|
} |
|
|
) |
|
|
} |
|
114 |
} |
} |
115 |
} |
} |
116 |
} |
} |