2014-03-18 10:05:57 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
|
|
function getPageData() {
|
|
|
|
|
var key = getSavedQueryKey();
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SyncInfo",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
2014-03-18 10:05:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
function getQuery() {
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
return getPageData().query;
|
2014-05-02 21:20:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
function getSavedQueryKey() {
|
|
|
|
|
|
2015-10-14 21:32:10 -07:00
|
|
|
|
return LibraryBrowser.getSavedQueryKey('movies');
|
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
|
|
|
|
|
2014-05-27 10:57:29 -07:00
|
|
|
|
var channelId = getParameterByName('id');
|
|
|
|
|
|
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
|
|
|
|
|
2015-10-04 11:10:50 -07:00
|
|
|
|
var query = getQuery();
|
2014-05-28 19:21:41 -07:00
|
|
|
|
if (maxPageSize) {
|
|
|
|
|
query.Limit = Math.min(maxPageSize, query.Limit || maxPageSize);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
getPageData().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
|
|
|
|
|
|
|
|
|
var channelId = getParameterByName('id');
|
2014-05-23 07:09:58 -07:00
|
|
|
|
var folderId = getParameterByName('folderId');
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
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,
|
|
|
|
|
viewButton: true,
|
|
|
|
|
showLimit: false,
|
2015-09-07 08:54:57 -07:00
|
|
|
|
updatePageSizeSetting: false,
|
|
|
|
|
viewIcon: 'filter-list',
|
|
|
|
|
sortButton: true
|
2015-01-28 12:30:45 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
|
|
|
|
updateFilterControls(page);
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
var elem = page.querySelector('#items');
|
|
|
|
|
elem.innerHTML = html + pagingHtml;
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
function showSortMenu(page) {
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var sortFields = getPageData().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);
|
|
|
|
|
},
|
|
|
|
|
query: getQuery()
|
|
|
|
|
});
|
|
|
|
|
}
|
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
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
2014-05-02 21:20:04 -07:00
|
|
|
|
$('.chkStandardFilter', page).each(function () {
|
|
|
|
|
|
|
|
|
|
var filters = "," + (query.Filters || "");
|
|
|
|
|
var filterName = this.getAttribute('data-filter');
|
|
|
|
|
|
|
|
|
|
this.checked = filters.indexOf(',' + filterName) != -1;
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
});
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
|
|
|
|
$('.alphabetPicker', page).alphaValue(query.NameStartsWith);
|
2014-03-18 10:05:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
pageIdOn('pageinit', "channelItemsPage", function () {
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('.chkStandardFilter', this).on('change', function () {
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
2014-05-02 21:20:04 -07:00
|
|
|
|
var filterName = this.getAttribute('data-filter');
|
|
|
|
|
var filters = query.Filters || "";
|
|
|
|
|
|
|
|
|
|
filters = (',' + filters).replace(',' + filterName, '').substring(1);
|
|
|
|
|
|
|
|
|
|
if (this.checked) {
|
|
|
|
|
filters = filters ? (filters + ',' + filterName) : filterName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
query.Filters = filters;
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.alphabetPicker', this).on('alphaselect', function (e, character) {
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
2014-05-02 21:20:04 -07:00
|
|
|
|
query.NameStartsWithOrGreater = character;
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
|
|
|
|
|
}).on('alphaclear', function (e) {
|
|
|
|
|
|
2015-09-07 08:54:57 -07:00
|
|
|
|
var query = getQuery();
|
2014-05-02 21:20:04 -07:00
|
|
|
|
query.NameStartsWithOrGreater = '';
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(jQuery, document);
|