2016-04-23 21:24:16 -07:00
|
|
|
|
define(['ironCardList', 'scrollThreshold', 'events', 'libraryBrowser', 'jQuery'], function (ironCardList, scrollThreshold, events, libraryBrowser, $) {
|
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: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
IncludeItemTypes: "Series",
|
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
|
|
|
|
|
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 22:27:12 -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('series');
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
|
|
|
|
return context.savedQueryKey;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
function setCardOptions(result) {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
var cardOptions;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
var view = self.getCurrentViewStyle();
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
if (view == "Thumb") {
|
|
|
|
|
|
|
|
|
|
cardOptions = {
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
context: 'tv',
|
|
|
|
|
lazy: true,
|
|
|
|
|
overlayPlayButton: true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else if (view == "ThumbCard") {
|
|
|
|
|
|
|
|
|
|
cardOptions = {
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
context: 'tv',
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showSeriesYear: true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else if (view == "Banner") {
|
|
|
|
|
|
|
|
|
|
cardOptions = {
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "banner",
|
|
|
|
|
preferBanner: true,
|
|
|
|
|
context: 'tv',
|
|
|
|
|
lazy: true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else if (view == "List") {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
html = libraryBrowser.getListViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
context: 'tv',
|
|
|
|
|
sortBy: query.SortBy
|
2016-03-18 12:43:17 -07:00
|
|
|
|
});
|
2016-04-23 21:24:16 -07:00
|
|
|
|
}
|
|
|
|
|
else if (view == "PosterCard") {
|
|
|
|
|
cardOptions = {
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "portrait",
|
|
|
|
|
context: 'tv',
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showYear: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
// Poster
|
|
|
|
|
cardOptions = {
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "portrait",
|
|
|
|
|
context: 'tv',
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
overlayPlayButton: true
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
self.cardOptions = cardOptions;
|
|
|
|
|
}
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
function reloadItems(page) {
|
|
|
|
|
|
|
|
|
|
self.isLoading = true;
|
|
|
|
|
Dashboard.showLoadingMsg();
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
var query = getQuery(page);
|
|
|
|
|
var startIndex = query.StartIndex;
|
|
|
|
|
var reloadList = !self.cardOptions || startIndex == 0;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
updateFilterControls(page);
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
var pushItems = true;
|
|
|
|
|
if (reloadList) {
|
|
|
|
|
setCardOptions(result);
|
|
|
|
|
pushItems = false;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
2016-04-23 21:24:16 -07:00
|
|
|
|
libraryBrowser.setPosterViewData(self.cardOptions);
|
|
|
|
|
libraryBrowser.setPosterViewDataOnItems(self.cardOptions, result.Items);
|
|
|
|
|
|
|
|
|
|
var ironList = page.querySelector('#ironList');
|
|
|
|
|
if (pushItems) {
|
|
|
|
|
for (var i = 0, length = result.Items.length; i < length; i++) {
|
|
|
|
|
ironList.push('items', result.Items[i]);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ironList.items = result.Items;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
// Hack: notifyResize needs to be done after the items have been rendered
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
ironList.notifyResize();
|
|
|
|
|
self.scrollThreshold.resetSize();
|
|
|
|
|
}, 300);
|
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.hasMoreItems = result.TotalRecordCount > (startIndex + result.Items.length);
|
|
|
|
|
self.isLoading = false;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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: 'series'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
2016-04-23 21:24:16 -07:00
|
|
|
|
getQuery(tabContent).StartIndex = 0;
|
|
|
|
|
reloadItems(tabContent);
|
2016-03-18 12:43:17 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
filterDialog.show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateFilterControls(tabContent) {
|
|
|
|
|
|
|
|
|
|
var query = getQuery(tabContent);
|
|
|
|
|
$('.alphabetPicker', tabContent).alphaValue(query.NameStartsWith);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initPage(tabContent) {
|
|
|
|
|
|
|
|
|
|
$('.alphabetPicker', tabContent).on('alphaselect', function (e, character) {
|
|
|
|
|
|
|
|
|
|
var query = getQuery(tabContent);
|
|
|
|
|
query.NameStartsWithOrGreater = character;
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
|
|
|
|
|
}).on('alphaclear', function (e) {
|
|
|
|
|
|
|
|
|
|
var query = getQuery(tabContent);
|
|
|
|
|
query.NameStartsWithOrGreater = '';
|
2016-04-23 21:24:16 -07:00
|
|
|
|
getQuery(tabContent).StartIndex = 0;
|
|
|
|
|
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
});
|
2016-03-18 12:43:17 -07:00
|
|
|
|
|
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: 'SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionImdbRating'),
|
|
|
|
|
id: 'CommunityRating,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionDateAdded'),
|
|
|
|
|
id: 'DateCreated,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionDatePlayed'),
|
|
|
|
|
id: 'DatePlayed,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionMetascore'),
|
|
|
|
|
id: 'Metascore,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionParentalRating'),
|
|
|
|
|
id: 'OfficialRating,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionPlayCount'),
|
|
|
|
|
id: 'PlayCount,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionReleaseDate'),
|
|
|
|
|
id: 'PremiereDate,SortName'
|
|
|
|
|
}],
|
|
|
|
|
callback: function () {
|
|
|
|
|
getQuery(tabContent).StartIndex = 0;
|
|
|
|
|
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(), 'Banner,List,Poster,PosterCard,Thumb,ThumbCard'.split(','));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tabContent.querySelector('.btnSelectView').addEventListener('layoutchange', function (e) {
|
|
|
|
|
|
|
|
|
|
var viewStyle = e.detail.viewStyle;
|
|
|
|
|
|
|
|
|
|
getPageData(tabContent).view = viewStyle;
|
|
|
|
|
libraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
|
|
|
|
|
getQuery(tabContent).StartIndex = 0;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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-03-18 12:43:17 -07:00
|
|
|
|
|
2016-04-23 21:24:16 -07:00
|
|
|
|
function createList() {
|
|
|
|
|
|
|
|
|
|
if (self.listCreated) {
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ironCardList.getTemplate('seriesTab').then(function (html) {
|
|
|
|
|
|
|
|
|
|
tabContent.querySelector('.itemsContainer').innerHTML = html;
|
|
|
|
|
self.listCreated = true;
|
2016-04-25 11:33:17 -07:00
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
|
|
|
|
|
setTimeout(resolve, 2000);
|
|
|
|
|
});
|
2016-04-23 21:24:16 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadMoreItems() {
|
|
|
|
|
|
|
|
|
|
if (!self.isLoading && self.hasMoreItems) {
|
|
|
|
|
|
|
|
|
|
getQuery(tabContent).StartIndex += pageSize;
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.scrollThreshold = new scrollThreshold(tabContent, false);
|
|
|
|
|
events.on(self.scrollThreshold, 'lower-threshold', loadMoreItems);
|
|
|
|
|
|
|
|
|
|
self.renderTab = function () {
|
|
|
|
|
|
|
|
|
|
createList().then(function () {
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
updateFilterControls(tabContent);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.destroy = function () {
|
|
|
|
|
events.off(self.scrollThreshold, 'lower-threshold', loadMoreItems);
|
|
|
|
|
if (self.scrollThreshold) {
|
|
|
|
|
self.scrollThreshold.destroy();
|
|
|
|
|
}
|
2016-03-18 12:43:17 -07:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|