2012-10-06 16:36:05 +00:00
|
|
|
(function(context,$) {
|
|
|
|
|
|
|
|
|
|
context.JK = context.JK || {};
|
|
|
|
|
context.JK.FindSessionScreen = function(app) {
|
2012-10-14 15:48:56 +00:00
|
|
|
var logger = context.JK.logger;
|
2012-11-28 02:29:46 +00:00
|
|
|
var sessionLatency;
|
2012-10-06 16:36:05 +00:00
|
|
|
|
|
|
|
|
function loadSessions() {
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "GET",
|
2012-11-28 02:29:46 +00:00
|
|
|
url: "/api/sessions",
|
|
|
|
|
// TODO: Change to buildLatencyMap
|
|
|
|
|
success: renderSessions
|
|
|
|
|
});
|
2012-10-06 16:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderSessions(response) {
|
|
|
|
|
$tb = $('#findSession-tableBody');
|
|
|
|
|
$tb.empty();
|
|
|
|
|
var rowTemplate = $('#template-findSession-row').html();
|
|
|
|
|
$.each(response, function() {
|
|
|
|
|
var vals = {
|
|
|
|
|
id: this.id,
|
|
|
|
|
participants: this.participants.length,
|
|
|
|
|
description: this.description || "(No description)"
|
|
|
|
|
};
|
|
|
|
|
var row = JK.fillTemplate(rowTemplate, vals);
|
|
|
|
|
$tb.append(row);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function afterShow(data) {
|
|
|
|
|
loadSessions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteSession(evt) {
|
|
|
|
|
var sessionId = $(this).attr("action-id");
|
|
|
|
|
if (sessionId) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "DELETE",
|
|
|
|
|
url: "/api/sessions/" + sessionId
|
|
|
|
|
}).done(loadSessions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function events() {
|
|
|
|
|
$('#findSession-tableBody').on("click", '[action="delete"]', deleteSession);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-28 02:29:46 +00:00
|
|
|
this.afterShow = afterShow;
|
|
|
|
|
|
2012-10-14 15:48:56 +00:00
|
|
|
this.initialize = function() {
|
2012-11-28 02:29:46 +00:00
|
|
|
if ("jamClient" in context) {
|
|
|
|
|
sessionLatency = new context.JK.SessionLatency(jamClient);
|
|
|
|
|
} else {
|
|
|
|
|
logger.warn("No jamClient available. Session pings will not be performed.");
|
|
|
|
|
}
|
2012-10-14 15:48:56 +00:00
|
|
|
screenBindings = {
|
|
|
|
|
'afterShow': afterShow
|
|
|
|
|
};
|
|
|
|
|
app.bindScreen('findSession', screenBindings);
|
|
|
|
|
events();
|
2012-10-06 16:36:05 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
})(window,jQuery);
|