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

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

@ -251,168 +251,66 @@ function initIndex(){
});
}
// Used on the management page
function initManage(){
var data = {};
// Used on the admin page
function initAdmin(){
var roomList = {};
var matches = 0;
// Update display of room list
function updateDeviceList(filter, min, max){
$('#deviceList').html('');
var filterRe = new RegExp(filter, "gi");
var i = 0;
matches = 0;
$.each(roomList, function (index, obj){
if (filter === '' || obj.name.match(filterRe)){
matches++;
if (i >= min && i < max){
$('#deviceList').append($('<tr>')
.append($('<td>').html(stringEscape(obj.name)))
.append($('<td>')
.append($('<div>').addClass('btn-group')
.append($('<a>').addClass('btn btn-default').attr('href',rootUrl + obj.name)
.html(
$('<span>').addClass('glyphicon glyphicon-log-in')
)
)
)
)
);
}
i++;
}
});
}
function sendAction(data,sw){
function getRooms(){
$.ajax({
url: rootUrl + 'admin/jsapi',
data: data,
error: function(data) {
data: {
req: JSON.stringify({
action: 'get_room_list',
param: {}
})
},
error: function() {
$.notify(locale.ERROR_OCCURRED, 'error');
if (typeof(sw) == 'object'){
sw.bootstrapSwitch('toggleState', true);
}
},
success: function(data) {
success: function(data){
if (data.status === 'success'){
$.notify(data.msg, 'success');
deviceList = data.data;
matches = Object.keys(deviceList).length;
updateRoomList($('searchRoom').val(), 0, matches);
}
else{
$.notify(data.msg, 'error');
if (typeof(sw) == 'object'){
sw.bootstrapSwitch('toggleState', true);
}
$.notify(locale.ERROR_OCCURED, 'error');
}
}
});
}
// Replace timestamps with a readable date
$('.timeStamp').each(function(){
$(this).html(timeStamp2Date(parseInt($(this).html())));
});
$('.bs-switch').on('switchChange.bootstrapSwitch', function(event, state) {
var sw = $(this);
var param = $(this).prop('id');
var room = $(this).data('room');
data = {room: room};
if (param === 'lockSwitch'){
data.action = (state) ? 'lock' : 'unlock';
sendAction(data,sw);
}
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');
setTimeout(function(){
sw.bootstrapSwitch('toggleState', true);
}, 500);
}
});
$('#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{
$('#joinPassConfirm').notify(locale.PASSWORDS_DO_NOT_MATCH, '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

@ -3,44 +3,47 @@
%=include 'public_toolbar'
<div class="container-fluid">
%= include 'noscript'
%= include 'configure_modal'
%= include 'invite_modal'
<div class="panel panel-default">
<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>
<table class="table table-hover">
<thead>
<tr>
<th>
<%=l 'ROOM_NAME' %>
</th>
<th>
<%=l 'MANAGE' %>
</th>
</tr>
</thead>
<tbody>
<%
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 %>">
<div class="panel-body">
<div class="text-center" id="pagination">
</div>
<table class="table table-hover">
<thead>
<tr>
<th>
<%=l 'ROOM_NAME' %>
</th>
<th>
<%=l 'MANAGE' %>
</a>
<a class="btn btn-default" href="<%= $self->get_url('/') . $room %>">
<%=l 'JOIN_THIS_ROOM' %>
</a>
</td>
</tr>
<% } %>
</tbody>
</table>
</th>
</tr>
</thead>
<tbody id="roomList">
</tbody>
</table>
</div>
</div>
</div>
%=include 'js_common'
<script>
$(document).ready(function(){
initAdmin();
});
</script>
%=include 'footer'

Loading…
Cancel
Save