2016-07-29 13:06:58 -07:00
|
|
|
|
define(['cardBuilder', 'emby-itemscontainer'], function (cardBuilder) {
|
2016-05-15 10:11:26 -07:00
|
|
|
|
|
|
|
|
|
return function (view, params, tabContent) {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
|
|
function getPageData(context) {
|
|
|
|
|
var key = getSavedQueryKey(context);
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
EnableFavoriteSorting: true,
|
2016-08-17 12:28:43 -07:00
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize(),
|
|
|
|
|
Fields: "PrimaryImageAspectRatio"
|
2016-05-15 10:11:26 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQuery(context) {
|
|
|
|
|
|
|
|
|
|
return getPageData(context).query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSavedQueryKey(context) {
|
|
|
|
|
|
|
|
|
|
if (!context.savedQueryKey) {
|
|
|
|
|
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('channels');
|
|
|
|
|
}
|
|
|
|
|
return context.savedQueryKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getChannelsHtml(channels) {
|
|
|
|
|
|
2016-07-29 13:06:58 -07:00
|
|
|
|
return cardBuilder.getCardsHtml({
|
2016-05-15 10:11:26 -07:00
|
|
|
|
items: channels,
|
|
|
|
|
shape: "square",
|
|
|
|
|
showTitle: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
2016-08-27 18:05:32 -07:00
|
|
|
|
showDetailsMenu: true,
|
|
|
|
|
showCurrentProgram: true
|
2016-05-15 10:11:26 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderChannels(context, result) {
|
|
|
|
|
|
|
|
|
|
var query = getQuery(context);
|
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
context.querySelector('.paging').innerHTML = LibraryBrowser.getQueryPagingHtml({
|
2016-05-15 10:11:26 -07:00
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
showLimit: false,
|
|
|
|
|
updatePageSizeSetting: false,
|
2016-06-18 10:26:42 -07:00
|
|
|
|
filterButton: false
|
|
|
|
|
});
|
2016-05-15 10:11:26 -07:00
|
|
|
|
|
|
|
|
|
var html = getChannelsHtml(result.Items);
|
|
|
|
|
|
|
|
|
|
var elem = context.querySelector('#items');
|
|
|
|
|
elem.innerHTML = html;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
var i, length;
|
|
|
|
|
var elems;
|
|
|
|
|
|
|
|
|
|
function onNextPageClick() {
|
2016-05-15 10:11:26 -07:00
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(context);
|
2016-06-18 10:26:42 -07:00
|
|
|
|
}
|
2016-05-15 10:11:26 -07:00
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
function onPreviousPageClick() {
|
2016-05-15 10:11:26 -07:00
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(context);
|
2016-06-18 10:26:42 -07:00
|
|
|
|
}
|
2016-05-15 10:11:26 -07:00
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
elems = context.querySelectorAll('.btnNextPage');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('click', onNextPageClick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elems = context.querySelectorAll('.btnPreviousPage');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('click', onPreviousPageClick);
|
|
|
|
|
}
|
2016-05-15 10:11:26 -07:00
|
|
|
|
|
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(context), query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showFilterMenu(context) {
|
|
|
|
|
|
|
|
|
|
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
|
|
|
|
|
|
|
|
|
|
var filterDialog = new filterDialogFactory({
|
|
|
|
|
query: getQuery(context),
|
|
|
|
|
mode: 'livetvchannels'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
|
|
|
|
reloadItems(context);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
filterDialog.show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reloadItems(context) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var query = getQuery(context);
|
|
|
|
|
|
|
|
|
|
query.UserId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
|
|
|
|
ApiClient.getLiveTvChannels(query).then(function (result) {
|
|
|
|
|
|
|
|
|
|
renderChannels(context, result);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
tabContent.querySelector('.btnFilter').addEventListener('click', function () {
|
|
|
|
|
showFilterMenu(tabContent);
|
|
|
|
|
});
|
|
|
|
|
|
2016-05-15 10:11:26 -07:00
|
|
|
|
self.renderTab = function () {
|
|
|
|
|
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|