jellyfin-web/dashboard-ui/scripts/livetvrecordings.js

202 lines
5.8 KiB
JavaScript
Raw Normal View History

2016-07-29 23:23:56 -07:00
define(['components/categorysyncbuttons', 'cardBuilder', 'scripts/livetvcomponents', 'emby-button', 'listViewStyle', 'emby-itemscontainer'], function (categorysyncbuttons, cardBuilder) {
2016-05-15 10:11:26 -07:00
function getRecordingGroupHtml(group) {
var html = '';
2016-06-25 18:33:16 -07:00
html += '<div class="listItem">';
2016-05-15 10:11:26 -07:00
2016-06-21 21:39:47 -07:00
html += '<button type="button" is="emby-button" class="fab mini autoSize blue" item-icon><i class="md-icon">live_tv</i></button>';
2016-05-15 10:11:26 -07:00
2016-06-26 21:19:10 -07:00
html += '<div class="listItemBody two-line">';
2016-05-15 10:11:26 -07:00
html += '<a href="livetvrecordinglist.html?groupid=' + group.Id + '" class="clearLink">';
html += '<div>';
html += group.Name;
html += '</div>';
2016-06-25 18:33:16 -07:00
html += '<div class="secondary">';
2016-05-15 10:11:26 -07:00
if (group.RecordingCount == 1) {
html += Globalize.translate('ValueItemCount', group.RecordingCount);
} else {
html += Globalize.translate('ValueItemCountPlural', group.RecordingCount);
}
html += '</div>';
html += '</a>';
2016-06-25 18:33:16 -07:00
html += '</div>';
html += '</div>';
2016-05-15 10:11:26 -07:00
return html;
}
function renderRecordingGroups(context, groups) {
if (groups.length) {
2016-06-06 18:55:16 -07:00
context.querySelector('#recordingGroups').classList.remove('hide');
2016-05-15 10:11:26 -07:00
} else {
2016-06-06 18:55:16 -07:00
context.querySelector('#recordingGroups').classList.add('hide');
2016-05-15 10:11:26 -07:00
}
var html = '';
html += '<div class="paperList">';
for (var i = 0, length = groups.length; i < length; i++) {
html += getRecordingGroupHtml(groups[i]);
}
html += '</div>';
context.querySelector('#recordingGroupItems').innerHTML = html;
Dashboard.hideLoadingMsg();
}
2016-05-15 22:46:23 -07:00
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
2016-05-15 10:11:26 -07:00
function renderRecordings(elem, recordings) {
if (recordings.length) {
elem.classList.remove('hide');
} else {
elem.classList.add('hide');
}
var recordingItems = elem.querySelector('.recordingItems');
2016-05-15 22:46:23 -07:00
if (enableScrollX()) {
recordingItems.classList.add('hiddenScrollX');
2016-07-29 23:23:56 -07:00
recordingItems.classList.remove('vertical-wrap');
2016-05-15 22:46:23 -07:00
} else {
recordingItems.classList.remove('hiddenScrollX');
2016-07-29 23:23:56 -07:00
recordingItems.classList.add('vertical-wrap');
2016-05-15 22:46:23 -07:00
}
2016-06-06 18:55:16 -07:00
2016-07-29 23:23:56 -07:00
recordingItems.innerHTML = cardBuilder.getCardsHtml({
2016-05-15 10:11:26 -07:00
items: recordings,
2016-05-18 10:02:56 -07:00
shape: (enableScrollX() ? 'autooverflow' : 'auto'),
2016-05-15 10:11:26 -07:00
showTitle: true,
showParentTitle: true,
coverImage: true,
lazy: true,
2016-05-18 10:02:56 -07:00
cardLayout: true
2016-05-15 10:11:26 -07:00
});
ImageLoader.lazyChildren(recordingItems);
}
function renderActiveRecordings(context) {
2016-06-19 10:41:49 -07:00
ApiClient.getLiveTvTimers({
2016-05-15 10:11:26 -07:00
2016-06-19 10:41:49 -07:00
IsActive: true
2016-05-15 10:11:26 -07:00
}).then(function (result) {
2016-06-19 10:41:49 -07:00
// The IsActive param is new, so handle older servers that don't support it
if (result.Items.length && result.Items[0].Status != 'InProgress') {
result.Items = [];
}
2016-05-15 10:11:26 -07:00
2016-06-19 10:41:49 -07:00
renderTimers(context.querySelector('#activeRecordings'), result.Items, {
indexByDate: false
});
2016-05-15 10:11:26 -07:00
});
2016-06-19 10:41:49 -07:00
//ApiClient.getLiveTvRecordings({
// userId: Dashboard.getCurrentUserId(),
// IsInProgress: true,
// Fields: 'CanDelete'
//}).then(function (result) {
// renderRecordings(context.querySelector('#activeRecordings'), result.Items);
//});
2016-05-15 10:11:26 -07:00
}
function renderLatestRecordings(context) {
ApiClient.getLiveTvRecordings({
userId: Dashboard.getCurrentUserId(),
2016-05-18 10:02:56 -07:00
limit: enableScrollX() ? 12 : 4,
2016-05-15 10:11:26 -07:00
IsInProgress: false,
2016-06-20 10:08:13 -07:00
Fields: 'CanDelete,PrimaryImageAspectRatio',
EnableTotalRecordCount: false
2016-05-15 10:11:26 -07:00
}).then(function (result) {
renderRecordings(context.querySelector('#latestRecordings'), result.Items);
});
}
2016-06-19 10:41:49 -07:00
function renderTimers(context, timers, options) {
2016-05-15 10:11:26 -07:00
2016-06-19 10:41:49 -07:00
LiveTvHelpers.getTimersHtml(timers, options).then(function (html) {
2016-05-15 10:11:26 -07:00
2016-06-19 10:41:49 -07:00
var elem = context;
2016-05-15 10:11:26 -07:00
if (html) {
elem.classList.remove('hide');
} else {
elem.classList.add('hide');
}
elem.querySelector('.recordingItems').innerHTML = html;
ImageLoader.lazyChildren(elem);
});
}
function renderUpcomingRecordings(context) {
2016-06-19 10:41:49 -07:00
ApiClient.getLiveTvTimers({
IsActive: false
}).then(function (result) {
2016-05-15 10:11:26 -07:00
2016-06-19 10:41:49 -07:00
renderTimers(context.querySelector('#upcomingRecordings'), result.Items);
2016-05-15 10:11:26 -07:00
});
}
function reload(context) {
Dashboard.showLoadingMsg();
renderUpcomingRecordings(context);
renderActiveRecordings(context);
renderLatestRecordings(context);
ApiClient.getLiveTvRecordingGroups({
userId: Dashboard.getCurrentUserId()
}).then(function (result) {
2016-06-25 18:33:16 -07:00
renderRecordingGroups(context, result.Items);
2016-05-15 10:11:26 -07:00
});
}
return function (view, params, tabContent) {
var self = this;
2016-07-18 20:57:55 -07:00
categorysyncbuttons.init(tabContent);
2016-06-19 10:41:49 -07:00
tabContent.querySelector('#activeRecordings .recordingItems').addEventListener('timercancelled', function () {
reload(tabContent);
});
2016-05-15 10:11:26 -07:00
tabContent.querySelector('#upcomingRecordings .recordingItems').addEventListener('timercancelled', function () {
reload(tabContent);
});
self.renderTab = function () {
reload(tabContent);
};
};
});