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

233 lines
7.1 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
2016-05-15 22:46:23 -07:00
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
2016-09-04 22:39:14 -07:00
function renderRecordings(elem, recordings, cardOptions) {
2016-05-15 10:11:26 -07:00
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-09-04 22:39:14 -07:00
recordingItems.innerHTML = cardBuilder.getCardsHtml(Object.assign({
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-08-12 08:54:37 -07:00
cardLayout: true,
allowBottomPadding: !enableScrollX()
2016-09-04 22:39:14 -07:00
}, cardOptions || {}));
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
});
}
function renderLatestRecordings(context) {
ApiClient.getLiveTvRecordings({
2016-09-04 22:39:14 -07:00
UserId: Dashboard.getCurrentUserId(),
Limit: enableScrollX() ? 12 : 8,
2016-05-15 10:11:26 -07:00
IsInProgress: false,
2016-09-04 22:39:14 -07:00
Fields: 'CanDelete,PrimaryImageAspectRatio,BasicSyncInfo',
2016-06-20 10:08:13 -07:00
EnableTotalRecordCount: false
2016-05-15 10:11:26 -07:00
}).then(function (result) {
renderRecordings(context.querySelector('#latestRecordings'), result.Items);
2016-09-04 22:39:14 -07:00
Dashboard.hideLoadingMsg();
});
}
function renderMovieRecordings(context) {
ApiClient.getLiveTvRecordings({
UserId: Dashboard.getCurrentUserId(),
Limit: enableScrollX() ? 12 : 8,
IsInProgress: false,
Fields: 'CanDelete,PrimaryImageAspectRatio,BasicSyncInfo',
EnableTotalRecordCount: false,
IsMovie: true
}).then(function (result) {
renderRecordings(context.querySelector('#movieRecordings'), result.Items, {
showYear: true,
showParentTitle: false
});
});
}
function renderEpisodeRecordings(context) {
ApiClient.getLiveTvRecordingSeries({
2016-09-04 22:39:14 -07:00
UserId: Dashboard.getCurrentUserId(),
Limit: enableScrollX() ? 12 : 8,
IsInProgress: false,
Fields: 'CanDelete,PrimaryImageAspectRatio,BasicSyncInfo',
EnableTotalRecordCount: false,
IsSeries: true
}).then(function (result) {
renderRecordings(context.querySelector('#episodeRecordings'), result.Items, {
showItemCounts: true,
showParentTitle: false
});
2016-09-04 22:39:14 -07:00
});
}
function renderSportsRecordings(context) {
2016-09-04 22:39:14 -07:00
ApiClient.getLiveTvRecordings({
UserId: Dashboard.getCurrentUserId(),
Limit: enableScrollX() ? 12 : 8,
IsInProgress: false,
Fields: 'CanDelete,PrimaryImageAspectRatio,BasicSyncInfo',
EnableTotalRecordCount: false,
IsSports: true
2016-09-04 22:39:14 -07:00
}).then(function (result) {
renderRecordings(context.querySelector('#sportsRecordings'), result.Items, {
showYear: true,
showParentTitle: false
});
});
}
function renderKidsRecordings(context) {
ApiClient.getLiveTvRecordings({
UserId: Dashboard.getCurrentUserId(),
Limit: enableScrollX() ? 12 : 8,
IsInProgress: false,
Fields: 'CanDelete,PrimaryImageAspectRatio,BasicSyncInfo',
EnableTotalRecordCount: false,
IsKids: true
}).then(function (result) {
renderRecordings(context.querySelector('#kidsRecordings'), result.Items, {
2016-09-04 22:39:14 -07:00
showYear: true,
showParentTitle: false
});
2016-05-15 10:11:26 -07:00
});
}
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 reload(context) {
Dashboard.showLoadingMsg();
renderActiveRecordings(context);
renderLatestRecordings(context);
2016-09-04 22:39:14 -07:00
renderMovieRecordings(context);
renderEpisodeRecordings(context);
renderSportsRecordings(context);
renderKidsRecordings(context);
2016-09-04 22:39:14 -07:00
}
2016-05-15 10:11:26 -07:00
2016-09-04 22:39:14 -07:00
function onMoreClick(e) {
var type = this.getAttribute('data-type');
switch(type) {
case 'latest':
Dashboard.navigate('livetvitems.html?type=Recordings');
break;
case 'movies':
Dashboard.navigate('livetvitems.html?type=Recordings&IsMovie=true');
break;
case 'episodes':
Dashboard.navigate('livetvitems.html?type=Recordings&IsSeries=true');
break;
case 'programs':
Dashboard.navigate('livetvitems.html?type=Recordings&IsSeries=false&IsMovie=false');
break;
case 'kids':
Dashboard.navigate('livetvitems.html?type=Recordings&IsKids=true');
break;
case 'sports':
Dashboard.navigate('livetvitems.html?type=Recordings&IsSports=true');
break;
2016-09-04 22:39:14 -07:00
default:
break;
}
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-09-04 22:39:14 -07:00
var moreButtons = tabContent.querySelectorAll('.more');
for (var i = 0, length = moreButtons.length; i < length; i++) {
moreButtons[i].addEventListener('click', onMoreClick);
}
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
self.renderTab = function () {
reload(tabContent);
};
};
});