2014-10-15 20:26:39 -07:00
|
|
|
|
(function ($, document) {
|
2013-11-20 14:08:12 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
|
|
function getPageData() {
|
|
|
|
|
var key = getSavedQueryKey();
|
|
|
|
|
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
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
function getQuery() {
|
|
|
|
|
|
|
|
|
|
return getPageData().query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSavedQueryKey() {
|
|
|
|
|
|
2015-10-14 21:32:10 -07:00
|
|
|
|
return LibraryBrowser.getSavedQueryKey('channels');
|
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) {
|
|
|
|
|
|
2015-07-24 08:20:11 -07:00
|
|
|
|
return LibraryBrowser.getListViewHtml({
|
2014-01-07 11:39:35 -07:00
|
|
|
|
items: channels,
|
2015-07-24 08:20:11 -07:00
|
|
|
|
smallIcon: true
|
2014-01-07 11:39:35 -07:00
|
|
|
|
});
|
2013-11-20 14:08:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-16 21:08:33 -07:00
|
|
|
|
function renderChannels(page, viewPanel, result) {
|
2014-01-10 06:52:01 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
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,
|
2015-08-16 21:08:33 -07:00
|
|
|
|
showLimit: false,
|
2015-09-07 08:54:57 -07:00
|
|
|
|
viewPanelClass: 'channelViewPanel',
|
|
|
|
|
updatePageSizeSetting: false,
|
|
|
|
|
viewIcon: 'filter-list'
|
2015-08-16 21:08:33 -07:00
|
|
|
|
|
2015-09-05 21:53:37 -07:00
|
|
|
|
}));
|
2014-01-10 06:52:01 -07:00
|
|
|
|
|
2015-08-16 21:08:33 -07:00
|
|
|
|
updateFilterControls(viewPanel);
|
2014-05-23 16:58:28 -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;
|
2015-08-16 21:08:33 -07:00
|
|
|
|
reloadItems(page, viewPanel);
|
2014-01-10 06:52:01 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
2015-08-16 21:08:33 -07:00
|
|
|
|
reloadItems(page, viewPanel);
|
2014-01-10 06:52:01 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
|
2014-01-10 06:52:01 -07:00
|
|
|
|
}
|
2015-09-07 08:54:57 -07:00
|
|
|
|
|
2015-08-16 21:08:33 -07:00
|
|
|
|
function reloadItems(page, viewPanel) {
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2015-08-18 08:52:48 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2015-09-07 08:54:57 -07:00
|
|
|
|
|
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
|
|
|
|
query.UserId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getLiveTvChannels(query).then(function (result) {
|
2014-01-10 06:52:01 -07:00
|
|
|
|
|
2015-08-16 21:08:33 -07:00
|
|
|
|
renderChannels(page, viewPanel, result);
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2015-08-18 08:52:48 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
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
|
|
|
|
}
|
|
|
|
|
|
2014-05-23 16:58:28 -07:00
|
|
|
|
function updateFilterControls(page) {
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
2015-09-21 08:43:10 -07:00
|
|
|
|
$('.chkFavorite', page).checked(query.IsFavorite == true);
|
|
|
|
|
$('.chkLikes', page).checked(query.IsLiked == true);
|
|
|
|
|
$('.chkDislikes', page).checked(query.IsDisliked == true);
|
2014-05-23 16:58:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 08:52:48 -07:00
|
|
|
|
window.LiveTvPage.initChannelsTab = function (page, tabContent) {
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2015-08-18 08:52:48 -07:00
|
|
|
|
var viewPanel = page.querySelector('.channelViewPanel');
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2015-09-21 08:43:10 -07:00
|
|
|
|
$('.chkFavorite', viewPanel).on('change', function () {
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
2014-05-23 16:58:28 -07:00
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
query.IsFavorite = this.checked ? true : null;
|
|
|
|
|
|
2015-08-18 08:52:48 -07:00
|
|
|
|
reloadItems(tabContent, viewPanel);
|
2014-05-23 16:58:28 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2015-09-21 08:43:10 -07:00
|
|
|
|
$('.chkLikes', viewPanel).on('change', function () {
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
2014-05-23 16:58:28 -07:00
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
query.IsLiked = this.checked ? true : null;
|
|
|
|
|
|
2015-08-18 08:52:48 -07:00
|
|
|
|
reloadItems(tabContent, viewPanel);
|
2014-05-23 16:58:28 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-09-21 08:43:10 -07:00
|
|
|
|
$('.chkDislikes', viewPanel).on('change', function () {
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
2014-05-23 16:58:28 -07:00
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
query.IsDisliked = this.checked ? true : null;
|
|
|
|
|
|
2015-08-18 08:52:48 -07:00
|
|
|
|
reloadItems(tabContent, viewPanel);
|
2014-05-23 16:58:28 -07:00
|
|
|
|
});
|
2015-08-18 08:52:48 -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
|
|
|
|
var viewPanel = page.querySelector('.channelViewPanel');
|
2015-08-02 16:47:31 -07:00
|
|
|
|
|
2015-08-18 08:52:48 -07:00
|
|
|
|
if (LibraryBrowser.needsRefresh(tabContent)) {
|
|
|
|
|
reloadItems(tabContent, viewPanel);
|
|
|
|
|
updateFilterControls(viewPanel);
|
|
|
|
|
}
|
|
|
|
|
};
|
2013-11-20 14:08:12 -07:00
|
|
|
|
|
2014-10-15 20:26:39 -07:00
|
|
|
|
})(jQuery, document);
|