summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Controller/Traveling.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-04-07 20:20:37 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-04-07 20:20:37 +0200
commitbeb17acb8440bb44f1070c2fb3b2e6cf7521f800 (patch)
treebbe052f289d841ecb1ca89426cbf39fbdfc2950a /lib/Travelynx/Controller/Traveling.pm
parentd4269a8fe4586e08577b66b5068b576e5ab36c7b (diff)
Prepare forms for manual journey entry and editing
Diffstat (limited to 'lib/Travelynx/Controller/Traveling.pm')
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index bbbc214..83036ba 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -378,6 +378,8 @@ sub journey_details {
my ($self) = @_;
my ( $uid, $checkout_id ) = split( qr{-}, $self->stash('id') );
+ $self->param( journey_id => $checkout_id );
+
if ( not( $uid == $self->current_user->{id} and $checkout_id ) ) {
$self->render(
'journey',
@@ -411,4 +413,60 @@ sub journey_details {
);
}
+sub edit_journey {
+ my ($self) = @_;
+ my $checkout_id = $self->param('journey_id');
+ my $uid = $self->current_user->{id};
+
+ if ( not( $uid == $self->current_user->{id} and $checkout_id ) ) {
+ $self->render(
+ 'edit_journey',
+ error => 'notfound',
+ journey => {}
+ );
+ return;
+ }
+
+ my @journeys = $self->get_user_travels(
+ uid => $uid,
+ checkout_id => $checkout_id,
+ );
+ if ( @journeys == 0
+ or not $journeys[0]{completed}
+ or $journeys[0]{ids}[1] != $checkout_id )
+ {
+ $self->render(
+ 'edit_journey',
+ error => 'notfound',
+ journey => {}
+ );
+ return;
+ }
+
+ my $journey = $journeys[0];
+
+ for my $key (qw(sched_departure rt_departure sched_arrival rt_arrival)) {
+ if ( $journey->{$key} and $journey->{$key}->epoch ) {
+ $self->param(
+ $key => $journey->{$key}->strftime('%d.%m.%Y %H:%M') );
+ }
+ }
+
+ if ( $journey->{route} ) {
+ $self->param( route => join( "\n", @{ $journey->{route} } ) );
+ }
+
+ $self->render(
+ 'edit_journey',
+ error => undef,
+ journey => $journey
+ );
+}
+
+sub add_journey_form {
+ my ($self) = @_;
+
+ $self->render( 'add_journey', error => undef );
+}
+
1;