56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
(function(context,$) {
|
|
|
|
context.JK = context.JK || {};
|
|
context.JK.FindSessionScreen = function(app) {
|
|
var logger = context.JK.logger;
|
|
|
|
function loadSessions() {
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "/api/sessions"
|
|
}).done(renderSessions);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
this.initialize = function() {
|
|
screenBindings = {
|
|
'afterShow': afterShow
|
|
};
|
|
app.bindScreen('findSession', screenBindings);
|
|
events();
|
|
};
|
|
};
|
|
|
|
})(window,jQuery); |