1 |
dpavlin |
15 |
package Arh::View::Units; |
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 { 'Unit' }; |
10 |
|
|
|
11 |
dpavlin |
23 |
sub display_columns { |
12 |
|
|
my $self = shift; |
13 |
|
|
return ( qw/name inv_id campaign material dimensions discovered_at description chronology location/ ); |
14 |
|
|
} |
15 |
|
|
|
16 |
dpavlin |
15 |
#private template search_region => sub {}; |
17 |
|
|
|
18 |
|
|
template 'view' => sub :CRUDView { |
19 |
|
|
my $self = shift; |
20 |
dpavlin |
23 |
my $id = get('id'); |
21 |
|
|
my $record = $self->_get_record( $id ); |
22 |
dpavlin |
15 |
|
23 |
|
|
my $update = $record->as_update_action( |
24 |
|
|
moniker => "update-" . Jifty->web->serial, |
25 |
|
|
); |
26 |
|
|
|
27 |
dpavlin |
23 |
my $delete = $record->as_delete_action( |
28 |
|
|
moniker => "delete-" . Jifty->web->serial, |
29 |
|
|
); |
30 |
|
|
my $editing = $record->current_user_can('write'); |
31 |
|
|
warn "## current_user_can('write') = $editing\n"; |
32 |
|
|
$editing = 0 unless $self->current_user->editing; |
33 |
|
|
warn "## editing ",$editing ? 'ok' : 'DENIED'; |
34 |
dpavlin |
15 |
|
35 |
dpavlin |
23 |
|
36 |
|
|
if ( $editing ) { |
37 |
|
|
form { |
38 |
|
|
outs_raw($delete->button( |
39 |
|
|
label => _('Delete'), |
40 |
|
|
class => 'float-crud-button', |
41 |
|
|
onclick => { |
42 |
|
|
submit => $delete, |
43 |
|
|
confirm => _('Really delete?'), |
44 |
|
|
# region => Jifty->web->current_region, |
45 |
|
|
replace_with => '/__jifty/empty', |
46 |
|
|
refresh_self => 1, |
47 |
|
|
args => { id => $id }, |
48 |
|
|
}, |
49 |
|
|
)); |
50 |
|
|
}; |
51 |
|
|
}; |
52 |
|
|
|
53 |
dpavlin |
15 |
form { |
54 |
dpavlin |
23 |
foreach my $f ( $self->display_columns ) { |
55 |
dpavlin |
15 |
if ( $f eq 'material' ) { |
56 |
|
|
set( search_collection => $record->material ); |
57 |
|
|
render_region( |
58 |
|
|
name => 'unit-materials', |
59 |
|
|
path => '/materials/list', |
60 |
|
|
defaults => { |
61 |
|
|
page => 1, |
62 |
|
|
unit => $record->id, |
63 |
|
|
} |
64 |
|
|
); |
65 |
|
|
} else { |
66 |
|
|
my %opt; |
67 |
dpavlin |
23 |
$opt{render_mode} = 'read' if ! $editing; |
68 |
dpavlin |
15 |
render_param( $update => $f, %opt ); |
69 |
|
|
} |
70 |
|
|
}; |
71 |
dpavlin |
23 |
if ( $editing ) { |
72 |
dpavlin |
20 |
div { |
73 |
|
|
{ class is 'submit_button' }; |
74 |
|
|
hyperlink( |
75 |
|
|
label => _('Update'), |
76 |
|
|
onclick => { |
77 |
|
|
submit => $update, |
78 |
|
|
refresh_self => 1, |
79 |
|
|
}, |
80 |
|
|
) |
81 |
|
|
}; |
82 |
|
|
} |
83 |
dpavlin |
15 |
}; |
84 |
|
|
hr {}; |
85 |
|
|
}; |
86 |
|
|
|
87 |
dpavlin |
23 |
template 'new_item' => sub { |
88 |
|
|
my $self = shift; |
89 |
|
|
return unless $self->current_user->editing; |
90 |
|
|
|
91 |
|
|
my ( $object_type, $id ) = ( $self->object_type, get('id') ); |
92 |
|
|
my $record_class = $self->record_class; |
93 |
|
|
my $create = $record_class->as_create_action; |
94 |
|
|
|
95 |
|
|
h1 { _("New unit") }; |
96 |
|
|
|
97 |
|
|
form { |
98 |
|
|
|
99 |
|
|
foreach my $f ( $self->display_columns ) { |
100 |
|
|
render_param( $create => $f ) unless $f eq 'material'; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
div { |
104 |
|
|
{ class is 'submit_button' }; |
105 |
|
|
hyperlink( |
106 |
|
|
label => _("Add"), |
107 |
|
|
onclick => [ |
108 |
|
|
{ |
109 |
|
|
submit => $create, |
110 |
|
|
# args => { |
111 |
|
|
# }, |
112 |
|
|
}, |
113 |
|
|
{ refresh_self => 1 }, |
114 |
|
|
{ |
115 |
|
|
element => Jifty->web->current_region->parent->get_element( 'div.list' ), |
116 |
|
|
append => $self->fragment_for('view'), |
117 |
|
|
args => { |
118 |
|
|
object_type => $object_type, |
119 |
|
|
id => { result_of => $create, name => 'id' }, |
120 |
|
|
unit => get('unit'), |
121 |
|
|
}, |
122 |
|
|
}, |
123 |
|
|
], |
124 |
|
|
as_button => 1, |
125 |
|
|
); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
}; |
129 |
|
|
}; |
130 |
|
|
|
131 |
dpavlin |
15 |
1; |