2016-07-29 22:58:07 -07:00
|
|
|
|
define(['events', 'libraryBrowser', 'imageLoader', 'alphaPicker', 'listView', 'cardBuilder', 'emby-itemscontainer'], function (events, libraryBrowser, imageLoader, alphaPicker, listView, cardBuilder) {
|
2015-08-15 11:46:57 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
return function (view, params, tabContent) {
|
2015-08-15 11:46:57 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
var self = this;
|
|
|
|
|
var pageSize = libraryBrowser.getDefaultPageSize();
|
|
|
|
|
|
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
|
|
function getPageData(context) {
|
|
|
|
|
var key = getSavedQueryKey(context);
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
IncludeItemTypes: "BoxSet",
|
|
|
|
|
Recursive: true,
|
2016-08-01 22:55:52 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName",
|
2016-06-17 12:10:05 -07:00
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
Limit: pageSize
|
|
|
|
|
},
|
2016-07-30 11:37:38 -07:00
|
|
|
|
view: libraryBrowser.getSavedView(key) || 'Poster'
|
2016-06-17 12:10:05 -07:00
|
|
|
|
};
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
libraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
|
|
|
|
}
|
2014-05-06 19:28:19 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
function getQuery(context) {
|
2014-05-06 19:28:19 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
return getPageData(context).query;
|
|
|
|
|
}
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
function getSavedQueryKey(context) {
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
if (!context.savedQueryKey) {
|
|
|
|
|
context.savedQueryKey = libraryBrowser.getSavedQueryKey('movies');
|
|
|
|
|
}
|
|
|
|
|
return context.savedQueryKey;
|
|
|
|
|
}
|
2014-07-19 21:46:29 -07:00
|
|
|
|
|
2016-07-29 22:58:07 -07:00
|
|
|
|
function onViewStyleChange() {
|
|
|
|
|
|
|
|
|
|
var viewStyle = self.getCurrentViewStyle();
|
|
|
|
|
|
|
|
|
|
var itemsContainer = tabContent.querySelector('.itemsContainer');
|
|
|
|
|
|
|
|
|
|
if (viewStyle == "List") {
|
|
|
|
|
|
|
|
|
|
itemsContainer.classList.add('vertical-list');
|
|
|
|
|
itemsContainer.classList.remove('vertical-wrap');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
itemsContainer.classList.remove('vertical-list');
|
|
|
|
|
itemsContainer.classList.add('vertical-wrap');
|
|
|
|
|
}
|
|
|
|
|
itemsContainer.innerHTML = '';
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
function reloadItems(page) {
|
2014-07-19 21:46:29 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
var query = getQuery(page);
|
2013-05-17 12:18:54 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
|
|
|
window.scrollTo(0, 0);
|
2015-08-15 16:10:50 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
updateFilterControls(page);
|
2015-08-15 11:17:22 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -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
|
|
|
|
|
});
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
var html;
|
|
|
|
|
var viewStyle = self.getCurrentViewStyle();
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
if (viewStyle == "Thumb") {
|
2014-07-05 12:57:18 -07:00
|
|
|
|
|
2016-07-29 22:58:07 -07:00
|
|
|
|
html = cardBuilder.getCardsHtml({
|
2014-07-05 12:57:18 -07:00
|
|
|
|
items: result.Items,
|
2016-06-17 12:10:05 -07:00
|
|
|
|
shape: "backdrop",
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
context: 'movies',
|
2016-02-12 13:26:03 -07:00
|
|
|
|
lazy: true,
|
2016-08-21 10:58:33 -07:00
|
|
|
|
overlayPlayButton: true,
|
|
|
|
|
showTitle: true
|
2014-07-05 12:57:18 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2016-06-17 12:10:05 -07:00
|
|
|
|
else if (viewStyle == "ThumbCard") {
|
|
|
|
|
|
2016-07-29 22:58:07 -07:00
|
|
|
|
html = cardBuilder.getCardsHtml({
|
2015-05-12 21:55:19 -07:00
|
|
|
|
items: result.Items,
|
2016-06-17 12:10:05 -07:00
|
|
|
|
shape: "backdrop",
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
context: 'movies',
|
2015-05-12 21:55:19 -07:00
|
|
|
|
lazy: true,
|
2016-06-17 12:10:05 -07:00
|
|
|
|
cardLayout: true,
|
|
|
|
|
showTitle: true,
|
2015-05-12 21:55:19 -07:00
|
|
|
|
showItemCounts: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-06-17 12:10:05 -07:00
|
|
|
|
else if (viewStyle == "Banner") {
|
|
|
|
|
|
2016-07-29 22:58:07 -07:00
|
|
|
|
html = cardBuilder.getCardsHtml({
|
2015-04-02 14:01:42 -07:00
|
|
|
|
items: result.Items,
|
2016-06-17 12:10:05 -07:00
|
|
|
|
shape: "banner",
|
|
|
|
|
preferBanner: true,
|
|
|
|
|
context: 'movies',
|
|
|
|
|
lazy: true
|
2015-04-02 14:01:42 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2016-06-17 12:10:05 -07:00
|
|
|
|
else if (viewStyle == "List") {
|
|
|
|
|
|
2016-07-15 22:05:40 -07:00
|
|
|
|
html = listView.getListViewHtml({
|
2015-05-12 21:55:19 -07:00
|
|
|
|
items: result.Items,
|
2016-06-17 12:10:05 -07:00
|
|
|
|
context: 'movies',
|
|
|
|
|
sortBy: query.SortBy
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (viewStyle == "PosterCard") {
|
|
|
|
|
|
2016-07-29 22:58:07 -07:00
|
|
|
|
html = cardBuilder.getCardsHtml({
|
2016-06-17 12:10:05 -07:00
|
|
|
|
items: result.Items,
|
2016-07-22 10:30:39 -07:00
|
|
|
|
shape: "auto",
|
2016-06-17 12:10:05 -07:00
|
|
|
|
context: 'movies',
|
2015-05-12 21:55:19 -07:00
|
|
|
|
showTitle: true,
|
2016-06-17 12:10:05 -07:00
|
|
|
|
showYear: true,
|
2015-05-12 21:55:19 -07:00
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showItemCounts: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-06-17 12:10:05 -07:00
|
|
|
|
else {
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
// Poster
|
2016-07-29 22:58:07 -07:00
|
|
|
|
html = cardBuilder.getCardsHtml({
|
2016-06-17 12:10:05 -07:00
|
|
|
|
items: result.Items,
|
2016-07-22 10:30:39 -07:00
|
|
|
|
shape: "auto",
|
2016-06-17 12:10:05 -07:00
|
|
|
|
context: 'movies',
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true,
|
2016-08-21 10:58:33 -07:00
|
|
|
|
overlayPlayButton: true,
|
|
|
|
|
showTitle: true
|
2016-06-17 12:10:05 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2014-07-19 21:46:29 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
var i, length;
|
|
|
|
|
var elems = tabContent.querySelectorAll('.paging');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].innerHTML = pagingHtml;
|
|
|
|
|
}
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
function onNextPageClick() {
|
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
}
|
2013-04-11 08:43:57 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
function onPreviousPageClick() {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2015-01-22 23:15:15 -07:00
|
|
|
|
|
2016-07-05 09:29:25 -07:00
|
|
|
|
if (!result.Items.length) {
|
2016-06-17 12:10:05 -07:00
|
|
|
|
html = '<p style="text-align:center;">' + Globalize.translate('MessageNoCollectionsAvailable') + '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var itemsContainer = tabContent.querySelector('.itemsContainer');
|
|
|
|
|
itemsContainer.innerHTML = html;
|
|
|
|
|
imageLoader.lazyChildren(itemsContainer);
|
|
|
|
|
|
|
|
|
|
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2013-04-29 19:00:42 -07:00
|
|
|
|
});
|
2016-06-17 12:10:05 -07:00
|
|
|
|
}
|
2013-04-15 15:03:05 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
function updateFilterControls(tabContent) {
|
|
|
|
|
|
|
|
|
|
var query = getQuery(tabContent);
|
|
|
|
|
self.alphaPicker.value(query.NameStartsWithOrGreater);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initPage(tabContent) {
|
|
|
|
|
|
|
|
|
|
var alphaPickerElement = tabContent.querySelector('.alphaPicker');
|
|
|
|
|
alphaPickerElement.addEventListener('alphavaluechanged', function (e) {
|
|
|
|
|
var newValue = e.detail.value;
|
|
|
|
|
var query = getQuery(tabContent);
|
|
|
|
|
query.NameStartsWithOrGreater = newValue;
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
reloadItems(tabContent);
|
2015-08-15 16:10:50 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
self.alphaPicker = new alphaPicker({
|
|
|
|
|
element: alphaPickerElement,
|
|
|
|
|
valueChangeEvent: 'click'
|
2013-04-29 19:00:42 -07:00
|
|
|
|
});
|
2013-04-15 15:03:05 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
tabContent.querySelector('.btnSort').addEventListener('click', function (e) {
|
|
|
|
|
libraryBrowser.showSortMenu({
|
2015-08-28 18:53:53 -07:00
|
|
|
|
items: [{
|
|
|
|
|
name: Globalize.translate('OptionNameSort'),
|
|
|
|
|
id: 'SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionImdbRating'),
|
|
|
|
|
id: 'CommunityRating,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionDateAdded'),
|
|
|
|
|
id: 'DateCreated,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionParentalRating'),
|
|
|
|
|
id: 'OfficialRating,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionReleaseDate'),
|
|
|
|
|
id: 'PremiereDate,SortName'
|
|
|
|
|
}],
|
|
|
|
|
callback: function () {
|
2016-06-17 12:10:05 -07:00
|
|
|
|
getQuery(tabContent).StartIndex = 0;
|
|
|
|
|
reloadItems(tabContent);
|
2015-08-28 18:53:53 -07:00
|
|
|
|
},
|
2016-06-17 12:10:05 -07:00
|
|
|
|
query: getQuery(tabContent),
|
|
|
|
|
button: e.target
|
2015-08-28 18:53:53 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
var btnSelectView = tabContent.querySelector('.btnSelectView');
|
|
|
|
|
btnSelectView.addEventListener('click', function (e) {
|
2014-07-05 12:57:18 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), 'List,Poster,PosterCard,Thumb,ThumbCard'.split(','));
|
2015-10-13 22:46:11 -07:00
|
|
|
|
});
|
2016-04-03 11:47:49 -07:00
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
btnSelectView.addEventListener('layoutchange', function (e) {
|
2014-06-03 20:34:36 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
var viewStyle = e.detail.viewStyle;
|
2014-06-03 20:34:36 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
getPageData(tabContent).view = viewStyle;
|
|
|
|
|
libraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
|
|
|
|
|
getQuery(tabContent).StartIndex = 0;
|
2016-07-29 22:58:07 -07:00
|
|
|
|
onViewStyleChange();
|
2016-06-17 12:10:05 -07:00
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
});
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
// The button is created dynamically
|
|
|
|
|
tabContent.querySelector('.btnNewCollection').addEventListener('click', function () {
|
2015-12-14 08:43:03 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
require(['collectionEditor'], function (collectionEditor) {
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
var serverId = ApiClient.serverInfo().Id;
|
|
|
|
|
new collectionEditor().show({
|
|
|
|
|
items: [],
|
|
|
|
|
serverId: serverId
|
|
|
|
|
});
|
2015-08-18 09:11:56 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-04-03 11:47:49 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
self.getCurrentViewStyle = function () {
|
|
|
|
|
return getPageData(tabContent).view;
|
2016-04-03 11:47:49 -07:00
|
|
|
|
};
|
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
initPage(tabContent);
|
2016-07-29 22:58:07 -07:00
|
|
|
|
onViewStyleChange();
|
2016-06-17 12:10:05 -07:00
|
|
|
|
|
2016-04-03 11:47:49 -07:00
|
|
|
|
self.renderTab = function () {
|
|
|
|
|
|
|
|
|
|
reloadItems(tabContent);
|
2016-06-17 12:10:05 -07:00
|
|
|
|
updateFilterControls(tabContent);
|
2016-04-03 11:47:49 -07:00
|
|
|
|
};
|
2015-08-18 09:11:56 -07:00
|
|
|
|
|
2016-06-17 12:10:05 -07:00
|
|
|
|
self.destroy = function () {
|
|
|
|
|
};
|
|
|
|
|
};
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|