1 |
dpavlin |
6 |
package Arh::View; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use Jifty::View::Declare -base; |
7 |
|
|
|
8 |
|
|
use Data::Dump qw/dump/; |
9 |
|
|
|
10 |
|
|
template '/pictures' => page { |
11 |
|
|
my $fc = Arh::Model::PictureCollection->new; |
12 |
|
|
$fc->unlimit; |
13 |
|
|
my $present; |
14 |
|
|
form { |
15 |
dpavlin |
12 |
if ( $fc->count ) { |
16 |
|
|
h1 { _("Pictures available in system") }; |
17 |
|
|
} |
18 |
dpavlin |
6 |
table { |
19 |
|
|
while ( my $f = $fc->next ) { |
20 |
|
|
$present->{ $f->filename }++; |
21 |
|
|
my $delete = new_action( class => 'DeletePicture' ); |
22 |
dpavlin |
8 |
my $update = new_action( class => 'UpdatePicture', record => $f ); |
23 |
dpavlin |
6 |
row { |
24 |
|
|
cell { |
25 |
dpavlin |
12 |
attr { class => 'picture' }; |
26 |
dpavlin |
6 |
img { attr { src => "static/pics/" . $f->filename } } |
27 |
|
|
div { tt{ $f->filename } } |
28 |
|
|
} |
29 |
|
|
cell { |
30 |
dpavlin |
12 |
attr { class => 'picture-description' }; |
31 |
dpavlin |
8 |
render_param( $update => 'campaign', render_mode => 'read' ); |
32 |
|
|
render_param( $update => 'type', render_mode => 'read' ); |
33 |
dpavlin |
12 |
if ( $f->current_user_can('write') ) { |
34 |
|
|
div { |
35 |
|
|
$delete->button( |
36 |
|
|
submit => $delete, |
37 |
|
|
label => _('Delete'), |
38 |
|
|
arguments => { |
39 |
|
|
id => $f->id, |
40 |
|
|
} |
41 |
|
|
) |
42 |
|
|
} |
43 |
dpavlin |
7 |
} |
44 |
dpavlin |
6 |
} |
45 |
|
|
} |
46 |
|
|
} |
47 |
|
|
row { |
48 |
dpavlin |
12 |
cell { attr { colspan => 2 } h1 { _('Pending pictures') } } |
49 |
dpavlin |
6 |
}; |
50 |
|
|
warn "## present = ",dump( $present ); |
51 |
|
|
foreach my $f ( Arh::Model::Picture->all_filenames ) { |
52 |
|
|
next if $present->{$f}; |
53 |
|
|
my $create = new_action( class => 'CreatePicture' ); |
54 |
|
|
row { |
55 |
|
|
cell { |
56 |
dpavlin |
12 |
attr { class => 'picture' }; |
57 |
dpavlin |
6 |
img { attr { src => "static/pics/$f" } } |
58 |
|
|
div { tt{ $f } } |
59 |
|
|
} |
60 |
|
|
cell { |
61 |
dpavlin |
12 |
attr { class => 'picture-description' }; |
62 |
dpavlin |
7 |
render_param( $create => 'campaign' ); |
63 |
|
|
render_param( $create => 'type' ); |
64 |
dpavlin |
6 |
$create->button( |
65 |
|
|
submit => $create, |
66 |
|
|
label => _('Add'), |
67 |
|
|
arguments => { |
68 |
|
|
filename => $f, |
69 |
|
|
} |
70 |
dpavlin |
7 |
); |
71 |
dpavlin |
6 |
} |
72 |
|
|
} |
73 |
|
|
} |
74 |
|
|
} |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
}; |
78 |
|
|
|
79 |
dpavlin |
8 |
template '/units' => page { |
80 |
|
|
h1 { _("Units available in system") }; |
81 |
|
|
|
82 |
|
|
my $units = Arh::Model::UnitCollection->new; |
83 |
|
|
$units->unlimit; |
84 |
|
|
|
85 |
|
|
while ( my $u = $units->next ) { |
86 |
|
|
unit( $u ); |
87 |
|
|
} |
88 |
|
|
}; |
89 |
|
|
|
90 |
|
|
sub unit { |
91 |
|
|
my $unit = shift || die "no unit?"; |
92 |
|
|
my $a = new_action( class => 'UpdateUnit', record => $unit ); |
93 |
dpavlin |
11 |
warn "## current_user = ",dump( current_user ); |
94 |
dpavlin |
8 |
form { |
95 |
dpavlin |
9 |
foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) { |
96 |
dpavlin |
8 |
if ( $f eq 'material' ) { |
97 |
|
|
my $material = $unit->material; |
98 |
|
|
while ( my $um = $material->next ) { |
99 |
|
|
my $m = new_action( class => 'UpdateMaterial', record => $um->material ); |
100 |
|
|
render_param( $m => 'name', label => _("Material"), render_mode => 'read' ); |
101 |
|
|
} |
102 |
|
|
} else { |
103 |
dpavlin |
11 |
my %opt; |
104 |
|
|
$opt{render_mode} = 'read'; # unless |
105 |
|
|
warn "write $f ",$unit->current_user_can('write',$f) ? 'ok' : 'DENIED'; |
106 |
|
|
render_param( $a => $f, %opt ); |
107 |
dpavlin |
8 |
} |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
|
|
112 |
dpavlin |
6 |
1; |