1 |
use strict; |
2 |
use warnings; |
3 |
|
4 |
package Transports::Model::Transport::Schema; |
5 |
use Jifty::DBI::Schema; |
6 |
|
7 |
use Transports::Model::Source; |
8 |
use Transports::Model::Destination; |
9 |
use Transports::Model::User; |
10 |
use Transports::Model::TransportClass; |
11 |
|
12 |
# Your column definitions go here. See L<Jifty::DBI::Schema> for |
13 |
# documentation about how to write column definitions. |
14 |
|
15 |
column date => |
16 |
type is 'timestamp', |
17 |
label is 'Date', |
18 |
render_as 'unrendered', |
19 |
since '0.0.1'; |
20 |
|
21 |
column class => |
22 |
refers_to Transports::Model::TransportClass, |
23 |
label is 'Transport class', |
24 |
is mandatory, |
25 |
since '0.0.11'; |
26 |
|
27 |
column source => |
28 |
refers_to Transports::Model::Source, |
29 |
label is 'Source client', |
30 |
# render_as 'Combobox', |
31 |
# sort_order is 'name', |
32 |
# render_as 'select', |
33 |
is mandatory, |
34 |
since '0.0.6'; |
35 |
|
36 |
column destination => |
37 |
refers_to Transports::Model::Destination, |
38 |
label is 'Destionation client', |
39 |
is mandatory, |
40 |
since '0.0.7'; |
41 |
|
42 |
column request_nr => |
43 |
type is 'text', |
44 |
label is 'Change request nr', |
45 |
is mandatory, |
46 |
since '0.0.7'; |
47 |
|
48 |
column client_dependent => |
49 |
type is 'boolean', |
50 |
label 'Client dependent', |
51 |
is mandatory, |
52 |
since '0.0.7', |
53 |
|
54 |
column description => |
55 |
type is 'text', |
56 |
label 'Description', |
57 |
render_as 'textarea', |
58 |
since '0.0.11'; |
59 |
|
60 |
column created_by => |
61 |
refers_to Transports::Model::User, |
62 |
label is 'Request by', |
63 |
since '0.0.7'; |
64 |
|
65 |
|
66 |
package Transports::Model::Transport; |
67 |
use base qw/Transports::Record/; |
68 |
use DateTime; |
69 |
|
70 |
# Your model-specific methods go here. |
71 |
|
72 |
=head2 create |
73 |
|
74 |
Create new transport and fill-in C<date> and C<created_by>. |
75 |
|
76 |
=cut |
77 |
|
78 |
sub create { |
79 |
my $self = shift; |
80 |
my %args = (@_); |
81 |
|
82 |
my $now = DateTime->now(); |
83 |
$args{'date'} = $now->ymd . " " . $now->hms; |
84 |
|
85 |
if (! $args{created_by}) { |
86 |
warn 'need $self->current_user' unless ($self->current_user); |
87 |
$args{created_by} = $self->current_user->user_object; |
88 |
} |
89 |
|
90 |
my ($id) = $self->SUPER::create(%args); |
91 |
return ($id); |
92 |
} |
93 |
|
94 |
=head2 current_user_can ACTION |
95 |
|
96 |
Let everybody create, read and update, but not delete. |
97 |
|
98 |
=cut |
99 |
|
100 |
sub current_user_can { |
101 |
my $self = shift; |
102 |
my $type = shift; |
103 |
|
104 |
# We probably want something like this eventually: |
105 |
if ($type =~ /(?:create|read|update)/i) { |
106 |
return 1; |
107 |
} else { |
108 |
return $self->SUPER::current_user_can($type, @_); |
109 |
} |
110 |
} |
111 |
|
112 |
|
113 |
1; |
114 |
|