summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-12-17 17:13:30 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-12-17 17:13:30 +0100
commit197cb64451b64397d5853f3dbe2b2f49b10daed5 (patch)
tree853c88e2bb0881cc7c45e86e956ce0631554d71c
parent451486f5c6779983cb3c7ebb0e004aaa383c58f4 (diff)
Allow saving default options in client-side cookie
-rw-r--r--index.pl19
-rw-r--r--templates/layouts/default.html.ep8
2 files changed, 27 insertions, 0 deletions
diff --git a/index.pl b/index.pl
index 3ec36cb..f2dca8c 100644
--- a/index.pl
+++ b/index.pl
@@ -321,6 +321,7 @@ sub handle_request {
my $apiver = $self->param('version') // 0;
my $callback = $self->param('callback');
my $with_related = !$self->param('no_related');
+ my $save_defaults = $self->param('save_defaults') // 0;
my @train_types = split( /,/, $self->param('train_types') // q{} );
my %opt;
@@ -329,6 +330,16 @@ sub handle_request {
? $Travel::Status::DE::IRIS::VERSION
: $Travel::Status::DE::HAFAS::VERSION;
+ if ($save_defaults) {
+ $self->session( has_data => 1 );
+ $self->session( mode => $template );
+ $self->session( hidelowdelay => $hide_low_delay );
+ $self->session( hide_opts => $hide_opts );
+ $self->session( show_realtime => $show_realtime );
+ $self->session( admode => $admode );
+ $self->session( no_related => !$with_related );
+ }
+
$self->stash( departures => [] );
$self->stash( title => 'db-infoscreen' );
$self->stash( version => $VERSION );
@@ -344,6 +355,13 @@ sub handle_request {
}
if ( not $station ) {
+ if ( $self->session('has_data') ) {
+ for my $param (
+ qw(mode hidelowdelay hide_opts show_realtime admode no_related))
+ {
+ $self->param( $param => $self->session($param) );
+ }
+ }
$self->render(
'landingpage',
hide_opts => 0,
@@ -963,6 +981,7 @@ post '/_geolocation' => sub {
};
app->defaults( layout => 'default' );
+app->sessions->default_expiration( 3600 * 24 * 28 );
get '/' => \&handle_request;
get '/multi/*station' => \&handle_request;
diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep
index 54bda52..4a0e616 100644
--- a/templates/layouts/default.html.ep
+++ b/templates/layouts/default.html.ep
@@ -147,6 +147,14 @@ Bitte eine Station aus der Liste auswählen</div>
</div>
</div>
<div class="field">
+ <div class="desc">
+ %= check_box 'save_defaults' => 1, id => 'id_save_defaults'
+ <label for="id_save_defaults">
+ Ausgewählte Optionen als Default speichern
+ </label>
+ </div>
+ </div>
+ <div class="field">
%= submit_button 'Anzeigen'
</div>
</div> <!-- moresettings -->