Add lang switch in the toolbar

master
Daniel Berteaud 10 years ago
parent 8d8dfad3d4
commit 232125b88c
  1. 21
      public/js/vroom.js
  2. 17
      public/vroom.pl
  3. 9
      templates/default/join.html.ep
  4. 9
      templates/default/public_toolbar.html.ep

@ -40,6 +40,27 @@ $.ajaxSetup({
dataType: 'json', 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 // Define a few functions
// //

@ -1164,6 +1164,16 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
my $action = $self->param('action'); my $action = $self->param('action');
my $prefix = ($self->stash('action') eq 'admin/action') ? 'admin':'room'; my $prefix = ($self->stash('action') eq 'admin/action') ? 'admin':'room';
my $room = $self->param('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 # 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})){ if ($prefix ne 'admin' && (!$self->session('name') || !$self->has_joined($self->session('name'), $room) || !$self->session($room) || !$self->session($room)->{role})){
return $self->render( return $self->render(
@ -1588,6 +1598,13 @@ push @{app->renderer->paths}, '../templates/'.$config->{template};
app->secret($config->{secret}); app->secret($config->{secret});
app->sessions->secure(1); app->sessions->secure(1);
app->sessions->cookie_name('vroom'); 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 !! # And start, lets VROOM !!
app->start; app->start;

@ -253,6 +253,15 @@
</span> </span>
</button> </button>
</div> </div>
<div class="btn-group">
<select class="form-control " id="langSwitch">
<% foreach my $lang (qw(en fr)){ %>
<option value="<%= $lang %>" <%= ($self->languages eq $lang) ? 'selected="selected"' : '' %>>
<%= $lang %>
</option>
<% } %>
</select>
</div>
</div> </div>
</div> </div>
</nav> </nav>

@ -26,6 +26,15 @@
<li> <li>
<a href="<%= $self->get_url('/feedback') %>"><%=l 'FEEDBACK' %></a> <a href="<%= $self->get_url('/feedback') %>"><%=l 'FEEDBACK' %></a>
</li> </li>
<li>
<select class="form-control navbar-btn" id="langSwitch">
<% foreach my $lang (qw(en fr)){ %>
<option value="<%= $lang %>" <%= ($self->languages eq $lang) ? 'selected="selected"' : '' %>>
<%= $lang %>
</option>
<% } %>
</select>
</li>
</ul> </ul>
</div> </div>
</div> </div>

Loading…
Cancel
Save