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

183 lines
6.5 KiB
JavaScript
Raw Normal View History

2016-07-29 13:06:58 -07:00
define(['cardBuilder', 'emby-itemscontainer'], function (cardBuilder) {
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
return function (view, params) {
// The base query options
var query = {
UserId: Dashboard.getCurrentUserId(),
StartIndex: 0,
Fields: "ChannelInfo"
};
if (params.type == 'Recordings') {
query.IsInProgress = false;
2016-09-07 00:08:20 -07:00
if (params.groupid) {
query.GroupId = params.groupid;
}
} else if (params.type == 'RecordingSeries') {
query.SortOrder = 'SortName';
query.SortOrder = 'Ascending';
2016-09-04 22:39:14 -07:00
} else {
query.HasAired = false;
query.SortBy = 'StartDate,SortName';
query.SortOrder = 'Ascending';
}
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
function getSavedQueryKey() {
return LibraryBrowser.getSavedQueryKey();
}
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
function reloadItems(page) {
Dashboard.showLoadingMsg();
var promise = params.type == 'Recordings' ?
ApiClient.getLiveTvRecordings(query) :
2016-09-06 22:48:14 -07:00
params.type == 'RecordingSeries' ?
ApiClient.getLiveTvRecordingSeries(query) :
2016-09-08 13:32:30 -07:00
params.IsAiring == 'true' ?
ApiClient.getLiveTvRecommendedPrograms(query) :
2016-09-04 22:39:14 -07:00
ApiClient.getLiveTvPrograms(query);
promise.then(function (result) {
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
var html = '';
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false
});
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
html = cardBuilder.getCardsHtml({
items: result.Items,
2016-09-06 22:48:14 -07:00
shape: query.IsMovie || params.type == 'RecordingSeries' ? 'portrait' : "backdrop",
preferThumb: !query.IsMovie && params.type != 'RecordingSeries',
2016-09-04 22:39:14 -07:00
context: 'livetv',
centerText: true,
lazy: true,
overlayText: false,
showTitle: true,
2016-09-07 13:11:16 -07:00
showParentTitle: query.IsSeries !== false && !query.IsMovie,
2016-09-06 22:48:14 -07:00
showProgramAirInfo: params.type != 'Recordings' && params.type != 'RecordingSeries',
2016-09-04 22:39:14 -07:00
overlayMoreButton: true,
2016-09-08 13:32:30 -07:00
showYear: query.IsMovie && params.type == 'Recordings',
coverImage: true
2016-09-04 22:39:14 -07:00
});
var elem = page.querySelector('.itemsContainer');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
var i, length;
var elems;
function onNextPageClick() {
query.StartIndex += query.Limit;
reloadItems(page);
}
function onPreviousPageClick() {
query.StartIndex -= query.Limit;
reloadItems(page);
}
elems = page.querySelectorAll('.btnNextPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onNextPageClick);
}
elems = page.querySelectorAll('.btnPreviousPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onPreviousPageClick);
}
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
Dashboard.hideLoadingMsg();
2015-03-14 13:56:50 -07:00
});
2016-09-04 22:39:14 -07:00
}
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
view.addEventListener('viewbeforeshow', function () {
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
query.ParentId = LibraryMenu.getTopParentId();
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
var page = this;
var limit = LibraryBrowser.getDefaultPageSize();
2016-06-18 10:26:42 -07:00
2016-09-04 22:39:14 -07:00
// If the default page size has changed, the start index will have to be reset
if (limit != query.Limit) {
query.Limit = limit;
query.StartIndex = 0;
2016-06-18 10:26:42 -07:00
}
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
if (params.IsMovie == 'true') {
query.IsMovie = true;
2016-06-18 10:26:42 -07:00
}
else if (params.IsMovie == 'false') {
2016-09-04 22:39:14 -07:00
query.IsMovie = false;
2016-06-18 10:26:42 -07:00
}
2016-09-04 22:39:14 -07:00
if (params.IsSports == 'true') {
query.IsSports = true;
}
else if (params.IsSports == 'false') {
2016-09-04 22:39:14 -07:00
query.IsSports = false;
}
if (params.IsKids == 'true') {
query.IsKids = true;
}
else if (params.IsKids == 'false') {
2016-09-04 22:39:14 -07:00
query.IsKids = false;
2016-06-18 10:26:42 -07:00
}
2016-09-08 13:32:30 -07:00
if (params.IsAiring == 'true') {
query.IsAiring = true;
}
else if (params.IsAiring == 'false') {
query.IsAiring = false;
}
2015-03-14 13:56:50 -07:00
2016-09-07 23:15:44 -07:00
if (params.type == 'Recordings') {
2016-09-08 13:32:30 -07:00
if (params.IsMovie == 'true') {
2016-09-07 23:15:44 -07:00
LibraryMenu.setTitle(Globalize.translate('TabMovies'));
2016-09-08 13:32:30 -07:00
} else if (params.IsSports == 'true') {
2016-09-07 23:15:44 -07:00
LibraryMenu.setTitle(Globalize.translate('Sports'));
2016-09-08 13:32:30 -07:00
} else if (params.IsKids == 'true') {
2016-09-07 23:15:44 -07:00
LibraryMenu.setTitle(Globalize.translate('HeaderForKids'));
} else {
LibraryMenu.setTitle(Globalize.translate('TabRecordings'));
}
} else if (params.type == 'RecordingSeries') {
LibraryMenu.setTitle(Globalize.translate('TabSeries'));
} else {
2016-09-08 13:32:30 -07:00
if (params.IsMovie == 'true') {
2016-09-07 23:15:44 -07:00
LibraryMenu.setTitle(Globalize.translate('HeaderUpcomingMovies'));
2016-09-08 13:32:30 -07:00
} else if (params.IsSports == 'true') {
2016-09-07 23:15:44 -07:00
LibraryMenu.setTitle(Globalize.translate('HeaderUpcomingSports'));
2016-09-08 13:32:30 -07:00
} else if (params.IsKids == 'true') {
2016-09-07 23:15:44 -07:00
LibraryMenu.setTitle(Globalize.translate('HeaderUpcomingForKids'));
2016-09-08 13:32:30 -07:00
} else if (params.IsAiring == 'true') {
LibraryMenu.setTitle(Globalize.translate('HeaderWhatsOnTV'));
2016-09-07 23:15:44 -07:00
} else {
LibraryMenu.setTitle(Globalize.translate('HeaderUpcomingPrograms'));
}
}
2016-09-04 22:39:14 -07:00
var viewkey = getSavedQueryKey();
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
LibraryBrowser.loadSavedQueryValues(viewkey, query);
2015-03-14 13:56:50 -07:00
2016-09-04 22:39:14 -07:00
reloadItems(page);
});
};
});