2016-04-25 19:17:11 -07:00
|
|
|
|
define(['events', 'libraryBrowser', 'imageLoader', 'jQuery'], function (events, libraryBrowser, imageLoader, $) {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
|
|
|
|
return function (view, params, tabContent) {
|
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
var self = this;
|
|
|
|
|
var pageSize = libraryBrowser.getDefaultPageSize();
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
|
|
function getPageData(context) {
|
|
|
|
|
var key = getSavedQueryKey(context);
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "SeriesSortName,SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
IncludeItemTypes: "Episode",
|
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,MediaSourceCount,UserData,SyncInfo",
|
|
|
|
|
IsMissing: false,
|
|
|
|
|
IsVirtualUnaired: false,
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
StartIndex: 0,
|
2016-04-23 21:24:16 -07:00
|
|
|
|
Limit: pageSize
|
2016-03-18 12:43:17 -07:00
|
|
|
|
},
|
2016-04-23 21:24:16 -07:00
|
|
|
|
view: libraryBrowser.getSavedView(key) || libraryBrowser.getDefaultItemsView('Poster', 'Poster')
|
2016-03-18 12:43:17 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pageData.query.ParentId = params.topParentId;
|
2016-04-23 21:24:16 -07:00
|
|
|
|
libraryBrowser.loadSavedQueryValues(key, pageData.query);
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
|
|
|
|
return pageData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQuery(context) {
|
|
|
|
|
|
|
|
|
|
return getPageData(context).query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSavedQueryKey(context) {
|
|
|
|
|
|
|
|
|
|
if (!context.savedQueryKey) {
|
2016-04-23 21:24:16 -07:00
|
|
|
|
context.savedQueryKey = libraryBrowser.getSavedQueryKey('episodes');
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
|
|
|
|
return context.savedQueryKey;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
function reloadItems(page) {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
var query = getQuery(page);
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-29 20:59:59 -07:00
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
|
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
showLimit: false,
|
|
|
|
|
updatePageSizeSetting: false,
|
|
|
|
|
addLayoutButton: false,
|
|
|
|
|
sortButton: false,
|
|
|
|
|
filterButton: false
|
2016-04-23 21:24:16 -07:00
|
|
|
|
});
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
var viewStyle = self.getCurrentViewStyle();
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
var html;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
if (viewStyle == "List") {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
html = libraryBrowser.getListViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
sortBy: query.SortBy
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (viewStyle == "PosterCard") {
|
|
|
|
|
html = libraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showParentTitle: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showDetailsMenu: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
// poster
|
|
|
|
|
html = libraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showParentTitle: true,
|
|
|
|
|
overlayText: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
showDetailsMenu: true,
|
|
|
|
|
overlayPlayButton: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
$('.paging', tabContent).html(pagingHtml);
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
$('.btnNextPage', tabContent).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
});
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
$('.btnPreviousPage', tabContent).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
});
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
var itemsContainer = tabContent.querySelector('.itemsContainer');
|
|
|
|
|
itemsContainer.innerHTML = html;
|
|
|
|
|
imageLoader.lazyChildren(itemsContainer);
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
self.showFilterMenu = function () {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
|
|
|
|
|
|
|
|
|
|
var filterDialog = new filterDialogFactory({
|
2016-04-23 21:24:16 -07:00
|
|
|
|
query: getQuery(tabContent),
|
2016-03-18 12:43:17 -07:00
|
|
|
|
mode: 'episodes'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
2016-04-23 21:24:16 -07:00
|
|
|
|
reloadItems(tabContent);
|
2016-03-18 12:43:17 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
filterDialog.show();
|
|
|
|
|
});
|
2016-04-23 21:24:16 -07:00
|
|
|
|
};
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
|
|
|
|
function initPage(tabContent) {
|
|
|
|
|
|
2016-06-01 23:08:47 -07:00
|
|
|
|
tabContent.querySelector('.itemsContainer').addEventListener('needsrefresh', function () {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
});
|
2016-04-23 21:24:16 -07:00
|
|
|
|
|
|
|
|
|
tabContent.querySelector('.btnFilter').addEventListener('click', function () {
|
|
|
|
|
self.showFilterMenu();
|
|
|
|
|
});
|
|
|
|
|
|
2016-04-25 11:33:17 -07:00
|
|
|
|
tabContent.querySelector('.btnSort').addEventListener('click', function (e) {
|
2016-04-23 21:24:16 -07:00
|
|
|
|
libraryBrowser.showSortMenu({
|
|
|
|
|
items: [{
|
|
|
|
|
name: Globalize.translate('OptionNameSort'),
|
|
|
|
|
id: 'SeriesSortName,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionTvdbRating'),
|
|
|
|
|
id: 'CommunityRating,SeriesSortName,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionDateAdded'),
|
|
|
|
|
id: 'DateCreated,SeriesSortName,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionPremiereDate'),
|
|
|
|
|
id: 'PremiereDate,SeriesSortName,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionDatePlayed'),
|
|
|
|
|
id: 'DatePlayed,SeriesSortName,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionParentalRating'),
|
|
|
|
|
id: 'OfficialRating,SeriesSortName,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionPlayCount'),
|
|
|
|
|
id: 'PlayCount,SeriesSortName,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionRuntime'),
|
|
|
|
|
id: 'Runtime,SeriesSortName,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionVideoBitrate'),
|
|
|
|
|
id: 'VideoBitRate,SeriesSortName,SortName'
|
|
|
|
|
}],
|
|
|
|
|
callback: function () {
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
},
|
2016-04-25 11:33:17 -07:00
|
|
|
|
query: getQuery(tabContent),
|
|
|
|
|
button: e.target
|
2016-04-23 21:24:16 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tabContent.querySelector('.btnSelectView').addEventListener('click', function (e) {
|
|
|
|
|
|
|
|
|
|
libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), 'List,Poster,PosterCard'.split(','));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tabContent.querySelector('.btnSelectView').addEventListener('layoutchange', function (e) {
|
|
|
|
|
|
|
|
|
|
var viewStyle = e.detail.viewStyle;
|
|
|
|
|
getPageData(tabContent).view = viewStyle;
|
|
|
|
|
libraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
});
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
self.getCurrentViewStyle = function () {
|
|
|
|
|
return getPageData(tabContent).view;
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-18 18:40:13 -07:00
|
|
|
|
initPage(tabContent);
|
2016-04-23 21:24:16 -07:00
|
|
|
|
|
|
|
|
|
self.renderTab = function () {
|
|
|
|
|
|
2016-04-25 19:17:11 -07:00
|
|
|
|
reloadItems(tabContent);
|
2016-04-23 21:24:16 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.destroy = function () {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|