39 |
show( './paging_bottom', $collection, $page ); |
show( './paging_bottom', $collection, $page ); |
40 |
|
|
41 |
render_region( |
render_region( |
42 |
name => 'new_item', |
name => 'new_item', |
43 |
path => $fragment_for_new_item, |
path => $fragment_for_new_item, |
44 |
defaults => { |
defaults => { |
45 |
object_type => $self->object_type, |
object_type => $self->object_type, |
46 |
unit => $unit, |
unit => $unit, |
52 |
|
|
53 |
template 'view' => sub :CRUDView { |
template 'view' => sub :CRUDView { |
54 |
my $self = shift; |
my $self = shift; |
55 |
my $record = $self->_get_record( get('id') ); |
my ( $id, $unit ) = get(qw(id unit)); |
56 |
|
my $record = $self->_get_record( $id ); |
57 |
|
|
58 |
my $update = $record->as_update_action( |
my $delete = $record->as_delete_action( |
59 |
moniker => "update-" . Jifty->web->serial, |
moniker => "delete-" . Jifty->web->serial, |
60 |
); |
); |
61 |
|
|
62 |
my $unit = get('unit'); |
#warn "## unit $unit"; |
63 |
warn "## new item for unit $unit"; |
|
64 |
|
|
65 |
div { |
div { |
66 |
{ class is 'form_field' }; |
{ class is 'form_field' }; |
67 |
if ( $record->current_user_can('update') ) { |
if ( $record->current_user_can('delete') && $self->current_user->editing ) { |
68 |
hyperlink( |
hyperlink( |
69 |
label => _("Edit"), |
label => _("Delete material"), |
70 |
class => "float-crud-button", |
class => "float-crud-button button-delete", |
71 |
onclick => { |
onclick => { |
72 |
replace_with => $self->fragment_for('update'), |
submit => $delete, |
73 |
args => { id => $record->id } |
confirm => _('Really delete?'), |
74 |
|
replace_with => '/__jifty/empty', |
75 |
|
refresh_self => 1, |
76 |
|
args => { id => $id }, |
77 |
}, |
}, |
78 |
as_button => 1, |
as_button => 1, |
79 |
); |
); |
80 |
} |
}; |
81 |
render_param( $update => 'material', render_mode => 'read' ); |
label { { class is 'label' } _("Material") }; |
82 |
|
span { $record->material->name }; |
83 |
}; |
}; |
84 |
|
|
85 |
}; |
}; |
86 |
|
|
87 |
template 'new_item' => sub { |
template 'new_item' => sub { |
88 |
my $self = shift; |
my $self = shift; |
89 |
my ( $object_type, $id ) = ( $self->object_type, get('id') ); |
return unless $self->current_user->editing; |
90 |
|
|
91 |
|
my ( $id, $unit ) = get(qw(id unit)); |
92 |
|
my $record_class = $self->record_class; |
93 |
|
my $create = $record_class->as_create_action( |
94 |
|
moniker => "create-" . Jifty->web->serial, |
95 |
|
); |
96 |
|
warn "## unit $unit"; |
97 |
|
|
98 |
|
my $attach_to = |
99 |
|
Jifty->web->current_region->parent ? |
100 |
|
Jifty->web->current_region->parent->get_element( 'div.list' ) : |
101 |
|
Jifty->web->current_region; |
102 |
|
|
103 |
my $record_class = $self->record_class; |
warn "## attach_to = $attach_to"; |
|
my $create = $record_class->as_create_action; |
|
|
my $unit = get('unit'); |
|
|
warn "## new item for unit $unit"; |
|
104 |
|
|
105 |
div { |
div { |
106 |
{ class is 'form_field' }; |
{ class is 'form_field' }; |
107 |
hyperlink( |
hyperlink( |
108 |
label => _("Add"), |
label => _("Add material"), |
109 |
class => "float-crud-button", |
class => "float-crud-button button-add", |
110 |
onclick => [ |
onclick => [ |
111 |
{ |
{ |
112 |
submit => $create, |
submit => $create, |
|
args => { |
|
|
unit => $unit, |
|
|
}, |
|
113 |
}, |
}, |
114 |
{ refresh_self => 1 }, |
{ refresh_self => 1 }, |
115 |
{ |
{ |
116 |
element => Jifty->web->current_region->parent->get_element( 'div.list' ), |
element => $attach_to, |
117 |
append => $self->fragment_for('view'), |
append => $self->fragment_for('view'), |
118 |
args => { |
args => { |
119 |
object_type => $object_type, |
object_type => $self->object_type, |
120 |
id => { result_of => $create, name => 'id' }, |
id => { result_of => $create, name => 'id' }, |
121 |
|
unit => $unit, |
122 |
}, |
}, |
123 |
}, |
}, |
124 |
], |
], |
125 |
as_button => 1, |
as_button => 1, |
126 |
); |
); |
127 |
render_param($create => 'material'); |
render_param($create => 'material'); |
128 |
render_param($create => 'unit', default_value => $unit, reader_as => 'hidden'); |
outs_raw( $create->hidden( unit => $unit ) ); |
129 |
} |
}; |
130 |
}; |
}; |
131 |
|
|
132 |
|
|