From 0a6e2d4f9b5d3850c369d6188393b87c7318b9b5 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sun, 18 Jan 2015 19:38:18 +0100 Subject: [PATCH] Switch set_persistent to the new API handler --- lib/Vroom/Constants.pm | 3 ++- public/js/vroom.js | 4 ++-- vroom.pl | 39 ++++++++++++++++++--------------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index 6342eda..77d14d9 100644 --- a/lib/Vroom/Constants.pm +++ b/lib/Vroom/Constants.pm @@ -155,7 +155,8 @@ use constant JS_STRINGS => qw( # API actions use constant API_ACTIONS => { admin => { - list_rooms => 1 + list_rooms => 1, + set_persistent => 1 }, owner => { invite_email => 1, diff --git a/public/js/vroom.js b/public/js/vroom.js index 19d5594..11a7b66 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -380,8 +380,8 @@ function initManage(){ } } else if (param === 'persistentSwitch'){ - data.action = 'setPersistent'; - data.type = (state) ? 'set' : 'unset'; + data.action = 'set_persistent'; + data.set = (state) ? 'on' : 'off'; sendAction(data,sw); } // Something isn't implemented yet ? diff --git a/vroom.pl b/vroom.pl index 338296c..536fcb7 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1372,6 +1372,24 @@ any '/api' => sub { } ); } + elsif ($req->{action} eq 'set_persistent'){ + my $set = $self->param('set'); + $room->{persistent} = ($set eq 'on') ? 1 : 0; + if ($self->modify_room($room)){ + return $self->render( + json => { + status => 'success', + msg => $self->l(($set eq 'on') ? 'ROOM_NOW_PERSISTENT' : 'ROOM_NO_MORE_PERSISTENT') + } + ); + } + return $self->render( + json => { + msg => $self->l('ERROR_OCCURRED'), + status => 'error' + } + ); + } elsif ($req->{action} eq 'authenticate'){ my $pass = $req->{param}->{'password'}; # Auth succeed ? lets promote him to owner of the room @@ -1546,27 +1564,6 @@ post '/*jsapi' => { jsapi => [qw(jsapi admin/jsapi)] } => sub { ); } - # Handle persistence - elsif ($action eq 'setPersistent'){ - my $type = $self->param('type'); - my $status = 'error'; - my $msg = $self->l('ERROR_OCCURRED'); - # Only possible through /admin/action - if ($prefix ne 'admin'){ - $msg = $self->l('NOT_ALLOWED'); - } - $data->{persistent} = ($type eq 'set') ? 1 : 0; - if ($self->modify_room($data)){ - $status = 'success'; - $msg = $self->l(($type eq 'set') ? 'ROOM_NOW_PERSISTENT' : 'ROOM_NO_MORE_PERSISTENT'); - } - return $self->render( - json => { - msg => $msg, - status => $status - } - ); - } # Return your role and various info about the room elsif ($action eq 'getRoomInfo'){ my $id = $self->param('id');