2013-10-03 15:04:25 -04:00
|
|
|
define(function() {
|
|
|
|
|
var Admin = {};
|
2013-07-15 13:49:21 -04:00
|
|
|
|
2013-11-29 23:08:42 -05:00
|
|
|
Admin.init = function() {
|
2014-01-16 15:10:37 -05:00
|
|
|
ajaxify.register_events(['meta.rooms.getAll']);
|
2014-01-10 13:27:50 -05:00
|
|
|
|
|
|
|
|
app.enterRoom('admin');
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.emit('meta.rooms.getAll', Admin.updateRoomUsage);
|
2014-01-13 12:01:42 -05:00
|
|
|
socket.on('event:meta.rooms.update', Admin.updateRoomUsage);
|
2013-07-15 13:49:21 -04:00
|
|
|
|
2013-11-29 23:08:42 -05:00
|
|
|
$('#logout-link').on('click', function() {
|
|
|
|
|
$.post(RELATIVE_PATH + '/logout', {
|
|
|
|
|
_csrf: $('#csrf_token').val()
|
|
|
|
|
}, function() {
|
|
|
|
|
window.location.href = RELATIVE_PATH + '/';
|
|
|
|
|
});
|
|
|
|
|
})
|
2013-10-03 15:04:25 -04:00
|
|
|
};
|
2013-07-15 13:49:21 -04:00
|
|
|
|
2014-01-16 16:26:47 -05:00
|
|
|
Admin.updateRoomUsage = function(err, data) {
|
2014-01-18 21:57:06 -05:00
|
|
|
var active_users = $('#active_users'),
|
2014-01-13 12:01:42 -05:00
|
|
|
total = 0;
|
2014-01-18 21:57:06 -05:00
|
|
|
|
|
|
|
|
if(!active_users.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
active_users.html('');
|
|
|
|
|
|
|
|
|
|
var usersHtml = '';
|
2014-01-13 12:01:42 -05:00
|
|
|
|
|
|
|
|
for (var room in data) {
|
|
|
|
|
if (room !== '') {
|
2014-01-16 17:22:11 -05:00
|
|
|
var count = $(data[room]).length;
|
2014-01-13 12:01:42 -05:00
|
|
|
total += count;
|
2014-01-18 21:57:06 -05:00
|
|
|
usersHtml += "<div class='alert alert-success'><strong>" + room + "</strong> " + count + " active user" + (count > 1 ? "s" : "") + "</div>";
|
2014-01-13 12:01:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-18 21:57:06 -05:00
|
|
|
active_users.html(usersHtml);
|
2014-01-13 12:01:42 -05:00
|
|
|
document.getElementById('connections').innerHTML = total;
|
|
|
|
|
};
|
|
|
|
|
|
2013-10-03 15:04:25 -04:00
|
|
|
return Admin;
|
|
|
|
|
});
|