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

138 lines
3.7 KiB
JavaScript
Raw Normal View History

2014-10-15 20:26:39 -07:00
(function ($, document) {
2013-11-20 14:08:12 -07:00
2014-01-10 06:52:01 -07:00
var query = {
2015-04-11 18:38:38 -07:00
StartIndex: 0,
EnableFavoriteSorting: true
2014-01-10 06:52:01 -07:00
};
2013-11-20 14:08:12 -07:00
function getChannelsHtml(channels) {
2015-07-24 08:20:11 -07:00
return LibraryBrowser.getListViewHtml({
items: channels,
2015-07-24 08:20:11 -07:00
smallIcon: true
});
2013-11-20 14:08:12 -07:00
}
function showLoadingMessage(page) {
2015-06-16 10:37:49 -07:00
Dashboard.showLoadingMsg();
}
function hideLoadingMessage(page) {
2015-06-16 10:37:49 -07:00
Dashboard.hideLoadingMsg();
}
2014-01-10 06:52:01 -07:00
function renderChannels(page, result) {
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,
viewButton: true,
showLimit: false
2015-01-22 23:15:15 -07:00
})).trigger('create');
2014-01-10 06:52:01 -07:00
updateFilterControls(this);
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);
2015-07-24 08:20:11 -07:00
$(elem).trigger('create');
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;
reloadItems(page);
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
LibraryBrowser.saveQueryValues('movies', query);
}
function reloadItems(page) {
showLoadingMessage(page);
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvChannels(query).done(function (result) {
2014-01-10 06:52:01 -07:00
renderChannels(page, result);
hideLoadingMessage(page);
2015-06-29 22:45:20 -07:00
LibraryBrowser.setLastRefreshed(page);
2014-01-10 06:52:01 -07:00
});
2013-11-20 14:08:12 -07:00
}
function updateFilterControls(page) {
$('#chkFavorite', page).checked(query.IsFavorite == true).checkboxradio('refresh');
$('#chkLikes', page).checked(query.IsLiked == true).checkboxradio('refresh');
$('#chkDislikes', page).checked(query.IsDisliked == true).checkboxradio('refresh');
2014-07-19 21:46:29 -07:00
$('#selectPageSize', page).val(query.Limit).selectmenu('refresh');
}
2015-08-02 16:47:31 -07:00
$(document).on('pageinitdepends', "#liveTvSuggestedPage", function () {
2015-08-02 16:47:31 -07:00
var page = this.querySelector('.channelsTabContent');
2015-08-02 16:47:31 -07:00
$('#chkFavorite', page).on('change', function () {
query.StartIndex = 0;
query.IsFavorite = this.checked ? true : null;
reloadItems(page);
});
2015-08-02 16:47:31 -07:00
$('#chkLikes', page).on('change', function () {
query.StartIndex = 0;
query.IsLiked = this.checked ? true : null;
reloadItems(page);
});
2015-08-02 16:47:31 -07:00
$('#chkDislikes', page).on('change', function () {
query.StartIndex = 0;
query.IsDisliked = this.checked ? true : null;
reloadItems(page);
});
2014-07-19 21:46:29 -07:00
$('#selectPageSize', page).on('change', function () {
query.Limit = parseInt(this.value);
query.StartIndex = 0;
reloadItems(page);
});
2015-08-02 16:47:31 -07:00
});
$(document).on('pageinitdepends', "#liveTvSuggestedPage", function () {
2013-11-20 14:08:12 -07:00
var page = this;
2015-08-02 16:47:31 -07:00
$(page.querySelector('neon-animated-pages')).on('tabchange', function () {
if (parseInt(this.selected) == 2) {
var tabContent = page.querySelector('.channelsTabContent');
if (LibraryBrowser.needsRefresh(tabContent)) {
query.UserId = Dashboard.getCurrentUserId();
LibraryBrowser.loadSavedQueryValues('movies', query);
query.Limit = query.Limit || LibraryBrowser.getDefaultPageSize();
reloadItems(tabContent);
updateFilterControls(this);
}
}
});
2013-11-20 14:08:12 -07:00
});
2014-10-15 20:26:39 -07:00
})(jQuery, document);