(function ($, document, apiClient) {
function deleteRecording(page, id) {
Dashboard.confirm("Are you sure you wish to delete this recording?", "Confirm Recording Deletion", function (result) {
if (result) {
Dashboard.showLoadingMsg();
ApiClient.deleteLiveTvRecording(id).done(function () {
Dashboard.alert('Recording deleted');
reload(page);
});
}
});
}
function loadRecordings(page, elem, groupId) {
var contentElem = $('.recordingList', elem).html('
');
apiClient.getLiveTvRecordings({
userId: Dashboard.getCurrentUserId(),
groupId: groupId
}).done(function (result) {
renderRecordings(page, contentElem, result.Items);
});
}
function getRecordingGroupHtml(group) {
var html = '';
html += '';
html += '
' + group.Name + '
';
html += '
';
html += '
';
html += '
';
return html;
}
function renderRecordingGroups(page, groups) {
var html = '';
for (var i = 0, length = groups.length; i < length; i++) {
html += getRecordingGroupHtml(groups[i]);
}
var elem = $('#items', page).html(html).trigger('create');
$('.recordingGroupCollapsible', elem).on('collapsibleexpand.lazyload', function () {
$(this).off('collapsibleexpand.lazyload');
var groupId = this.getAttribute('data-recordinggroupid');
loadRecordings(page, this, groupId);
});
Dashboard.hideLoadingMsg();
}
function renderRecordings(page, elem, recordings) {
var html = '';
html += '';
elem.html(html).trigger('create');
$('.btnDeleteRecording', elem).on('click', function () {
var recordingId = this.getAttribute('data-recordingid');
deleteRecording(page, recordingId);
});
Dashboard.hideLoadingMsg();
}
function reload(page) {
Dashboard.showLoadingMsg();
apiClient.getLiveTvRecordingGroups({
userId: Dashboard.getCurrentUserId()
}).done(function (result) {
renderRecordingGroups(page, result.Items);
});
}
$(document).on('pagebeforeshow', "#liveTvRecordingsPage", function () {
var page = this;
reload(page);
}).on('pagehide', "#liveTvRecordingsPage", function () {
var page = this;
$('.recordingGroupCollapsible', page).off('collapsibleexpand.lazyload');
});
})(jQuery, document, ApiClient);