79 |
|
|
80 |
}; |
}; |
81 |
|
|
82 |
|
use Jifty::View::Declare::CRUD; |
83 |
|
Jifty::View::Declare::CRUD->mount_view('materials'); |
84 |
|
|
85 |
|
use Jifty::View::Declare::CRUD; |
86 |
|
Jifty::View::Declare::CRUD->mount_view('units'); |
87 |
|
|
88 |
template '/units' => page { |
template '/units' => page { |
89 |
h1 { _("Units available in system") }; |
h1 { _("Units available in system") }; |
90 |
|
|
91 |
my $units = Arh::Model::UnitCollection->new; |
my $search = Arh::Model::UnitCollection->new; |
92 |
$units->unlimit; |
$search->unlimit; |
93 |
|
|
94 |
while ( my $u = $units->next ) { |
set( search_collection => $search ); |
95 |
unit( $u ); |
render_region( |
96 |
} |
name => 'units', |
97 |
}; |
path => '/units/list', |
98 |
|
defaults => { |
99 |
sub unit { |
page => 1, |
|
my $unit = shift || die "no unit?"; |
|
|
my $a = new_action( class => 'UpdateUnit', record => $unit ); |
|
|
form { |
|
|
foreach my $f ( qw/name number campaign material dimensions position description chronology location/ ) { |
|
|
my $can_write = $unit->current_user_can('write',$f); |
|
|
#warn "write $f ",$can_write ? 'ok' : 'DENIED'; |
|
|
if ( $f eq 'material' ) { |
|
|
set( UnitMaterialCollection => $unit->material ); |
|
|
show( '/unit/materials' ); |
|
|
} else { |
|
|
my %opt; |
|
|
$opt{render_mode} = 'read' if ! $unit->current_user_can('write',$f); |
|
|
render_param( $a => $f, %opt ); |
|
|
} |
|
100 |
} |
} |
101 |
} |
); |
|
} |
|
102 |
|
|
|
template '/unit/materials' => sub { |
|
|
my $materials = get('UnitMaterialCollection'); |
|
|
my $del_um = new_action( class => 'DeleteUnitMaterial', moniker => 'del_um' ); |
|
|
my $new_um = new_action( class => 'CreateUnitMaterial', moniker => 'new_um' ); |
|
|
my $can_write; |
|
|
while ( my $um = $materials->next ) { |
|
|
div { attr { class is 'form_field' } |
|
|
span { |
|
|
span { attr { class is 'label' } _("Material") }; |
|
|
span { $um->material->name }; |
|
|
|
|
|
$can_write ||= $um->current_user_can('write'); |
|
|
if ( $can_write ) { |
|
|
outs_raw($del_um->button( |
|
|
submit => $del_um, |
|
|
label => _('Delete'), |
|
|
arguments => { |
|
|
unit => $um->unit, |
|
|
material => $um->material |
|
|
}, |
|
|
)); |
|
|
} |
|
|
} |
|
|
}; |
|
|
|
|
|
if ( $can_write ) { |
|
|
render_param( |
|
|
$new_um => 'material', label => _("Material"), |
|
|
render_as => 'Arh::Web::Material', |
|
|
# cludge to transfer arguments |
|
|
hints => { |
|
|
unit => $um->unit, |
|
|
}, |
|
|
); |
|
|
} |
|
|
} |
|
103 |
}; |
}; |
104 |
|
|
105 |
1; |
1; |