/[transports]/trunk/lib/Transports/Dispatcher.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/Dispatcher.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (show annotations)
Fri Jun 23 12:54:45 2006 UTC (17 years, 10 months ago) by dpavlin
File size: 3169 byte(s)
transports now filter source and destinations
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 /transports/create/
12
13 Select transport (if only one exists, it will be picked automatically) and
14 create new stransport
15
16 =cut
17
18 under '/transports/create' => [
19
20 on 'landscape' => run {
21
22 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 my $l = Transports::Model::Landscape->new();
53 $l->load_by_cols( id => $landscape_id );
54
55 if (! $l->id) {
56 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 my $d = Transports::Model::DestinationCollection->new();
68 $d->limit(
69 column => 'landscape',
70 value => $landscape_id,
71 );
72 $transport->arguments->{'destination'}->{'valid_values'}->[0]->{'collection'} = $d;
73
74 set 'transport' => $transport;
75
76 show '/transports/create/new';
77 },
78 ];
79
80 =head1 User operations
81
82 =cut
83
84 under '/users' => [
85 on '' => run {
86 dispatch '/users/form' if ( get 'user_id' );
87 },
88 ];
89
90 =head1 Login and logout operations
91
92 =head2 logout
93
94 =cut
95
96 before '/logout', run {
97 Jifty->web->request->add_action(
98 moniker => 'logout',
99 class => 'Transports::Action::Logout'
100 );
101 warn "added Transports::Action::Logout";
102 };
103
104
105 # These are dispatcher rules that halos and error handling need to be
106 # able to edit files in place. These should become a plugin of some
107 # sort, when we have that infrastructure.
108
109 before '*', run {
110
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');
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 {
128 my $editor = Jifty->web->new_action(
129 class => 'Jifty::Action::Devel::FileEditor',
130 moniker => 'editpage',
131 arguments => {
132 source_path => $2,
133 file_type => $1,
134 }
135 );
136
137 set editor => $editor;
138 show '/__jifty/edit_file';
139 };
140
141 1;

  ViewVC Help
Powered by ViewVC 1.1.26