From 96d8a0eaa6a1235aa5290aa48a21aab6d51e466e Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 14 May 2014 21:51:35 +0200 Subject: [PATCH] Fix error handling for lock/unlock --- public/js/vroom.js | 22 +++++++++++++--------- public/vroom.pl | 7 ++++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index 6fac860..f7b2958 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -580,20 +580,24 @@ function initVroom(room) { room: roomName }, error: function(data) { - var msg = (data && data.msg) ? data.msg : locale.ERROR_OCCURED; - $.notify(msg, 'error'); + $.notify(locale.ERROR_OCCURED, 'error'); }, success: function(data) { - $.notify(data.msg, 'info'); - if (action === 'lock'){ - $("#lockLabel").addClass('btn-danger'); - webrtc.sendToAll('room_locked', {}); + if (data.status == 'success'){ + $.notify(data.msg, 'info'); + if (action === 'lock'){ + $("#lockLabel").addClass('btn-danger'); + webrtc.sendToAll('room_locked', {}); + } + else{ + $("#lockLabel").removeClass('btn-danger'); + webrtc.sendToAll('room_unlocked', {}); + } } else{ - $("#lockLabel").removeClass('btn-danger'); - webrtc.sendToAll('room_unlocked', {}); + $.notify(data.msg, 'error'); } - } + } }); }); diff --git a/public/vroom.pl b/public/vroom.pl index 5e8c2f8..448f160 100755 --- a/public/vroom.pl +++ b/public/vroom.pl @@ -517,14 +517,15 @@ post '/action' => sub { unless ($res){ return $self->render( json => { - msg => $self->l('ERROR_OCCURED'), + msg => $self->l('ERROR_OCCURED'), + status => 'error' }, - status => '500' ); } return $self->render( json => { - msg => $success, + msg => $success, + status => 'success' } ); }