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