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

126 lines
3.1 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-11-20 14:08:12 -07:00
2015-09-07 08:54:57 -07:00
var data = {};
2016-02-26 12:02:53 -07:00
function getPageData(context) {
var key = getSavedQueryKey(context);
2015-09-07 08:54:57 -07:00
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
StartIndex: 0,
EnableFavoriteSorting: true,
Limit: LibraryBrowser.getDefaultPageSize()
}
};
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData;
}
2014-01-10 06:52:01 -07:00
2016-02-26 12:02:53 -07:00
function getQuery(context) {
2015-09-07 08:54:57 -07:00
2016-02-26 12:02:53 -07:00
return getPageData(context).query;
2015-09-07 08:54:57 -07:00
}
2016-02-26 12:02:53 -07:00
function getSavedQueryKey(context) {
2015-09-07 08:54:57 -07:00
2016-02-26 12:02:53 -07:00
if (!context.savedQueryKey) {
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('channels');
}
return context.savedQueryKey;
2015-09-07 08:54:57 -07:00
}
2014-01-10 06:52:01 -07:00
2013-11-20 14:08:12 -07:00
function getChannelsHtml(channels) {
2016-05-05 22:13:29 -07:00
return LibraryBrowser.getPosterViewHtml({
items: channels,
2016-05-05 22:13:29 -07:00
shape: "square",
showTitle: true,
lazy: true,
cardLayout: true,
showDetailsMenu: true
});
2013-11-20 14:08:12 -07:00
}
2016-02-14 19:51:05 -07:00
function renderChannels(page, result) {
2014-01-10 06:52:01 -07:00
2016-02-26 12:02:53 -07:00
var query = getQuery(page);
2015-09-07 08:54:57 -07:00
2015-01-22 23:15:15 -07:00
$('.listTopPaging', page).html(LibraryBrowser.getQueryPagingHtml({
2014-07-19 21:46:29 -07:00
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
2015-08-16 21:08:33 -07:00
showLimit: false,
2015-09-07 08:54:57 -07:00
updatePageSizeSetting: false,
2016-02-14 19:51:05 -07:00
filterButton: true
2015-09-05 21:53:37 -07:00
}));
2014-01-10 06:52:01 -07:00
var html = getChannelsHtml(result.Items);
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('#items');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
2013-11-20 14:08:12 -07:00
2014-01-10 06:52:01 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
2016-02-14 19:51:05 -07:00
reloadItems(page);
2014-01-10 06:52:01 -07:00
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
2016-02-14 19:51:05 -07:00
reloadItems(page);
});
$('.btnFilter', page).on('click', function () {
showFilterMenu(page);
2014-01-10 06:52:01 -07:00
});
2016-02-26 12:02:53 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
2014-01-10 06:52:01 -07:00
}
2015-09-07 08:54:57 -07:00
2016-02-14 19:51:05 -07:00
function showFilterMenu(page) {
2015-09-07 08:54:57 -07:00
2016-02-14 19:51:05 -07:00
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
2014-01-10 06:52:01 -07:00
2016-02-14 19:51:05 -07:00
var filterDialog = new filterDialogFactory({
2016-02-26 12:02:53 -07:00
query: getQuery(page),
2016-02-14 19:51:05 -07:00
mode: 'livetvchannels'
});
2016-02-14 19:51:05 -07:00
Events.on(filterDialog, 'filterchange', function () {
reloadItems(page);
});
2015-06-29 22:45:20 -07:00
2016-02-14 19:51:05 -07:00
filterDialog.show();
2014-01-10 06:52:01 -07:00
});
2013-11-20 14:08:12 -07:00
}
2016-02-14 19:51:05 -07:00
function reloadItems(page) {
2016-02-14 19:51:05 -07:00
Dashboard.showLoadingMsg();
2016-02-26 12:02:53 -07:00
var query = getQuery(page);
2016-02-14 19:51:05 -07:00
query.UserId = Dashboard.getCurrentUserId();
2016-02-14 19:51:05 -07:00
ApiClient.getLiveTvChannels(query).then(function (result) {
2016-02-14 19:51:05 -07:00
renderChannels(page, result);
2016-02-14 19:51:05 -07:00
Dashboard.hideLoadingMsg();
2016-02-14 19:51:05 -07:00
LibraryBrowser.setLastRefreshed(page);
});
2016-02-14 19:51:05 -07:00
}
2014-07-19 21:46:29 -07:00
2015-08-18 08:52:48 -07:00
window.LiveTvPage.renderChannelsTab = function (page, tabContent) {
2015-08-02 16:47:31 -07:00
2015-08-18 08:52:48 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
2016-02-14 19:51:05 -07:00
reloadItems(tabContent);
2015-08-18 08:52:48 -07:00
}
};
2013-11-20 14:08:12 -07:00
});