8 |
|
|
9 |
=head1 Transports operations |
=head1 Transports operations |
10 |
|
|
11 |
=head2 new |
=head2 /transports/create/ |
12 |
|
|
13 |
new transport |
Select transport (if only one exists, it will be picked automatically) and |
14 |
|
create new stransport |
15 |
|
|
16 |
=cut |
=cut |
17 |
|
|
18 |
on 'new', run { |
under '/transports/create' => [ |
|
my $t = Jifty->web->new_action( |
|
|
class => 'CreateTransport', |
|
|
monkier => 'create', |
|
|
); |
|
19 |
|
|
20 |
set transport => $t; |
on 'landscape' => run { |
|
}; |
|
|
|
|
|
=head2 /edit/42 |
|
|
|
|
|
edit transport with request number C<42> |
|
|
|
|
|
=cut |
|
|
|
|
|
on qr'^/edit/(\d+)', run { |
|
|
my $id = $1; |
|
|
my $t = Transports::Model::Transport->new(); |
|
|
$t->load_by_cols( id => $id ); |
|
|
Jifty->web->redirect( '/new' ) unless ( $t->id ); |
|
|
|
|
|
set transport => Jifty->web->new_action( class => 'UpdateTransport', record => $t ); |
|
|
show('/edit'); |
|
|
}; |
|
|
|
|
|
=head1 User operations |
|
|
|
|
|
=head2 /user/42 |
|
21 |
|
|
22 |
edit user with id C<42> |
my $landscapes = Transports::Model::UserOnLandscapeCollection->new(); |
23 |
|
$landscapes->limit( |
24 |
|
column => 'user_on', |
25 |
|
value => Jifty->web->current_user->id, |
26 |
|
quote_value => 0, |
27 |
|
); |
28 |
|
$landscapes->order_by( column => 'landscape' ); |
29 |
|
|
30 |
|
if ($landscapes->count == 0) { |
31 |
|
show '/transports/create/no_landscape'; |
32 |
|
} elsif ($landscapes->count == 1) { |
33 |
|
$landscape_id = $landscapes->first->id; |
34 |
|
set 'landscape_id' => $landscape_id; |
35 |
|
dispatch('/transports/create/'); |
36 |
|
} else { |
37 |
|
set landscapes => $landscapes; |
38 |
|
show '/transports/create/landscape'; |
39 |
|
}; |
40 |
|
|
41 |
|
}, |
42 |
|
on '' => run { |
43 |
|
|
44 |
|
my $landscape_id = get('landscape_id'); |
45 |
|
redirect('/transports/create/landscape') unless ($landscape_id); |
46 |
|
|
47 |
|
my $transport = Jifty->web->new_action( |
48 |
|
class => 'CreateTransport', |
49 |
|
moniker => 'transports_create', |
50 |
|
); |
51 |
|
|
52 |
=cut |
my $l = Transports::Model::Landscape->new(); |
53 |
|
$l->load_by_cols( id => $landscape_id ); |
54 |
|
|
55 |
on qr'^/users?/?(\d*)', run { |
if (! $l->id) { |
56 |
my $id = $1; |
warn "Can't find landscape with id $landscape_id\n"; |
57 |
|
redirect('/transports/create/landscape'); |
58 |
|
} |
59 |
|
|
60 |
|
my $s = Transports::Model::SourceCollection->new(); |
61 |
|
$s->limit( |
62 |
|
column => 'landscape', |
63 |
|
value => $landscape_id, |
64 |
|
); |
65 |
|
# $transport->arguments->{'source'}->{'valid_values'}->[0]->{'collection'} = $s; |
66 |
|
|
67 |
if ($id) { |
my $d = Transports::Model::DestinationCollection->new(); |
68 |
my $u = Transports::Model::User->new(); |
$d->limit( |
69 |
$u->load_by_cols( id => $id ); |
column => 'landscape', |
70 |
|
value => $landscape_id, |
|
set user_id => $id; |
|
|
|
|
|
set user => Jifty->web->new_action( |
|
|
class => $u->id ? 'UpdateUser' : 'CreateUser', |
|
|
record => $u |
|
71 |
); |
); |
72 |
|
# $transport->arguments->{'destination'}->{'valid_values'}->[0]->{'collection'} = $d; |
73 |
|
|
74 |
show('/user_form'); |
set 'transport' => $transport; |
|
} else { |
|
|
my $u = Transports::Model::UserCollection->new(); |
|
|
$u->unlimit(); |
|
|
set users => $u; |
|
|
show('/users'); |
|
|
} |
|
|
}; |
|
75 |
|
|
76 |
=head1 Login and logout operations |
show '/transports/create/new'; |
77 |
|
}, |
78 |
|
]; |
79 |
|
|
80 |
=head2 login |
=head1 User operations |
81 |
|
|
82 |
=cut |
=cut |
83 |
|
|
84 |
on qr'^/login(/.*)?$', run { |
under '/users' => [ |
85 |
|
on '' => run { |
86 |
|
dispatch '/users/form' if ( get 'user_id' ); |
87 |
|
}, |
88 |
|
]; |
89 |
|
|
90 |
my $return_url = $1 || '/'; |
=head1 Login and logout operations |
|
|
|
|
set 'action' => |
|
|
Jifty->web->new_action( class => 'Login', moniker => 'loginbox' ); |
|
|
set 'next' => Jifty->web->request->continuation |
|
|
|| Jifty::Continuation->new( |
|
|
request => Jifty::Request->new( path => $return_url ) ); |
|
|
show '/login'; |
|
|
}; |
|
91 |
|
|
92 |
=head2 logout |
=head2 logout |
93 |
|
|
94 |
=cut |
=cut |
95 |
|
|
96 |
before 'logout', run { |
before '/logout', run { |
97 |
Jifty->web->request->add_action( |
Jifty->web->request->add_action( |
98 |
moniker => 'logout', |
moniker => 'logout', |
99 |
class => 'Transports::Action::Logout' |
class => 'Transports::Action::Logout' |
100 |
); |
); |
101 |
|
warn "added Transports::Action::Logout"; |
102 |
}; |
}; |
103 |
|
|
104 |
|
|
107 |
# sort, when we have that infrastructure. |
# sort, when we have that infrastructure. |
108 |
|
|
109 |
before '*', run { |
before '*', run { |
110 |
Jifty->api->allow(qr/^Jifty::Action::Devel/) |
|
111 |
|
my $url = Jifty->web->request->path; |
112 |
|
|
113 |
|
#warn "before url: $url"; |
114 |
|
|
115 |
|
next_rule if ($url eq '/' || $url =~ m#^/(?:login|logout|__jifty)/*#); |
116 |
|
|
117 |
|
Jifty->api->allow(qr/^Jifty::Action::Devel/) |
118 |
if Jifty->config->framework('DevelMode'); |
if Jifty->config->framework('DevelMode'); |
119 |
|
|
120 |
|
if (not Jifty->web->current_user->id) { |
121 |
|
warn "send user accessing $url to login form\n"; |
122 |
|
Jifty->web->tangent( url => '/login' ); |
123 |
|
} |
124 |
|
|
125 |
}; |
}; |
126 |
|
|
127 |
on qr'^/__jifty/edit/(.*?)/(.*)$', run { |
on qr'^/__jifty/edit/(.*?)/(.*)$', run { |