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

135 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-11-24 23:58:38 -07:00
define(['cardBuilder', 'apphost', 'imageLoader', 'scripts/livetvcomponents', 'emby-button', 'emby-itemscontainer'], function (cardBuilder, appHost, imageLoader) {
2016-10-22 22:11:46 -07:00
'use strict';
2016-10-10 23:46:59 -07:00
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
function renderRecordings(elem, recordings, cardOptions) {
if (recordings.length) {
elem.classList.remove('hide');
} else {
elem.classList.add('hide');
}
var recordingItems = elem.querySelector('.recordingItems');
if (enableScrollX()) {
recordingItems.classList.add('hiddenScrollX');
recordingItems.classList.remove('vertical-wrap');
} else {
recordingItems.classList.remove('hiddenScrollX');
recordingItems.classList.add('vertical-wrap');
}
2016-10-12 11:23:09 -07:00
var supportsImageAnalysis = appHost.supports('imageanalysis');
var cardLayout = appHost.preferVisualCards || supportsImageAnalysis;
2016-10-10 23:46:59 -07:00
recordingItems.innerHTML = cardBuilder.getCardsHtml(Object.assign({
items: recordings,
shape: (enableScrollX() ? 'autooverflow' : 'auto'),
showTitle: true,
showParentTitle: true,
coverImage: true,
2016-10-12 11:23:09 -07:00
cardLayout: cardLayout,
centerText: !cardLayout,
vibrant: supportsImageAnalysis,
2016-10-10 23:46:59 -07:00
allowBottomPadding: !enableScrollX(),
preferThumb: 'auto'
}, cardOptions || {}));
2016-11-24 23:58:38 -07:00
imageLoader.lazyChildren(recordingItems);
2016-10-10 23:46:59 -07:00
}
function getBackdropShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
2016-09-04 08:01:31 -07:00
2016-10-02 23:28:45 -07:00
function renderActiveRecordings(context, promise) {
2016-10-02 23:28:45 -07:00
promise.then(function (result) {
// 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-10-10 23:46:59 -07:00
renderRecordings(context.querySelector('#activeRecordings'), result.Items, {
shape: getBackdropShape(),
showParentTitle: false,
showTitle: true,
showAirTime: true,
showAirEndTime: true,
showChannelName: true,
preferThumb: true,
coverImage: true,
overlayText: false
});
});
}
2016-10-02 23:28:45 -07:00
2016-09-04 08:01:31 -07:00
function renderTimers(context, timers, options) {
LiveTvHelpers.getTimersHtml(timers, options).then(function (html) {
var elem = context;
if (html) {
elem.classList.remove('hide');
} else {
elem.classList.add('hide');
}
elem.querySelector('.recordingItems').innerHTML = html;
2016-11-24 23:58:38 -07:00
imageLoader.lazyChildren(elem);
2016-09-04 08:01:31 -07:00
});
}
2016-10-02 23:28:45 -07:00
function renderUpcomingRecordings(context, promise) {
2016-09-04 08:01:31 -07:00
2016-10-02 23:28:45 -07:00
promise.then(function (result) {
2016-09-04 08:01:31 -07:00
renderTimers(context.querySelector('#upcomingRecordings'), result.Items);
Dashboard.hideLoadingMsg();
});
}
return function (view, params, tabContent) {
var self = this;
2016-10-02 23:28:45 -07:00
var activeRecordingsPromise;
var upcomingRecordingsPromise;
2016-09-04 08:01:31 -07:00
2016-09-04 10:52:43 -07:00
tabContent.querySelector('#upcomingRecordings .recordingItems').addEventListener('timercancelled', function () {
2016-10-02 23:28:45 -07:00
self.preRender();
self.renderTab();
2016-09-04 08:01:31 -07:00
});
2016-10-02 23:28:45 -07:00
self.preRender = function () {
2016-10-10 23:46:59 -07:00
activeRecordingsPromise = ApiClient.getLiveTvRecordings({
UserId: Dashboard.getCurrentUserId(),
IsInProgress: true,
Fields: 'CanDelete,PrimaryImageAspectRatio,BasicSyncInfo',
EnableTotalRecordCount: false,
EnableImageTypes: "Primary,Thumb,Backdrop"
2016-10-02 23:28:45 -07:00
});
upcomingRecordingsPromise = ApiClient.getLiveTvTimers({
2016-10-03 22:15:39 -07:00
IsActive: false,
IsScheduled: true
2016-10-02 23:28:45 -07:00
});
};
2016-09-04 08:01:31 -07:00
self.renderTab = function () {
2016-10-02 23:28:45 -07:00
Dashboard.showLoadingMsg();
renderActiveRecordings(tabContent, activeRecordingsPromise);
renderUpcomingRecordings(tabContent, upcomingRecordingsPromise);
2016-09-04 08:01:31 -07:00
};
};
});