From dde7079b1c0d6349818e2762beb0d8ca0d587aaa Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sat, 19 Jul 2014 12:55:36 +0200 Subject: [PATCH] Add buttons to join and delete room on the management page --- public/js/vroom.js | 36 ++++++++++++++++++++++++-------- templates/default/manage_room.html.ep | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index 5c628ed..44e860d 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -343,13 +343,15 @@ function initManage(){ var data = {}; - function ajaxifySwitch(sw,data){ + function sendAction(data,sw){ $.ajax({ url: rootUrl + 'admin/action', data: data, error: function(data) { $.notify(locale.ERROR_OCCURRED, 'error'); - sw.bootstrapSwitch('toggleState', true); + if (typeof(sw) == 'object'){ + sw.bootstrapSwitch('toggleState', true); + } }, success: function(data) { if (data.status === 'success'){ @@ -357,7 +359,9 @@ function initManage(){ } else{ $.notify(data.msg, 'error'); - sw.bootstrapSwitch('toggleState', true); + if (typeof(sw) == 'object'){ + sw.bootstrapSwitch('toggleState', true); + } } } }); @@ -375,12 +379,12 @@ function initManage(){ data = {room: room}; if (param === 'lockSwitch'){ data.action = (state) ? 'lock' : 'unlock'; - ajaxifySwitch(sw,data); + sendAction(data,sw); } else if (param === 'askForNameSwitch'){ data.action = 'askForName'; data.type = (state) ? 'set' : 'unset'; - ajaxifySwitch(sw,data); + sendAction(data,sw); } else if (param === 'joinPassSwitch'){ if (state){ @@ -391,7 +395,7 @@ function initManage(){ else{ data.action = 'setPassword'; data.type = 'join'; - ajaxifySwitch(sw,data); + sendAction(data,sw); } } else if (param === 'ownerPassSwitch'){ @@ -402,7 +406,7 @@ function initManage(){ else{ data.action = 'setPassword'; data.type = 'owner'; - ajaxifySwitch(sw,data); + sendAction(data,sw); } } // Something isn't implemented yet ? @@ -425,7 +429,7 @@ function initManage(){ data.action = 'setPassword'; data.type = 'join'; data.password = pass - ajaxifySwitch($('#joinPassSwitch'), data); + sendAction(data, $('#joinPassSwitch')); $('#joinPassSwitch').bootstrapSwitch('toggleState', true); $('#joinPassModal').modal('hide'); } @@ -445,7 +449,7 @@ function initManage(){ data.action = 'setPassword'; data.type = 'owner'; data.password = pass - ajaxifySwitch($('#ownerPassSwitch'), data); + sendAction(data, $('#ownerPassSwitch')); $('#ownerPassSwitch').bootstrapSwitch('toggleState', true); $('#persistentModal').modal('hide'); } @@ -454,6 +458,20 @@ function initManage(){ } }); + // Handle room deletion + $('#deleteRoomButton').click(function(){ + $('#deleteRoomModal').modal('show'); + data.room = $(this).data('room'); + }); + $('#confirmDeleteButton').click(function(){ + data.action = 'deleteRoom'; + sendAction(data); + $('#deleteRoomModal').modal('hide'); + setTimeout(function(){ + window.location.assign(rootUrl + 'admin'); + }, 2000); + }); + } // This is the main function called when you join a room diff --git a/templates/default/manage_room.html.ep b/templates/default/manage_room.html.ep index 79d17e9..9e40ec4 100644 --- a/templates/default/manage_room.html.ep +++ b/templates/default/manage_room.html.ep @@ -4,6 +4,33 @@
%= include 'owner_password_modal' %= include 'join_password_modal' + %= include 'noscript'
@@ -71,6 +98,18 @@
+
+ +
+ +
+
%=include 'js_common'