Start rewriting the admin area (WIP, not working yet)

master
Daniel Berteaud 10 years ago
parent a0b4362608
commit 944f121ae4
  1. 194
      public/js/vroom.js
  2. 43
      templates/default/admin.html.ep

@ -251,168 +251,66 @@ function initIndex(){
}); });
} }
// Used on the management page // Used on the admin page
function initManage(){ function initAdmin(){
var roomList = {};
var data = {}; var matches = 0;
function sendAction(data,sw){ // Update display of room list
$.ajax({ function updateDeviceList(filter, min, max){
url: rootUrl + 'admin/jsapi', $('#deviceList').html('');
data: data, var filterRe = new RegExp(filter, "gi");
error: function(data) { var i = 0;
$.notify(locale.ERROR_OCCURRED, 'error'); matches = 0;
if (typeof(sw) == 'object'){ $.each(roomList, function (index, obj){
sw.bootstrapSwitch('toggleState', true); if (filter === '' || obj.name.match(filterRe)){
} matches++;
}, if (i >= min && i < max){
success: function(data) { $('#deviceList').append($('<tr>')
if (data.status === 'success'){ .append($('<td>').html(stringEscape(obj.name)))
$.notify(data.msg, 'success'); .append($('<td>')
} .append($('<div>').addClass('btn-group')
else{ .append($('<a>').addClass('btn btn-default').attr('href',rootUrl + obj.name)
$.notify(data.msg, 'error'); .html(
if (typeof(sw) == 'object'){ $('<span>').addClass('glyphicon glyphicon-log-in')
sw.bootstrapSwitch('toggleState', true); )
} )
)
)
);
} }
i++;
} }
}); });
} }
// Replace timestamps with a readable date
$('.timeStamp').each(function(){
$(this).html(timeStamp2Date(parseInt($(this).html())));
});
$('.bs-switch').on('switchChange.bootstrapSwitch', function(event, state) { function getRooms(){
var sw = $(this); $.ajax({
var param = $(this).prop('id'); data: {
var room = $(this).data('room'); req: JSON.stringify({
data = {room: room}; action: 'get_room_list',
if (param === 'lockSwitch'){ param: {}
data.action = (state) ? 'lock' : 'unlock'; })
sendAction(data,sw); },
} error: function() {
else if (param === 'askForNameSwitch'){
data.action = 'askForName';
data.type = (state) ? 'set' : 'unset';
sendAction(data,sw);
}
else if (param === 'joinPassSwitch'){
if (state){
$('#joinPassModal').modal('show');
// switch back to off in case it's cancelled
sw.bootstrapSwitch('toggleState', true);
}
else{
data.action = 'setPassword';
data.type = 'join';
sendAction(data,sw);
}
}
else if (param === 'ownerPassSwitch'){
if (state){
$('#ownerPassModal').modal('show');
sw.bootstrapSwitch('toggleState', true);
}
else{
data.action = 'setPassword';
data.type = 'owner';
sendAction(data,sw);
}
}
else if (param === 'persistentSwitch'){
data.action = 'set_persistent';
data.set = (state) ? 'on' : 'off';
sendAction(data,sw);
}
// Something isn't implemented yet ?
else{
$.notify(locale.ERROR_OCCURRED, 'error'); $.notify(locale.ERROR_OCCURRED, 'error');
setTimeout(function(){ },
sw.bootstrapSwitch('toggleState', true); success: function(data){
}, 500); if (data.status === 'success'){
} deviceList = data.data;
}); matches = Object.keys(deviceList).length;
updateRoomList($('searchRoom').val(), 0, matches);
$('#joinPassForm').submit(function(event) {
event.preventDefault();
var pass = $('#joinPass').val();
var pass2 = $('#joinPassConfirm').val();
if (pass == pass2 && pass != ''){
$('#setJoinPassButton').addClass('disabled');
$('#joinPass').val('');
$('#joinPassConfirm').val('');
data.action = 'setPassword';
data.type = 'join';
data.password = pass
sendAction(data, $('#joinPassSwitch'));
$('#joinPassSwitch').bootstrapSwitch('toggleState', true);
$('#joinPassModal').modal('hide');
} }
else{ else{
$('#joinPassConfirm').notify(locale.PASSWORDS_DO_NOT_MATCH, 'error'); $.notify(locale.ERROR_OCCURED, 'error');
}
});
$('#ownerPassForm').submit(function(event) {
event.preventDefault();
var pass = $('#ownerPass').val();
var pass2 = $('#ownerPassConfirm').val();
if (pass == pass2 && pass != ''){
$('#setOwnerPassButton').addClass('disabled');
$('#ownerPass').val('');
$('#ownerPassConfirm').val('');
data.action = 'setPassword';
data.type = 'owner';
data.password = pass
sendAction(data, $('#ownerPassSwitch'));
$('#ownerPassSwitch').bootstrapSwitch('toggleState', true);
$('#ownerPassModal').modal('hide');
} }
else{
$('#ownerPassConfirm').notify(locale.PASSWORDS_DO_NOT_MATCH, 'error');
} }
}); });
// 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);
});
// Show the invite by email dialog
$('#showEmailInvite').click(function(){
$('#emailInviteModal').modal('show');
data.room = $(this).data('room');
});
// Handle Email Invitation
$('#inviteEmail').submit(function(event) {
event.preventDefault();
var rcpt = $('#recipient').val();
message = $('#message').val();
// Simple email address verification
// not fullproof, but email validation is a real nightmare
if (!rcpt.match(/\S+@\S+\.\S+/)){
$.notify(locale.ERROR_MAIL_INVALID, 'error');
return;
} }
data.action = 'invite';
data.recipient = rcpt;
data.message = message
sendAction(data);
});
// Get room list right after loading the page
getRooms();
} }
// This is the main function called when you join a room // This is the main function called when you join a room

@ -3,9 +3,24 @@
%=include 'public_toolbar' %=include 'public_toolbar'
<div class="container-fluid"> <div class="container-fluid">
%= include 'noscript' %= include 'noscript'
%= include 'configure_modal'
%= include 'invite_modal'
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<%=l 'EXISTING_ROOMS' %> <div class="form-inline">
<div class="form-group">
<div class="input-group">
<input type="text" id="searchRoom" class="form-control" value=""/>
<div class="input-group-addon">
<span class="glyphicon glyphicon-search">
</span>
</div>
</div>
</div>
</div>
</div>
<div class="panel-body">
<div class="text-center" id="pagination">
</div> </div>
<table class="table table-hover"> <table class="table table-hover">
<thead> <thead>
@ -18,29 +33,17 @@
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody id="roomList">
<%
my $rooms = $self->get_room_list();
foreach my $room (keys %{$rooms}){
%>
<tr>
<td>
<%= $room %>
</td>
<td>
<a class="btn btn-primary" href="<%= $self->get_url('/admin/') . $room %>">
<%=l 'MANAGE' %>
</a>
<a class="btn btn-default" href="<%= $self->get_url('/') . $room %>">
<%=l 'JOIN_THIS_ROOM' %>
</a>
</td>
</tr>
<% } %>
</tbody> </tbody>
</table> </table>
</div> </div>
</div>
</div> </div>
%=include 'js_common' %=include 'js_common'
<script>
$(document).ready(function(){
initAdmin();
});
</script>
%=include 'footer' %=include 'footer'

Loading…
Cancel
Save