2016-03-18 12:43:17 -07:00
|
|
|
|
define(['libraryBrowser', 'jQuery'], function (libraryBrowser, $) {
|
2015-07-08 17:20:01 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
return function (view, params) {
|
2015-07-08 17:20:01 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var currentItem;
|
2015-07-08 17:20:01 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var data;
|
2015-09-16 10:16:39 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function getPageData() {
|
|
|
|
|
var pageData = data;
|
2016-02-26 12:02:53 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
Fields: "DateCreated,PrimaryImageAspectRatio,MediaSourceCount,SyncInfo",
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
Limit: libraryBrowser.getDefaultPageSize()
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-07-08 17:20:01 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
pageData.query.Filters = "";
|
|
|
|
|
pageData.query.NameStartsWithOrGreater = '';
|
|
|
|
|
var key = getSavedQueryKey();
|
|
|
|
|
pageData.view = libraryBrowser.getSavedView(key) || libraryBrowser.getDefaultItemsView('Poster', 'Poster');
|
2016-02-26 12:02:53 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
pageData.query.ParentId = params.parentId || null;
|
|
|
|
|
libraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
2016-02-26 12:02:53 -07:00
|
|
|
|
}
|
2013-06-02 07:33:51 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function getQuery() {
|
2013-03-28 22:45:21 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
return getPageData().query;
|
|
|
|
|
}
|
|
|
|
|
function getSavedQueryKey() {
|
2013-03-30 07:57:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (!view.savedQueryKey) {
|
|
|
|
|
view.savedQueryKey = libraryBrowser.getSavedQueryKey('items');
|
|
|
|
|
}
|
|
|
|
|
return view.savedQueryKey;
|
|
|
|
|
}
|
2013-03-05 23:22:19 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function reloadItems() {
|
2014-10-20 13:23:40 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2014-10-20 13:23:40 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var query = getQuery();
|
|
|
|
|
var userId = Dashboard.getCurrentUserId();
|
2014-10-20 13:23:40 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var parentItemPromise = query.ParentId ?
|
|
|
|
|
ApiClient.getItem(userId, query.ParentId) :
|
|
|
|
|
ApiClient.getRootFolder(userId);
|
2013-03-30 07:57:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var itemsPromise = ApiClient.getItems(userId, query);
|
2013-05-17 12:18:54 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
Promise.all([parentItemPromise, itemsPromise]).then(function (responses) {
|
2015-09-16 10:16:39 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var item = responses[0];
|
|
|
|
|
currentItem = item;
|
|
|
|
|
var result = responses[1];
|
2015-01-28 12:30:45 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
|
|
|
window.scrollTo(0, 0);
|
2013-03-05 23:22:19 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var viewStyle = getPageData(view).view;
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var html = '';
|
|
|
|
|
var pagingHtml = libraryBrowser.getQueryPagingHtml({
|
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
showLimit: false,
|
|
|
|
|
addLayoutButton: true,
|
|
|
|
|
currentLayout: viewStyle,
|
|
|
|
|
sortButton: true,
|
|
|
|
|
layouts: 'Poster,PosterCard,Thumb',
|
|
|
|
|
filterButton: true
|
|
|
|
|
});
|
2014-08-14 06:24:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
view.querySelector('.listTopPaging').innerHTML = pagingHtml;
|
2014-08-14 06:24:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
updateFilterControls();
|
2014-03-07 21:20:31 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var context = params.context;
|
2015-08-26 11:17:38 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var posterOptions = {
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "auto",
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
coverImage: item.Type == 'PhotoAlbum'
|
|
|
|
|
};
|
2015-08-26 11:17:38 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (viewStyle == "Backdrop") {
|
2015-08-26 11:17:38 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
posterOptions.shape = 'backdrop';
|
|
|
|
|
posterOptions.showTitle = true;
|
|
|
|
|
posterOptions.preferBackdrop = true;
|
2015-08-26 11:17:38 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
html = libraryBrowser.getPosterViewHtml(posterOptions);
|
|
|
|
|
}
|
|
|
|
|
else if (viewStyle == "Poster") {
|
2015-08-26 11:17:38 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
posterOptions.showTitle = context == 'photos' ? 'auto' : true;
|
|
|
|
|
posterOptions.overlayText = context == 'photos';
|
2016-02-18 22:03:00 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
html = libraryBrowser.getPosterViewHtml(posterOptions);
|
|
|
|
|
}
|
|
|
|
|
else if (viewStyle == "PosterCard") {
|
2013-03-30 07:57:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
posterOptions.showTitle = true;
|
|
|
|
|
posterOptions.showYear = true;
|
|
|
|
|
posterOptions.cardLayout = true;
|
|
|
|
|
posterOptions.centerText = false;
|
2013-03-26 19:48:33 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
html = libraryBrowser.getPosterViewHtml(posterOptions);
|
|
|
|
|
}
|
|
|
|
|
else if (viewStyle == "Thumb") {
|
2016-02-14 23:09:49 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
posterOptions.preferThumb = true;
|
|
|
|
|
posterOptions.shape = "backdrop";
|
|
|
|
|
html = libraryBrowser.getPosterViewHtml(posterOptions);
|
|
|
|
|
}
|
2013-04-15 15:03:05 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var elem = view.querySelector('#items');
|
|
|
|
|
elem.innerHTML = html + pagingHtml;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2013-04-15 15:03:05 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
$('.btnFilter', view).on('click', function () {
|
|
|
|
|
showFilterMenu();
|
|
|
|
|
});
|
2015-09-16 10:16:39 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
$('.btnNextPage', view).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(view);
|
2015-09-16 10:16:39 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
$('.btnPreviousPage', view).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(view);
|
|
|
|
|
});
|
2013-04-27 15:52:41 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
$('.btnChangeLayout', view).on('layoutchange', function (e, layout) {
|
|
|
|
|
getPageData(view).view = layout;
|
|
|
|
|
libraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
|
|
|
|
|
reloadItems(view);
|
|
|
|
|
});
|
2013-03-28 22:45:21 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
// On callback make sure to set StartIndex = 0
|
|
|
|
|
$('.btnSort', view).on('click', function () {
|
|
|
|
|
libraryBrowser.showSortMenu({
|
|
|
|
|
items: [{
|
|
|
|
|
name: Globalize.translate('OptionNameSort'),
|
|
|
|
|
id: 'SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionCommunityRating'),
|
|
|
|
|
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('OptionParentalRating'),
|
|
|
|
|
id: 'OfficialRating,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionPlayCount'),
|
|
|
|
|
id: 'PlayCount,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionReleaseDate'),
|
|
|
|
|
id: 'PremiereDate,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionRuntime'),
|
|
|
|
|
id: 'Runtime,SortName'
|
|
|
|
|
}],
|
|
|
|
|
callback: function () {
|
|
|
|
|
reloadItems(view);
|
|
|
|
|
},
|
|
|
|
|
query: query
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-04-26 06:50:21 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
libraryBrowser.saveQueryValues(params.parentId, query);
|
2013-05-15 12:40:47 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var name = item.Name;
|
2013-05-10 05:18:07 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (item.IndexNumber != null) {
|
|
|
|
|
name = item.IndexNumber + " - " + name;
|
|
|
|
|
}
|
|
|
|
|
if (item.ParentIndexNumber != null) {
|
|
|
|
|
name = item.ParentIndexNumber + "." + name;
|
|
|
|
|
}
|
2013-03-30 07:57:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
LibraryMenu.setTitle(name);
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
view.dispatchEvent(new CustomEvent("displayingitem", {
|
|
|
|
|
detail: {
|
|
|
|
|
item: item
|
|
|
|
|
},
|
|
|
|
|
bubbles: true
|
|
|
|
|
}));
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
libraryBrowser.setLastRefreshed(view);
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2016-02-14 23:09:49 -07:00
|
|
|
|
});
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function showFilterMenu() {
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
|
2016-02-14 23:09:49 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var filterDialog = new filterDialogFactory({
|
|
|
|
|
query: getQuery()
|
|
|
|
|
});
|
2016-02-14 23:09:49 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
|
|
|
|
reloadItems();
|
|
|
|
|
});
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
filterDialog.show();
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function updateFilterControls() {
|
2014-10-20 13:23:40 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var query = getQuery();
|
2014-10-20 13:23:40 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
$('.alphabetPicker', view).alphaValue(query.NameStartsWithOrGreater);
|
2015-05-09 21:29:04 -07:00
|
|
|
|
}
|
2014-10-20 13:23:40 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
function onListItemClick(e) {
|
|
|
|
|
|
|
|
|
|
var query = getQuery();
|
|
|
|
|
var info = libraryBrowser.getListItemInfo(this);
|
2013-03-30 07:57:30 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
if (info.mediaType == 'Photo') {
|
|
|
|
|
require(['scripts/photos'], function () {
|
|
|
|
|
Photos.startSlideshow(view, query, info.id);
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-18 19:52:22 -07:00
|
|
|
|
|
2013-06-04 18:41:59 -07:00
|
|
|
|
$('.alphabetPicker', this).on('alphaselect', function (e, character) {
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var query = getQuery();
|
2013-06-04 18:41:59 -07:00
|
|
|
|
query.NameStartsWithOrGreater = character;
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
reloadItems(view);
|
2013-06-04 18:41:59 -07:00
|
|
|
|
|
|
|
|
|
}).on('alphaclear', function (e) {
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var query = getQuery();
|
2013-06-04 18:41:59 -07:00
|
|
|
|
query.NameStartsWithOrGreater = '';
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
reloadItems(view);
|
2013-06-04 18:41:59 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
$(view).on('click', '.mediaItem', onListItemClick);
|
2015-12-14 08:43:03 -07:00
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
view.addEventListener('viewbeforeshow', function (e) {
|
|
|
|
|
reloadItems(view);
|
|
|
|
|
updateFilterControls();
|
|
|
|
|
LibraryMenu.setBackButtonVisible(params.context);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
});
|