2016-07-15 22:05:40 -07:00
|
|
|
define(['jQuery', 'listView'], function ($, listView) {
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2016-02-15 08:51:08 -07:00
|
|
|
var data = {};
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
function getPageData(context) {
|
|
|
|
var key = getSavedQueryKey(context);
|
2016-02-15 08:51:08 -07:00
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
pageData = data[key] = {
|
|
|
|
query: {
|
|
|
|
SortBy: "SortName",
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
MediaTypes: "Game",
|
|
|
|
Recursive: true,
|
|
|
|
Fields: "Genres,Studios,PrimaryImageAspectRatio,SortName",
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
StartIndex: 0,
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
|
|
|
},
|
2016-07-30 11:37:38 -07:00
|
|
|
view: LibraryBrowser.getSavedView(key) || 'Poster'
|
2016-02-15 08:51:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
pageData.query.ParentId = LibraryMenu.getTopParentId();
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
}
|
|
|
|
return pageData;
|
|
|
|
}
|
2014-07-05 14:15:25 -07:00
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
function getQuery(context) {
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
return getPageData(context).query;
|
2016-02-15 08:51:08 -07:00
|
|
|
}
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
function getSavedQueryKey(context) {
|
2014-05-01 19:54:33 -07:00
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
if (!context.savedQueryKey) {
|
|
|
|
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('games');
|
|
|
|
}
|
|
|
|
return context.savedQueryKey;
|
2014-05-01 19:54:33 -07:00
|
|
|
}
|
|
|
|
|
2013-04-29 18:32:15 -07:00
|
|
|
function reloadItems(page) {
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2013-04-29 18:32:15 -07:00
|
|
|
Dashboard.showLoadingMsg();
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
var query = getQuery(page);
|
2016-02-15 08:51:08 -07:00
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
|
2013-04-14 20:37:07 -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 18:32:15 -07:00
|
|
|
var html = '';
|
2013-04-14 20:37:07 -07:00
|
|
|
|
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,
|
2016-02-15 08:51:08 -07:00
|
|
|
showLimit: false,
|
|
|
|
filterButton: true
|
2015-09-05 21:53:37 -07:00
|
|
|
}));
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
var view = getPageData(page).view;
|
2013-10-18 09:09:47 -07:00
|
|
|
|
2014-07-05 14:15:25 -07:00
|
|
|
if (view == "List") {
|
|
|
|
|
2016-07-15 22:05:40 -07:00
|
|
|
html = listView.getListViewHtml({
|
2014-07-05 14:15:25 -07:00
|
|
|
items: result.Items,
|
|
|
|
context: 'games',
|
|
|
|
sortBy: query.SortBy
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (view == "Poster") {
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
items: result.Items,
|
|
|
|
shape: "auto",
|
|
|
|
context: 'games',
|
|
|
|
showTitle: true,
|
|
|
|
showParentTitle: true,
|
|
|
|
centerText: true
|
|
|
|
});
|
|
|
|
}
|
2014-11-10 20:41:19 -07:00
|
|
|
else if (view == "PosterCard") {
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
items: result.Items,
|
|
|
|
shape: "auto",
|
|
|
|
context: 'games',
|
|
|
|
showTitle: true,
|
|
|
|
showParentTitle: true,
|
|
|
|
cardLayout: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
var elem = page.querySelector('#items');
|
|
|
|
elem.innerHTML = html;
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2013-04-29 18:32:15 -07:00
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
reloadItems(page);
|
|
|
|
});
|
2013-04-15 15:03:05 -07:00
|
|
|
|
2013-04-29 18:32:15 -07:00
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
reloadItems(page);
|
|
|
|
});
|
2013-04-15 15:03:05 -07:00
|
|
|
|
2016-02-15 08:51:08 -07:00
|
|
|
$('.btnFilter', page).on('click', function () {
|
|
|
|
showFilterMenu(page);
|
|
|
|
});
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
|
2013-10-18 09:09:47 -07:00
|
|
|
|
2013-04-29 18:32:15 -07:00
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
});
|
|
|
|
}
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2016-02-15 08:51:08 -07:00
|
|
|
function showFilterMenu(page) {
|
2013-10-18 09:09:47 -07:00
|
|
|
|
2016-02-15 08:51:08 -07:00
|
|
|
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
|
2013-10-18 09:09:47 -07:00
|
|
|
|
2016-02-15 08:51:08 -07:00
|
|
|
var filterDialog = new filterDialogFactory({
|
2016-02-26 12:02:53 -07:00
|
|
|
query: getQuery(page),
|
2016-02-15 08:51:08 -07:00
|
|
|
mode: 'games'
|
|
|
|
});
|
2014-11-09 21:20:11 -07:00
|
|
|
|
2016-02-15 08:51:08 -07:00
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
2014-11-09 21:20:11 -07:00
|
|
|
reloadItems(page);
|
|
|
|
});
|
2016-02-15 08:51:08 -07:00
|
|
|
|
|
|
|
filterDialog.show();
|
|
|
|
});
|
2014-11-09 21:20:11 -07:00
|
|
|
}
|
|
|
|
|
2015-09-01 07:01:59 -07:00
|
|
|
$(document).on('pageinit', "#gamesPage", function () {
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2013-04-29 18:32:15 -07:00
|
|
|
var page = this;
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2013-05-16 12:00:42 -07:00
|
|
|
$('.alphabetPicker', this).on('alphaselect', function (e, character) {
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
var query = getQuery(page);
|
2013-05-16 20:24:41 -07:00
|
|
|
query.NameStartsWithOrGreater = character;
|
2013-05-17 11:05:49 -07:00
|
|
|
query.StartIndex = 0;
|
2013-05-16 12:00:42 -07:00
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
|
|
|
}).on('alphaclear', function (e) {
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
var query = getQuery(page);
|
2013-05-16 20:24:41 -07:00
|
|
|
query.NameStartsWithOrGreater = '';
|
2013-05-16 12:00:42 -07:00
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
});
|
|
|
|
|
2015-08-31 23:22:46 -07:00
|
|
|
}).on('pagebeforeshow', "#gamesPage", function () {
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2014-07-05 14:15:25 -07:00
|
|
|
var page = this;
|
2016-02-26 12:02:53 -07:00
|
|
|
var query = getQuery(page);
|
2014-05-01 19:54:33 -07:00
|
|
|
query.ParentId = LibraryMenu.getTopParentId();
|
|
|
|
|
2013-05-15 12:40:47 -07:00
|
|
|
var limit = LibraryBrowser.getDefaultPageSize();
|
|
|
|
|
|
|
|
// If the default page size has changed, the start index will have to be reset
|
|
|
|
if (limit != query.Limit) {
|
|
|
|
query.Limit = limit;
|
|
|
|
query.StartIndex = 0;
|
|
|
|
}
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
var viewkey = getSavedQueryKey(page);
|
2013-10-17 13:59:46 -07:00
|
|
|
|
2014-07-05 14:15:25 -07:00
|
|
|
LibraryBrowser.loadSavedQueryValues(viewkey, query);
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
LibraryBrowser.getSavedViewSetting(viewkey).then(function (val) {
|
2014-07-05 14:15:25 -07:00
|
|
|
|
|
|
|
if (val) {
|
2015-09-03 10:01:51 -07:00
|
|
|
$('#selectView', page).val(val).trigger('change');
|
2014-07-05 14:15:25 -07:00
|
|
|
} else {
|
|
|
|
reloadItems(page);
|
|
|
|
}
|
|
|
|
});
|
2013-04-29 18:32:15 -07:00
|
|
|
});
|
2013-04-14 20:37:07 -07:00
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
});
|