|
|
@ -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
|
|
|
|