2016-06-18 10:26:42 -07:00
|
|
|
|
define(['libraryBrowser', 'alphaPicker'], function (libraryBrowser, alphaPicker) {
|
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: {
|
2016-04-27 10:52:27 -07:00
|
|
|
|
SortBy: "IsFolder,SortName",
|
2016-03-18 12:43:17 -07:00
|
|
|
|
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) {
|
2016-04-27 10:52:27 -07:00
|
|
|
|
view.savedQueryKey = libraryBrowser.getSavedQueryKey('itemsv1');
|
2016-03-18 12:43:17 -07:00
|
|
|
|
}
|
|
|
|
|
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,
|
2016-06-18 10:26:42 -07:00
|
|
|
|
addLayoutButton: false,
|
2016-03-18 12:43:17 -07:00
|
|
|
|
currentLayout: viewStyle,
|
2016-06-18 10:26:42 -07:00
|
|
|
|
sortButton: false,
|
|
|
|
|
filterButton: false
|
2016-03-18 12:43:17 -07:00
|
|
|
|
});
|
2014-08-14 06:24:30 -07:00
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
view.querySelector('.paging').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 == "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";
|
2016-06-18 10:26:42 -07:00
|
|
|
|
html = libraryBrowser.getPosterViewHtml(posterOptions);
|
|
|
|
|
} else {
|
2016-06-18 12:21:28 -07:00
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
// Poster
|
|
|
|
|
posterOptions.showTitle = context == 'photos' ? 'auto' : true;
|
|
|
|
|
posterOptions.overlayText = context == 'photos';
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
html = libraryBrowser.getPosterViewHtml(posterOptions);
|
|
|
|
|
}
|
2013-04-15 15:03:05 -07:00
|
|
|
|
|
2016-06-18 12:21:28 -07:00
|
|
|
|
if (currentItem.CollectionType == 'boxsets') {
|
|
|
|
|
view.querySelector('.btnNewCollection').classList.remove('hide');
|
|
|
|
|
if (!result.Items.length) {
|
|
|
|
|
html = '<p style="text-align:center;">' + Globalize.translate('MessageNoCollectionsAvailable') + '</p>';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
view.querySelector('.btnNewCollection').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
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-06-18 10:26:42 -07:00
|
|
|
|
var i, length;
|
|
|
|
|
var elems = view.querySelectorAll('.paging');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].innerHTML = pagingHtml;
|
|
|
|
|
}
|
2015-09-16 10:16:39 -07:00
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
function onNextPageClick() {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(view);
|
2016-06-18 10:26:42 -07:00
|
|
|
|
}
|
2015-09-16 10:16:39 -07:00
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
function onPreviousPageClick() {
|
2016-03-18 12:43:17 -07:00
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(view);
|
2016-06-18 10:26:42 -07:00
|
|
|
|
}
|
2013-04-27 15:52:41 -07:00
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
elems = view.querySelectorAll('.btnNextPage');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('click', onNextPageClick);
|
|
|
|
|
}
|
2013-03-28 22:45:21 -07:00
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
elems = view.querySelectorAll('.btnPreviousPage');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].addEventListener('click', onPreviousPageClick);
|
|
|
|
|
}
|
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
|
|
|
|
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-06-06 22:42:26 -07:00
|
|
|
|
var alphaPickerElement = view.querySelector('.alphaPicker');
|
|
|
|
|
alphaPickerElement.addEventListener('alphavaluechanged', function (e) {
|
|
|
|
|
var newValue = e.detail.value;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
var query = getQuery();
|
2016-06-06 22:42:26 -07:00
|
|
|
|
query.NameStartsWithOrGreater = newValue;
|
2013-06-04 18:41:59 -07:00
|
|
|
|
query.StartIndex = 0;
|
2016-03-18 12:43:17 -07:00
|
|
|
|
reloadItems(view);
|
2016-06-06 22:42:26 -07:00
|
|
|
|
});
|
2013-06-04 18:41:59 -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'
|
2013-06-04 18:41:59 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
function parentWithClass(elem, className) {
|
|
|
|
|
|
|
|
|
|
while (!elem.classList || !elem.classList.contains(className)) {
|
|
|
|
|
elem = elem.parentNode;
|
|
|
|
|
|
|
|
|
|
if (!elem) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
view.addEventListener('click', function (e) {
|
|
|
|
|
|
|
|
|
|
var mediaItem = parentWithClass(e.target, 'mediaItem');
|
|
|
|
|
if (mediaItem) {
|
|
|
|
|
var query = getQuery();
|
|
|
|
|
var info = libraryBrowser.getListItemInfo(mediaItem);
|
|
|
|
|
|
|
|
|
|
if (info.mediaType == 'Photo') {
|
|
|
|
|
require(['scripts/photos'], function () {
|
|
|
|
|
Photos.startSlideshow(view, query, info.id);
|
|
|
|
|
});
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-12-14 08:43:03 -07:00
|
|
|
|
|
2016-06-06 22:42:26 -07:00
|
|
|
|
function updateFilterControls() {
|
|
|
|
|
|
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
|
|
|
|
self.alphaPicker.value(query.NameStartsWithOrGreater);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-18 10:26:42 -07:00
|
|
|
|
var btnSelectView = view.querySelector('.btnSelectView');
|
|
|
|
|
btnSelectView.addEventListener('click', function (e) {
|
|
|
|
|
|
|
|
|
|
libraryBrowser.showLayoutMenu(e.target, getPageData().view, 'Poster,PosterCard,Thumb'.split(','));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
btnSelectView.addEventListener('layoutchange', function (e) {
|
|
|
|
|
var layout = e.detail.viewStyle;
|
|
|
|
|
getPageData().view = layout;
|
|
|
|
|
libraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
|
|
|
|
|
reloadItems(view);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
view.querySelector('.btnFilter').addEventListener('click', function () {
|
|
|
|
|
showFilterMenu();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// On callback make sure to set StartIndex = 0
|
|
|
|
|
view.querySelector('.btnSort').addEventListener('click', function () {
|
|
|
|
|
libraryBrowser.showSortMenu({
|
|
|
|
|
items: [{
|
|
|
|
|
name: Globalize.translate('OptionNameSort'),
|
|
|
|
|
id: 'IsFolder,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: getQuery()
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-18 12:21:28 -07:00
|
|
|
|
// The button is created dynamically
|
|
|
|
|
view.querySelector('.btnNewCollection').addEventListener('click', function () {
|
|
|
|
|
|
|
|
|
|
require(['collectionEditor'], function (collectionEditor) {
|
|
|
|
|
|
|
|
|
|
var serverId = ApiClient.serverInfo().Id;
|
|
|
|
|
new collectionEditor().show({
|
|
|
|
|
items: [],
|
|
|
|
|
serverId: serverId
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-18 12:43:17 -07:00
|
|
|
|
view.addEventListener('viewbeforeshow', function (e) {
|
|
|
|
|
reloadItems(view);
|
|
|
|
|
updateFilterControls();
|
|
|
|
|
LibraryMenu.setBackButtonVisible(params.context);
|
|
|
|
|
});
|
2016-06-06 22:42:26 -07:00
|
|
|
|
|
|
|
|
|
view.addEventListener('viewdestroy', function (e) {
|
|
|
|
|
if (self.alphaPicker) {
|
|
|
|
|
self.alphaPicker.destroy();
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-03-18 12:43:17 -07:00
|
|
|
|
};
|
|
|
|
|
});
|