2013-04-03 21:21:46 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
2015-08-15 11:17:22 -07:00
|
|
|
|
var data = {};
|
2015-08-15 11:46:57 -07:00
|
|
|
|
function getPageData() {
|
2015-08-15 11:17:22 -07:00
|
|
|
|
var key = getSavedQueryKey();
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
IncludeItemTypes: "BoxSet",
|
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo,CanDelete",
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
2015-08-15 11:46:57 -07:00
|
|
|
|
},
|
|
|
|
|
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
|
2015-08-15 11:17:22 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
2015-08-15 11:46:57 -07:00
|
|
|
|
return pageData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQuery() {
|
|
|
|
|
|
|
|
|
|
return getPageData().query;
|
2015-08-15 11:17:22 -07:00
|
|
|
|
}
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2014-05-06 19:28:19 -07:00
|
|
|
|
function getSavedQueryKey() {
|
|
|
|
|
|
2015-10-14 21:32:10 -07:00
|
|
|
|
return LibraryBrowser.getSavedQueryKey('collections');
|
2014-05-06 19:28:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 16:10:50 -07:00
|
|
|
|
function reloadItems(page) {
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2013-04-29 19:00:42 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2015-08-15 11:17:22 -07:00
|
|
|
|
var query = getQuery();
|
2014-07-19 21:46:29 -07:00
|
|
|
|
var promise1 = ApiClient.getItems(Dashboard.getCurrentUserId(), query);
|
|
|
|
|
var promise2 = Dashboard.getCurrentUser();
|
|
|
|
|
|
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
|
|
|
|
|
|
|
|
|
var result = response1[0];
|
|
|
|
|
var user = response2[0];
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2013-05-17 12:18:54 -07:00
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
2015-06-28 07:45:21 -07:00
|
|
|
|
window.scrollTo(0, 0);
|
2013-05-17 12:18:54 -07:00
|
|
|
|
|
2013-04-29 19:00:42 -07:00
|
|
|
|
var html = '';
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2015-08-15 16:10:50 -07:00
|
|
|
|
var view = getPageData().view;
|
|
|
|
|
|
2015-01-22 23:15:15 -07:00
|
|
|
|
$('.listTopPaging', page).html(LibraryBrowser.getQueryPagingHtml({
|
2014-07-19 21:46:29 -07:00
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
2015-08-15 16:10:50 -07:00
|
|
|
|
viewButton: false,
|
2015-08-28 18:53:53 -07:00
|
|
|
|
sortButton: true,
|
2014-07-19 21:46:29 -07:00
|
|
|
|
showLimit: false,
|
2015-08-15 16:10:50 -07:00
|
|
|
|
updatePageSizeSetting: false,
|
|
|
|
|
addLayoutButton: true,
|
|
|
|
|
currentLayout: view
|
2015-08-15 11:17:22 -07:00
|
|
|
|
|
2015-01-22 23:15:15 -07:00
|
|
|
|
})).trigger('create');
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2014-03-07 11:48:55 -07:00
|
|
|
|
if (result.TotalRecordCount) {
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2015-08-15 11:17:22 -07:00
|
|
|
|
var context = getParameterByName('context');
|
|
|
|
|
|
2014-07-05 12:57:18 -07:00
|
|
|
|
if (view == "List") {
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getListViewHtml({
|
|
|
|
|
items: result.Items,
|
2015-08-15 11:17:22 -07:00
|
|
|
|
context: context,
|
2014-07-05 12:57:18 -07:00
|
|
|
|
sortBy: query.SortBy
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "Poster") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
2015-01-22 23:15:15 -07:00
|
|
|
|
shape: "auto",
|
2015-08-15 11:17:22 -07:00
|
|
|
|
context: context,
|
2015-01-22 23:15:15 -07:00
|
|
|
|
showTitle: true,
|
2014-07-05 12:57:18 -07:00
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-05-12 21:55:19 -07:00
|
|
|
|
else if (view == "PosterCard") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "auto",
|
2015-08-15 11:17:22 -07:00
|
|
|
|
context: context,
|
2015-05-12 21:55:19 -07:00
|
|
|
|
showTitle: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
showItemCounts: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-04-02 14:01:42 -07:00
|
|
|
|
else if (view == "Thumb") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
2015-08-15 11:17:22 -07:00
|
|
|
|
context: context,
|
2015-04-02 14:01:42 -07:00
|
|
|
|
showTitle: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
preferThumb: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-05-12 21:55:19 -07:00
|
|
|
|
else if (view == "ThumbCard") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
2015-08-15 11:17:22 -07:00
|
|
|
|
context: context,
|
2015-05-12 21:55:19 -07:00
|
|
|
|
showTitle: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showItemCounts: true
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
$('.noItemsMessage', page).hide();
|
2014-07-19 21:46:29 -07:00
|
|
|
|
|
2014-03-07 11:48:55 -07:00
|
|
|
|
} else {
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
$('.noItemsMessage', page).show();
|
2014-03-07 11:48:55 -07:00
|
|
|
|
}
|
2013-04-11 08:43:57 -07:00
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
var elem = page.querySelector('.itemsContainer');
|
|
|
|
|
elem.innerHTML = html;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2015-01-22 23:15:15 -07:00
|
|
|
|
|
2013-04-29 19:00:42 -07:00
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
2015-08-15 16:10:50 -07:00
|
|
|
|
reloadItems(page);
|
2013-04-29 19:00:42 -07:00
|
|
|
|
});
|
2013-04-15 15:03:05 -07:00
|
|
|
|
|
2013-04-29 19:00:42 -07:00
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
2015-08-15 16:10:50 -07:00
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
|
|
|
|
|
getPageData().view = layout;
|
2015-08-26 11:17:38 -07:00
|
|
|
|
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
|
2015-08-15 16:10:50 -07:00
|
|
|
|
reloadItems(page);
|
2013-04-29 19:00:42 -07:00
|
|
|
|
});
|
2013-04-15 15:03:05 -07:00
|
|
|
|
|
2015-08-28 18:53:53 -07:00
|
|
|
|
// On callback make sure to set StartIndex = 0
|
|
|
|
|
$('.btnSort', page).on('click', function () {
|
|
|
|
|
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('OptionParentalRating'),
|
|
|
|
|
id: 'OfficialRating,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionReleaseDate'),
|
|
|
|
|
id: 'PremiereDate,SortName'
|
|
|
|
|
}],
|
|
|
|
|
callback: function () {
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
},
|
|
|
|
|
query: query
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2014-05-06 19:28:19 -07:00
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2013-04-29 19:00:42 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2015-08-15 16:10:50 -07:00
|
|
|
|
function initPage(tabContent) {
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2015-10-13 22:46:11 -07:00
|
|
|
|
// The button is created dynamically
|
|
|
|
|
$('.btnNewCollection', tabContent).on('click', function () {
|
2014-07-05 12:57:18 -07:00
|
|
|
|
|
2015-10-13 22:46:11 -07:00
|
|
|
|
require(['collectioneditor'], function (collectioneditor) {
|
2014-07-05 12:57:18 -07:00
|
|
|
|
|
2015-10-13 22:46:11 -07:00
|
|
|
|
new collectioneditor().show();
|
2014-07-05 12:57:18 -07:00
|
|
|
|
|
2015-10-13 22:46:11 -07:00
|
|
|
|
});
|
2014-07-05 12:57:18 -07:00
|
|
|
|
});
|
2015-08-15 11:17:22 -07:00
|
|
|
|
}
|
2014-07-19 21:46:29 -07:00
|
|
|
|
|
2015-09-01 07:01:59 -07:00
|
|
|
|
$(document).on('pageinit', "#boxsetsPage", function () {
|
2014-06-03 20:34:36 -07:00
|
|
|
|
|
2015-08-15 11:17:22 -07:00
|
|
|
|
var page = this;
|
2014-06-03 20:34:36 -07:00
|
|
|
|
|
2015-08-15 11:17:22 -07:00
|
|
|
|
var content = page;
|
2014-06-03 20:34:36 -07:00
|
|
|
|
|
2015-08-15 16:10:50 -07:00
|
|
|
|
initPage(content);
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2015-08-31 23:22:46 -07:00
|
|
|
|
}).on('pagebeforeshow', "#boxsetsPage", function () {
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2015-08-15 11:17:22 -07:00
|
|
|
|
var content = page;
|
2014-05-31 07:30:59 -07:00
|
|
|
|
|
2015-08-15 16:10:50 -07:00
|
|
|
|
reloadItems(content);
|
2013-04-29 19:00:42 -07:00
|
|
|
|
});
|
2013-04-03 21:21:46 -07:00
|
|
|
|
|
2015-08-18 09:11:56 -07:00
|
|
|
|
window.MoviesPage = window.MoviesPage || {};
|
|
|
|
|
window.MoviesPage.renderCollectionsTab = function (page, tabContent) {
|
|
|
|
|
|
|
|
|
|
if (LibraryBrowser.needsRefresh(tabContent)) {
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
window.MoviesPage.initCollectionsTab = function (page, tabContent) {
|
|
|
|
|
|
|
|
|
|
initPage(tabContent);
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-03 21:21:46 -07:00
|
|
|
|
})(jQuery, document);
|