2016-07-29 13:06:58 -07:00
|
|
|
|
define(['jQuery', 'cardBuilder', 'emby-itemscontainer'], function ($, cardBuilder) {
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var data = {};
|
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
function getPageData(context) {
|
|
|
|
|
var key = getSavedQueryKey(context);
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "",
|
|
|
|
|
SortOrder: "Ascending",
|
2016-08-01 22:55:52 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio",
|
2015-09-07 08:54:57 -07:00
|
|
|
|
StartIndex: 0,
|
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
2014-03-18 10:05:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
function getQuery(context) {
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
return getPageData(context).query;
|
2014-05-02 21:20:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
function getSavedQueryKey(context) {
|
2015-09-07 08:54:57 -07:00
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
if (!context.savedQueryKey) {
|
|
|
|
|
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('channelitems');
|
|
|
|
|
}
|
|
|
|
|
return context.savedQueryKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getParam(context, name) {
|
|
|
|
|
|
|
|
|
|
if (!context.pageParams) {
|
|
|
|
|
context.pageParams = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!context.pageParams[name]) {
|
|
|
|
|
context.pageParams[name] = getParameterByName(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return context.pageParams[name];
|
2014-05-02 21:20:04 -07:00
|
|
|
|
}
|
2014-05-27 14:17:48 -07:00
|
|
|
|
|
2014-05-27 10:57:29 -07:00
|
|
|
|
function reloadFeatures(page) {
|
2014-05-27 14:17:48 -07:00
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
var channelId = getParam(page, 'id');
|
2014-05-27 10:57:29 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("Channels/" + channelId + "/Features")).then(function (features) {
|
2014-05-27 10:57:29 -07:00
|
|
|
|
|
|
|
|
|
if (features.CanFilter) {
|
|
|
|
|
|
2014-07-19 21:46:29 -07:00
|
|
|
|
$('.filterControls', page).show();
|
2014-05-27 10:57:29 -07:00
|
|
|
|
|
|
|
|
|
} else {
|
2014-07-19 21:46:29 -07:00
|
|
|
|
$('.filterControls', page).hide();
|
2014-05-27 10:57:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (features.SupportsSortOrderToggle) {
|
|
|
|
|
|
|
|
|
|
$('.sortOrderToggle', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('.sortOrderToggle', page).hide();
|
|
|
|
|
}
|
2014-05-27 14:17:48 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var maxPageSize = features.MaxPageSize;
|
2014-05-27 14:17:48 -07:00
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
var query = getQuery(page);
|
2014-05-28 19:21:41 -07:00
|
|
|
|
if (maxPageSize) {
|
|
|
|
|
query.Limit = Math.min(maxPageSize, query.Limit || maxPageSize);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
getPageData(page).sortFields = features.DefaultSortFields;
|
2014-05-28 19:21:41 -07:00
|
|
|
|
|
2014-05-27 14:17:48 -07:00
|
|
|
|
reloadItems(page);
|
2014-05-27 10:57:29 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2014-03-18 10:05:57 -07:00
|
|
|
|
function reloadItems(page) {
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
var channelId = getParam(page, 'id');
|
|
|
|
|
var folderId = getParam(page, 'folderId');
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
var query = getQuery(page);
|
2014-03-18 10:05:57 -07:00
|
|
|
|
query.UserId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
2014-05-23 07:09:58 -07:00
|
|
|
|
if (folderId) {
|
2014-05-19 12:51:56 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getItem(query.UserId, folderId).then(function (item) {
|
2014-05-19 12:51:56 -07:00
|
|
|
|
|
2015-07-18 11:07:03 -07:00
|
|
|
|
LibraryMenu.setTitle(item.Name);
|
2014-05-19 12:51:56 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getItem(query.UserId, channelId).then(function (item) {
|
2014-05-04 17:46:52 -07:00
|
|
|
|
|
2015-07-18 11:07:03 -07:00
|
|
|
|
LibraryMenu.setTitle(item.Name);
|
2014-05-19 12:51:56 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-23 07:09:58 -07:00
|
|
|
|
query.folderId = folderId;
|
2014-05-28 19:21:41 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("Channels/" + channelId + "/Items", query)).then(function (result) {
|
2014-03-18 10:05:57 -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);
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
2015-01-28 12:30:45 -07:00
|
|
|
|
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
|
2014-07-19 21:46:29 -07:00
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
showLimit: false,
|
2015-09-07 08:54:57 -07:00
|
|
|
|
updatePageSizeSetting: false,
|
2016-02-14 13:34:54 -07:00
|
|
|
|
sortButton: true,
|
|
|
|
|
filterButton: true
|
2015-01-28 12:30:45 -07:00
|
|
|
|
});
|
|
|
|
|
|
2014-03-18 10:05:57 -07:00
|
|
|
|
updateFilterControls(page);
|
|
|
|
|
|
2016-07-29 13:06:58 -07:00
|
|
|
|
html = cardBuilder.getCardsHtml({
|
2014-03-18 10:05:57 -07:00
|
|
|
|
items: result.Items,
|
2014-05-04 17:46:52 -07:00
|
|
|
|
shape: "auto",
|
2014-06-19 21:50:30 -07:00
|
|
|
|
defaultShape: 'square',
|
2014-03-18 10:05:57 -07:00
|
|
|
|
context: 'channels',
|
|
|
|
|
showTitle: true,
|
2015-05-12 21:55:19 -07:00
|
|
|
|
coverImage: true,
|
|
|
|
|
showYear: true,
|
2015-06-07 14:21:30 -07:00
|
|
|
|
lazy: true,
|
|
|
|
|
centerText: true
|
2014-03-18 10:05:57 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-07-29 21:21:03 -07:00
|
|
|
|
var i, length;
|
|
|
|
|
var elems = page.querySelectorAll('.paging');
|
|
|
|
|
for (i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
elems[i].innerHTML = pagingHtml;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
var elem = page.querySelector('#items');
|
2016-07-29 21:21:03 -07:00
|
|
|
|
elem.innerHTML = html;
|
2015-06-28 07:45:21 -07:00
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-14 13:34:54 -07:00
|
|
|
|
$('.btnFilter', page).on('click', function () {
|
|
|
|
|
showFilterMenu(page);
|
|
|
|
|
});
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
// On callback make sure to set StartIndex = 0
|
|
|
|
|
$('.btnSort', page).on('click', function () {
|
|
|
|
|
showSortMenu(page);
|
|
|
|
|
});
|
2014-05-19 12:51:56 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2014-05-19 12:51:56 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2014-03-18 10:05:57 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-14 13:34:54 -07:00
|
|
|
|
function showFilterMenu(page) {
|
|
|
|
|
|
|
|
|
|
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
|
|
|
|
|
|
|
|
|
|
var filterDialog = new filterDialogFactory({
|
2016-02-26 12:02:53 -07:00
|
|
|
|
query: getQuery(page)
|
2016-02-14 13:34:54 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
filterDialog.show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
function showSortMenu(page) {
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
2016-02-26 12:02:53 -07:00
|
|
|
|
var sortFields = getPageData(page).sortFields;
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var items = [];
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
items.push({
|
|
|
|
|
name: Globalize.translate('OptionDefaultSort'),
|
|
|
|
|
id: ''
|
|
|
|
|
});
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
if (sortFields.indexOf('Name') != -1) {
|
|
|
|
|
items.push({
|
|
|
|
|
name: Globalize.translate('OptionNameSort'),
|
|
|
|
|
id: 'SortName'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (sortFields.indexOf('CommunityRating') != -1) {
|
|
|
|
|
items.push({
|
|
|
|
|
name: Globalize.translate('OptionCommunityRating'),
|
|
|
|
|
id: 'CommunityRating'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (sortFields.indexOf('DateCreated') != -1) {
|
|
|
|
|
items.push({
|
|
|
|
|
name: Globalize.translate('OptionDateAdded'),
|
|
|
|
|
id: 'DateCreated'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (sortFields.indexOf('PlayCount') != -1) {
|
|
|
|
|
items.push({
|
|
|
|
|
name: Globalize.translate('OptionPlayCount'),
|
|
|
|
|
id: 'PlayCount'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (sortFields.indexOf('PremiereDate') != -1) {
|
|
|
|
|
items.push({
|
|
|
|
|
name: Globalize.translate('OptionReleaseDate'),
|
|
|
|
|
id: 'PremiereDate'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (sortFields.indexOf('Runtime') != -1) {
|
|
|
|
|
items.push({
|
|
|
|
|
name: Globalize.translate('OptionRuntime'),
|
|
|
|
|
id: 'Runtime'
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
LibraryBrowser.showSortMenu({
|
|
|
|
|
items: items,
|
|
|
|
|
callback: function () {
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
},
|
2016-02-26 12:02:53 -07:00
|
|
|
|
query: getQuery(page)
|
2015-09-07 08:54:57 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
function updateFilterControls(page) {
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2014-03-18 10:05:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
pageIdOn('pagebeforeshow', "channelItemsPage", function () {
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
2014-05-27 10:57:29 -07:00
|
|
|
|
reloadFeatures(page);
|
2014-05-02 21:20:04 -07:00
|
|
|
|
updateFilterControls(page);
|
2014-03-18 10:05:57 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|