2016-06-14 13:59:30 -07:00
|
|
|
|
define(['alphaPicker'], function (alphaPicker) {
|
2013-04-01 17:54:06 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -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: {
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
IncludeItemTypes: "Movie",
|
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,MediaSourceCount,SyncInfo",
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
|
|
|
|
},
|
|
|
|
|
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pageData.query.ParentId = params.topParentId;
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
2015-07-06 09:40:55 -07:00
|
|
|
|
}
|
2015-08-15 11:46:57 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
function getQuery(context) {
|
2015-08-15 11:46:57 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
return getPageData(context).query;
|
|
|
|
|
}
|
2013-04-01 20:28:20 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
function getSavedQueryKey(context) {
|
2014-05-01 19:54:33 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
if (!context.savedQueryKey) {
|
|
|
|
|
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('movies');
|
|
|
|
|
}
|
|
|
|
|
return context.savedQueryKey;
|
2016-02-26 12:02:53 -07:00
|
|
|
|
}
|
2014-05-01 19:54:33 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
function reloadItems(context) {
|
2013-04-01 20:28:20 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-04-10 22:27:27 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
var userId = Dashboard.getCurrentUserId();
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
var query = getQuery(context);
|
|
|
|
|
var view = getPageData(context).view;
|
|
|
|
|
|
|
|
|
|
ApiClient.getItems(userId, query).then(function (result) {
|
|
|
|
|
|
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
|
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
showLimit: false,
|
|
|
|
|
updatePageSizeSetting: false,
|
|
|
|
|
addLayoutButton: true,
|
|
|
|
|
sortButton: true,
|
|
|
|
|
currentLayout: view,
|
|
|
|
|
layouts: 'Banner,List,Poster,PosterCard,Thumb,ThumbCard,Timeline',
|
|
|
|
|
filterButton: true
|
|
|
|
|
});
|
2013-04-01 17:54:06 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
context.querySelector('.listTopPaging').innerHTML = pagingHtml;
|
2013-05-17 12:18:54 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
updateFilterControls(context);
|
2013-04-08 14:05:00 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
if (view == "Thumb") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
showDetailsMenu: true,
|
|
|
|
|
overlayPlayButton: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "ThumbCard") {
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
showTitle: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showYear: true,
|
|
|
|
|
showDetailsMenu: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "Banner") {
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "banner",
|
|
|
|
|
preferBanner: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
showDetailsMenu: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "List") {
|
2015-01-28 12:30:45 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
html = LibraryBrowser.getListViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
sortBy: query.SortBy
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "Poster") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "portrait",
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
showDetailsMenu: true,
|
|
|
|
|
overlayPlayButton: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "PosterCard") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "portrait",
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showYear: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showDetailsMenu: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "Timeline") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "portrait",
|
|
|
|
|
showTitle: true,
|
|
|
|
|
timeline: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
showDetailsMenu: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-04-08 14:05:00 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
var elem = context.querySelector('.itemsContainer');
|
|
|
|
|
elem.innerHTML = html + pagingHtml;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-06-14 13:59:30 -07:00
|
|
|
|
function onNextPageClick() {
|
2016-04-03 11:47:49 -07:00
|
|
|
|
query.StartIndex += query.Limit;
|
2016-06-14 13:59:30 -07:00
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
}
|
2014-07-05 09:51:39 -07:00
|
|
|
|
|
2016-06-14 13:59:30 -07:00
|
|
|
|
function onPreviousPageClick() {
|
2016-04-03 11:47:49 -07:00
|
|
|
|
query.StartIndex -= query.Limit;
|
2016-06-14 13:59:30 -07:00
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
}
|
2013-04-08 14:05:00 -07:00
|
|
|
|
|
2016-06-14 13:59:30 -07:00
|
|
|
|
var elems, i, length;
|
|
|
|
|
elems = tabContent.querySelectorAll('.btnNextPage');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('click', onNextPageClick);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elems = tabContent.querySelectorAll('.btnPreviousPage');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('click', onPreviousPageClick);
|
|
|
|
|
}
|
2013-04-01 20:28:20 -07:00
|
|
|
|
|
2016-06-14 13:59:30 -07:00
|
|
|
|
function onChangeLayout(e) {
|
|
|
|
|
var layout = e.detail.viewStyle;
|
2016-04-03 11:47:49 -07:00
|
|
|
|
if (layout == 'Timeline') {
|
|
|
|
|
getQuery(context).SortBy = 'ProductionYear,PremiereDate,SortName';
|
|
|
|
|
getQuery(context).SortOrder = 'Descending';
|
|
|
|
|
}
|
2013-04-15 15:03:05 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
getPageData(context).view = layout;
|
|
|
|
|
LibraryBrowser.saveViewSetting(getSavedQueryKey(context), layout);
|
|
|
|
|
reloadItems(context);
|
2016-06-14 13:59:30 -07:00
|
|
|
|
}
|
2013-04-08 14:05:00 -07:00
|
|
|
|
|
2016-06-14 13:59:30 -07:00
|
|
|
|
elems = tabContent.querySelectorAll('.btnChangeLayout');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('layoutchange', onChangeLayout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onFilterClick() {
|
2016-04-03 11:47:49 -07:00
|
|
|
|
showFilterMenu(context);
|
2016-06-14 13:59:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elems = tabContent.querySelectorAll('.btnFilter');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('click', onFilterClick);
|
|
|
|
|
}
|
2015-10-02 11:30:27 -07:00
|
|
|
|
|
2016-06-14 13:59:30 -07:00
|
|
|
|
function onSortClick() {
|
2016-04-03 11:47:49 -07:00
|
|
|
|
LibraryBrowser.showSortMenu({
|
|
|
|
|
items: [{
|
|
|
|
|
name: Globalize.translate('OptionNameSort'),
|
|
|
|
|
id: 'SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionBudget'),
|
|
|
|
|
id: 'Budget,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionImdbRating'),
|
|
|
|
|
id: 'CommunityRating,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionCriticRating'),
|
|
|
|
|
id: 'CriticRating,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'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionRevenue'),
|
|
|
|
|
id: 'Revenue,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionRuntime'),
|
|
|
|
|
id: 'Runtime,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionVideoBitrate'),
|
|
|
|
|
id: 'VideoBitRate,SortName'
|
|
|
|
|
}],
|
|
|
|
|
callback: function () {
|
|
|
|
|
reloadItems(context);
|
|
|
|
|
},
|
|
|
|
|
query: query
|
|
|
|
|
});
|
2016-06-14 13:59:30 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elems = tabContent.querySelectorAll('.btnSort');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('click', onSortClick);
|
|
|
|
|
}
|
2015-10-02 11:30:27 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(context), query);
|
2016-02-15 08:51:08 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2015-08-25 19:13:28 -07:00
|
|
|
|
});
|
2016-04-03 11:47:49 -07:00
|
|
|
|
}
|
2015-08-25 19:13:28 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
function showFilterMenu(context) {
|
2013-04-01 17:54:06 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
var filterDialog = new filterDialogFactory({
|
|
|
|
|
query: getQuery(context),
|
|
|
|
|
mode: 'movies'
|
|
|
|
|
});
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
|
|
|
|
reloadItems(context);
|
|
|
|
|
});
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
filterDialog.show();
|
2016-02-15 08:51:08 -07:00
|
|
|
|
});
|
2016-04-03 11:47:49 -07:00
|
|
|
|
}
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
function updateFilterControls(context) {
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
var query = getQuery(context);
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2016-06-06 22:42:26 -07:00
|
|
|
|
self.alphaPicker.value(query.NameStartsWithOrGreater);
|
2016-04-03 11:47:49 -07:00
|
|
|
|
}
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
function initPage(context) {
|
2013-10-26 15:01:21 -07:00
|
|
|
|
|
2016-06-06 22:42:26 -07:00
|
|
|
|
var alphaPickerElement = context.querySelector('.alphaPicker');
|
|
|
|
|
alphaPickerElement.addEventListener('alphavaluechanged', function (e) {
|
|
|
|
|
var newValue = e.detail.value;
|
2016-04-03 11:47:49 -07:00
|
|
|
|
var query = getQuery(context);
|
2016-06-06 22:42:26 -07:00
|
|
|
|
query.NameStartsWithOrGreater = newValue;
|
2016-04-03 11:47:49 -07:00
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
reloadItems(context);
|
2016-06-06 22:42:26 -07:00
|
|
|
|
});
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-06-06 22:42:26 -07:00
|
|
|
|
self.alphaPicker = new alphaPicker({
|
2016-06-07 22:24:25 -07:00
|
|
|
|
element: alphaPickerElement,
|
|
|
|
|
valueChangeEvent: 'click'
|
2016-04-03 11:47:49 -07:00
|
|
|
|
});
|
2013-12-01 19:24:14 -07:00
|
|
|
|
|
2016-06-01 23:08:47 -07:00
|
|
|
|
context.querySelector('.itemsContainer').addEventListener('needsrefresh', function () {
|
2014-03-18 18:35:40 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
reloadItems(context);
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-08-15 11:30:52 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
self.initTab = function () {
|
2015-08-15 11:30:52 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
initPage(tabContent);
|
|
|
|
|
};
|
2015-08-15 11:30:52 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
self.renderTab = function () {
|
2015-08-15 11:30:52 -07:00
|
|
|
|
|
2016-02-15 08:51:08 -07:00
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
updateFilterControls(tabContent);
|
2016-04-03 11:47:49 -07:00
|
|
|
|
};
|
2015-08-18 09:11:56 -07:00
|
|
|
|
};
|
2013-04-01 17:54:06 -07:00
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|