From 232125b88c3305584d6bf19fc0f42b0500961131 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Thu, 9 Oct 2014 21:33:21 +0200 Subject: [PATCH] Add lang switch in the toolbar --- public/js/vroom.js | 21 +++++++++++++++++++++ public/vroom.pl | 17 +++++++++++++++++ templates/default/join.html.ep | 9 +++++++++ templates/default/public_toolbar.html.ep | 9 +++++++++ 4 files changed, 56 insertions(+) diff --git a/public/js/vroom.js b/public/js/vroom.js index 24754e3..70c6df0 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -40,6 +40,27 @@ $.ajaxSetup({ dataType: 'json', }); +// Handle lang switch +$('#langSwitch').change(function(){ + $.ajax({ + data: { + action: 'langSwitch', + lang: $('#langSwitch').val() + }, + error: function() { + $.notify(locale.ERROR_OCCURRED, 'error'); + }, + success: function(data){ + if (data.status === 'success'){ + window.location.reload(); + } + else{ + $.notify(locale.ERROR_OCCURED, 'error'); + } + } + }); +}); + // // Define a few functions // diff --git a/public/vroom.pl b/public/vroom.pl index b7b00b2..9fe4cf8 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -1164,6 +1164,16 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub { my $action = $self->param('action'); my $prefix = ($self->stash('action') eq 'admin/action') ? 'admin':'room'; my $room = $self->param('room') || ""; + if ($action eq 'langSwitch'){ + my $new_lang = $self->param('lang') || 'en'; + $self->app->log->debug("switching to lang $new_lang"); + $self->session(language => $new_lang); + return $self->render( + json => { + status => 'success', + } + ); + } # Refuse any action from non members of the room if ($prefix ne 'admin' && (!$self->session('name') || !$self->has_joined($self->session('name'), $room) || !$self->session($room) || !$self->session($room)->{role})){ return $self->render( @@ -1588,6 +1598,13 @@ push @{app->renderer->paths}, '../templates/'.$config->{template}; app->secret($config->{secret}); app->sessions->secure(1); app->sessions->cookie_name('vroom'); +app->hook(before_dispatch => sub { + my $self = shift; + # Switch to the desired language + if ($self->session('language')){ + $self->languages($self->session('language')); + } +}); # And start, lets VROOM !! app->start; diff --git a/templates/default/join.html.ep b/templates/default/join.html.ep index 0bb3f89..c988228 100644 --- a/templates/default/join.html.ep +++ b/templates/default/join.html.ep @@ -253,6 +253,15 @@ +
+ +
diff --git a/templates/default/public_toolbar.html.ep b/templates/default/public_toolbar.html.ep index 7ff72cc..74a742d 100644 --- a/templates/default/public_toolbar.html.ep +++ b/templates/default/public_toolbar.html.ep @@ -26,6 +26,15 @@
  • <%=l 'FEEDBACK' %>
  • +
  • + +