1 |
package Transports::Dispatcher; |
2 |
use Jifty::Dispatcher -base; |
3 |
|
4 |
# Default page |
5 |
#on '/', run { |
6 |
# redirect( '/new'); |
7 |
#}; |
8 |
|
9 |
=head1 Transports operations |
10 |
|
11 |
=head2 /edit/42 |
12 |
|
13 |
edit transport with request number C<42> |
14 |
|
15 |
=cut |
16 |
|
17 |
on qr'^/edit/(\d+)', run { |
18 |
my $id = $1; |
19 |
my $t = Transports::Model::Transport->new(); |
20 |
$t->load_by_cols( id => $id ); |
21 |
Jifty->web->redirect( '/new' ) unless ( $t->id ); |
22 |
|
23 |
set transport => Jifty->web->new_action( class => 'UpdateTransport', record => $t ); |
24 |
show('/edit'); |
25 |
}; |
26 |
|
27 |
=head2 /import/42 |
28 |
|
29 |
import transport with request number C<42> |
30 |
|
31 |
=cut |
32 |
|
33 |
on qr'^/import/(\d+)', run { |
34 |
my $id = $1; |
35 |
my $t = Transports::Model::Transport->new(); |
36 |
$t->load_by_cols( id => $id ); |
37 |
Jifty->web->redirect( '/transports' ) unless ( $t->id ); |
38 |
|
39 |
set transport => Jifty->web->new_action( class => 'UpdateTransport', record => $t ); |
40 |
show('/import'); |
41 |
}; |
42 |
|
43 |
=head1 User operations |
44 |
|
45 |
=head2 /user/42 |
46 |
|
47 |
edit user with id C<42> |
48 |
|
49 |
=cut |
50 |
|
51 |
on qr'^/user/(\d+)', run { |
52 |
my $u = Transports::Model::User->new(); |
53 |
$u->load_by_cols( id => $1 ); |
54 |
|
55 |
set user_id => $1; |
56 |
|
57 |
set user => Jifty->web->new_action( |
58 |
class => $u->id ? 'UpdateUser' : 'CreateUser', |
59 |
record => $u |
60 |
); |
61 |
|
62 |
show('/user_form'); |
63 |
}; |
64 |
|
65 |
=head1 Login and logout operations |
66 |
|
67 |
=head2 login |
68 |
|
69 |
=cut |
70 |
|
71 |
on qr'^/login(/.*)?$', run { |
72 |
|
73 |
my $return_url = $1 || '/'; |
74 |
|
75 |
set 'action' => |
76 |
Jifty->web->new_action( class => 'Login', moniker => 'loginbox' ); |
77 |
set 'next' => Jifty->web->request->continuation |
78 |
|| Jifty::Continuation->new( |
79 |
request => Jifty::Request->new( path => $return_url ) ); |
80 |
show '/login'; |
81 |
}; |
82 |
|
83 |
=head2 logout |
84 |
|
85 |
=cut |
86 |
|
87 |
before 'logout', run { |
88 |
Jifty->web->request->add_action( |
89 |
moniker => 'logout', |
90 |
class => 'Transports::Action::Logout' |
91 |
); |
92 |
}; |
93 |
|
94 |
|
95 |
# These are dispatcher rules that halos and error handling need to be |
96 |
# able to edit files in place. These should become a plugin of some |
97 |
# sort, when we have that infrastructure. |
98 |
|
99 |
before '*', run { |
100 |
Jifty->api->allow(qr/^Jifty::Action::Devel/) |
101 |
if Jifty->config->framework('DevelMode'); |
102 |
}; |
103 |
|
104 |
on qr'^/__jifty/edit/(.*?)/(.*)$', run { |
105 |
my $editor = Jifty->web->new_action( |
106 |
class => 'Jifty::Action::Devel::FileEditor', |
107 |
moniker => 'editpage', |
108 |
arguments => { |
109 |
source_path => $2, |
110 |
file_type => $1, |
111 |
} |
112 |
); |
113 |
|
114 |
set editor => $editor; |
115 |
show '/__jifty/edit_file'; |
116 |
}; |
117 |
|
118 |
1; |