1 |
dpavlin |
15 |
package Arh::View::Materials; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
|
|
use base 'Jifty::View::Declare::CRUD'; |
7 |
|
|
use Jifty::View::Declare -base; |
8 |
|
|
|
9 |
|
|
sub object_type { 'UnitMaterial' }; |
10 |
|
|
|
11 |
|
|
private template search_region => sub {}; |
12 |
|
|
|
13 |
|
|
sub display_columns { |
14 |
|
|
my $self = shift; |
15 |
|
|
return ('material'); |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
sub edit_columns { |
19 |
|
|
my $self = shift; |
20 |
|
|
return ('unit','material'); |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
template 'view' => sub :CRUDView { |
24 |
|
|
my $self = shift; |
25 |
|
|
my $record = $self->_get_record( get('id') ); |
26 |
|
|
|
27 |
|
|
my $update = $record->as_update_action( |
28 |
|
|
moniker => "update-" . Jifty->web->serial, |
29 |
|
|
); |
30 |
|
|
|
31 |
|
|
my $unit = get('unit'); |
32 |
|
|
warn "## new item for unit $unit"; |
33 |
|
|
|
34 |
|
|
div { |
35 |
|
|
{ class is 'form_field' }; |
36 |
|
|
if ( $record->current_user_can('update') ) { |
37 |
|
|
hyperlink( |
38 |
|
|
label => _("Edit"), |
39 |
|
|
class => "float-crud-button", |
40 |
|
|
onclick => { |
41 |
|
|
replace_with => $self->fragment_for('update'), |
42 |
|
|
args => { id => $record->id } |
43 |
|
|
}, |
44 |
|
|
as_button => 1, |
45 |
|
|
); |
46 |
|
|
} |
47 |
|
|
render_param( $update => 'material', render_mode => 'read' ); |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
}; |
51 |
|
|
|
52 |
|
|
template 'new_item' => sub { |
53 |
|
|
my $self = shift; |
54 |
|
|
my ( $object_type, $id ) = ( $self->object_type, get('id') ); |
55 |
|
|
|
56 |
|
|
my $record_class = $self->record_class; |
57 |
|
|
my $create = $record_class->as_create_action; |
58 |
|
|
my $unit = get('unit'); |
59 |
|
|
warn "## new item for unit $unit"; |
60 |
|
|
|
61 |
|
|
div { |
62 |
|
|
{ class is 'form_field' }; |
63 |
|
|
hyperlink( |
64 |
|
|
label => _("Add"), |
65 |
|
|
class => "float-crud-button", |
66 |
|
|
onclick => [ |
67 |
|
|
{ |
68 |
|
|
submit => $create, |
69 |
|
|
args => { |
70 |
|
|
# unit => $unit, |
71 |
|
|
}, |
72 |
|
|
}, |
73 |
|
|
{ refresh_self => 1 }, |
74 |
|
|
{ |
75 |
|
|
element => Jifty->web->current_region->parent->get_element( 'div.list' ), |
76 |
|
|
append => $self->fragment_for('view'), |
77 |
|
|
args => { |
78 |
|
|
object_type => $object_type, |
79 |
|
|
id => { result_of => $create, name => 'id' }, |
80 |
|
|
# unit => $unit, |
81 |
|
|
}, |
82 |
|
|
}, |
83 |
|
|
], |
84 |
|
|
as_button => 1, |
85 |
|
|
); |
86 |
|
|
render_param($create => 'material'); |
87 |
|
|
render_param($create => 'unit', default_value => $unit, reader_as => 'hidden'); |
88 |
|
|
} |
89 |
|
|
}; |
90 |
|
|
|
91 |
|
|
|
92 |
|
|
1; |