8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
|
10 |
template '/pictures' => page { |
template '/pictures' => page { |
|
h1 { _("Pictures available in system") }; |
|
11 |
my $fc = Arh::Model::PictureCollection->new; |
my $fc = Arh::Model::PictureCollection->new; |
12 |
$fc->unlimit; |
$fc->unlimit; |
13 |
my $present; |
my $present; |
14 |
form { |
form { |
15 |
|
if ( $fc->count ) { |
16 |
|
h1 { _("Pictures available in system") }; |
17 |
|
} |
18 |
table { |
table { |
19 |
while ( my $f = $fc->next ) { |
while ( my $f = $fc->next ) { |
20 |
$present->{ $f->filename }++; |
$present->{ $f->filename }++; |
21 |
my $delete = new_action( class => 'DeletePicture' ); |
my $delete = new_action( class => 'DeletePicture' ); |
22 |
|
my $update = new_action( class => 'UpdatePicture', record => $f ); |
23 |
row { |
row { |
24 |
cell { |
cell { |
25 |
|
attr { class => 'picture' }; |
26 |
img { attr { src => "static/pics/" . $f->filename } } |
img { attr { src => "static/pics/" . $f->filename } } |
27 |
div { tt{ $f->filename } } |
div { tt{ $f->filename } } |
28 |
} |
} |
29 |
cell { |
cell { |
30 |
ul { |
attr { class => 'picture-description' }; |
31 |
li { _("Part of campaign"), ': ', $f->campaign->name; } |
render_param( $update => 'campaign', render_mode => 'read' ); |
32 |
li { _("Type of picture"), ': ', $f->type->name } |
render_param( $update => 'type', render_mode => 'read' ); |
33 |
div { $delete->button( |
if ( $f->current_user_can('write') ) { |
34 |
|
div { |
35 |
|
$delete->button( |
36 |
submit => $delete, |
submit => $delete, |
37 |
label => _('Delete'), |
label => _('Delete'), |
38 |
arguments => { |
arguments => { |
44 |
} |
} |
45 |
} |
} |
46 |
} |
} |
47 |
row { |
warn "current_user->id: ",current_user->id; |
48 |
cell { attr { colspan => 4 } outs _('Pending pictures') } |
if ( current_user->id ) { |
|
}; |
|
|
warn "## present = ",dump( $present ); |
|
|
foreach my $f ( Arh::Model::Picture->all_filenames ) { |
|
|
next if $present->{$f}; |
|
|
my $create = new_action( class => 'CreatePicture' ); |
|
49 |
row { |
row { |
50 |
cell { |
cell { attr { colspan => 2 } h1 { _('Pending pictures') } } |
51 |
img { attr { src => "static/pics/$f" } } |
}; |
52 |
div { tt{ $f } } |
warn "## present = ",dump( $present ); |
53 |
} |
foreach my $f ( Arh::Model::Picture->all_filenames ) { |
54 |
cell { |
next if $present->{$f}; |
55 |
render_param( $create => 'campaign' ); |
my $create = new_action( class => 'CreatePicture' ); |
56 |
render_param( $create => 'type' ); |
row { |
57 |
$create->button( |
cell { |
58 |
submit => $create, |
attr { class => 'picture' }; |
59 |
label => _('Add'), |
img { attr { src => "static/pics/$f" } } |
60 |
arguments => { |
div { tt{ $f } } |
61 |
filename => $f, |
} |
62 |
} |
cell { |
63 |
); |
attr { class => 'picture-description' }; |
64 |
|
render_param( $create => 'campaign' ); |
65 |
|
render_param( $create => 'type' ); |
66 |
|
$create->button( |
67 |
|
submit => $create, |
68 |
|
label => _('Add'), |
69 |
|
arguments => { |
70 |
|
filename => $f, |
71 |
|
} |
72 |
|
); |
73 |
|
} |
74 |
} |
} |
75 |
} |
} |
76 |
} |
} |
79 |
|
|
80 |
}; |
}; |
81 |
|
|
82 |
|
template '/units' => page { |
83 |
|
h1 { _("Units available in system") }; |
84 |
|
|
85 |
|
my $units = Arh::Model::UnitCollection->new; |
86 |
|
$units->unlimit; |
87 |
|
|
88 |
|
while ( my $u = $units->next ) { |
89 |
|
unit( $u ); |
90 |
|
} |
91 |
|
}; |
92 |
|
|
93 |
|
sub unit { |
94 |
|
my $unit = shift || die "no unit?"; |
95 |
|
my $a = new_action( class => 'UpdateUnit', record => $unit ); |
96 |
|
form { |
97 |
|
foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) { |
98 |
|
my $can_write = $unit->current_user_can('write',$f); |
99 |
|
#warn "write $f ",$can_write ? 'ok' : 'DENIED'; |
100 |
|
if ( $f eq 'material' ) { |
101 |
|
set( UnitMaterialCollection => $unit->material ); |
102 |
|
show( '/unit/materials' ); |
103 |
|
} else { |
104 |
|
my %opt; |
105 |
|
$opt{render_mode} = 'read' if ! $unit->current_user_can('write',$f); |
106 |
|
render_param( $a => $f, %opt ); |
107 |
|
} |
108 |
|
} |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
|
template '/unit/materials' => sub { |
113 |
|
my $materials = get('UnitMaterialCollection'); |
114 |
|
my $del_um = new_action( class => 'DeleteUnitMaterial', moniker => 'del_um' ); |
115 |
|
my $new_um = new_action( class => 'CreateUnitMaterial', moniker => 'new_um' ); |
116 |
|
my $can_write; |
117 |
|
while ( my $um = $materials->next ) { |
118 |
|
div { attr { class is 'form_field' } |
119 |
|
span { |
120 |
|
span { attr { class is 'label' } _("Material") }; |
121 |
|
span { $um->material->name }; |
122 |
|
|
123 |
|
$can_write ||= $um->current_user_can('write'); |
124 |
|
if ( $can_write ) { |
125 |
|
outs_raw($del_um->button( |
126 |
|
submit => $del_um, |
127 |
|
label => _('Delete'), |
128 |
|
arguments => { |
129 |
|
unit => $um->unit, |
130 |
|
material => $um->material |
131 |
|
}, |
132 |
|
)); |
133 |
|
} |
134 |
|
} |
135 |
|
}; |
136 |
|
|
137 |
|
if ( $can_write ) { |
138 |
|
render_param( |
139 |
|
$new_um => 'material', label => _("Material"), |
140 |
|
render_as => 'Arh::Web::Material', |
141 |
|
# cludge to transfer arguments |
142 |
|
hints => { |
143 |
|
unit => $um->unit, |
144 |
|
}, |
145 |
|
); |
146 |
|
} |
147 |
|
} |
148 |
|
}; |
149 |
|
|
150 |
1; |
1; |