/[transports]/trunk/lib/Transports/Model/Transport.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Transports/Model/Transport.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 90 - (show annotations)
Wed Jun 21 13:06:11 2006 UTC (17 years, 10 months ago) by dpavlin
File size: 2818 byte(s)
re-worked transports create (again), but now it works
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 use Transports::Model::ReturnCode;
12
13 # Your column definitions go here. See L<Jifty::DBI::Schema> for
14 # documentation about how to write column definitions.
15
16 column date =>
17 type is 'timestamp',
18 label is 'Date',
19 render_as 'unrendered',
20 since '0.0.1';
21
22 column class =>
23 refers_to Transports::Model::TransportClass,
24 label is 'Transport class',
25 is mandatory,
26 since '0.0.11';
27
28 column source =>
29 refers_to Transports::Model::Source,
30 label is 'Source client',
31 # render_as 'Combobox',
32 # sort_order is 'name',
33 # render_as 'select',
34 is mandatory,
35 since '0.0.6';
36
37 column destination =>
38 refers_to Transports::Model::Destination,
39 label is 'Destionation client',
40 is mandatory,
41 since '0.0.7';
42
43 column request_nr =>
44 type is 'text',
45 label is 'Change request nr',
46 is mandatory,
47 since '0.0.7';
48
49 column client_dependent =>
50 type is 'boolean',
51 label 'Client dependent',
52 is mandatory,
53 since '0.0.7',
54
55 column description =>
56 type is 'text',
57 label 'Description',
58 render_as 'textarea',
59 since '0.0.11';
60
61 column created_by =>
62 refers_to Transports::Model::User,
63 label is 'Request by',
64 since '0.0.7';
65
66 column return_code =>
67 refers_to Transports::Model::ReturnCode,
68 label is 'Return code',
69 since '0.0.12';
70
71 column comment =>
72 type is 'text',
73 label is 'Import comment',
74 render_as 'textarea',
75 since '0.0.12';
76
77 column landscape =>
78 refers_to Transports::Model::Landscape,
79 label is 'Part of landscape',
80 since '0.0.15';
81
82 package Transports::Model::Transport;
83 use base qw/Transports::Record/;
84 use DateTime;
85
86 # Your model-specific methods go here.
87
88 =head2 create
89
90 Create new transport and fill-in C<date> and C<created_by>.
91
92 =cut
93
94 sub create {
95 my $self = shift;
96 my %args = (@_);
97
98 my $now = DateTime->now();
99 $args{'date'} = $now->ymd . " " . $now->hms;
100
101 if (! $args{created_by}) {
102 warn 'need $self->current_user' unless ($self->current_user);
103 $args{created_by} = $self->current_user->user_object;
104 }
105
106 my ($id) = $self->SUPER::create(%args);
107 return ($id);
108 }
109
110 =head2 current_user_can ACTION
111
112 Let everybody create, read and update, but not delete.
113
114 =cut
115
116 sub current_user_can {
117 my $self = shift;
118 my $type = shift;
119
120 # We probably want something like this eventually:
121 if ($type =~ /(?:create|read|update)/i) {
122 return 1;
123 } else {
124 return $self->SUPER::current_user_can($type, @_);
125 }
126 }
127
128 =head2 validate_request_nr
129
130 =cut
131
132 sub validate_request_nr {
133 my $self = shift;
134 my $nr = shift;
135
136 return (0, 'Request number is required!') unless ($nr);
137
138 return (0, 'Request number should be number!') unless ($nr =~ m#^\d+$#);
139
140 return (1, 'OK');
141 }
142
143 1;
144

  ViewVC Help
Powered by ViewVC 1.1.26