2014-03-18 10:05:57 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
2014-05-27 14:17:48 -07:00
|
|
|
|
var maxPageSize;
|
2014-05-28 19:21:41 -07:00
|
|
|
|
|
2014-03-18 10:05:57 -07:00
|
|
|
|
// The base query options
|
|
|
|
|
var query = {
|
|
|
|
|
|
2014-05-27 14:17:48 -07:00
|
|
|
|
SortBy: "",
|
2014-05-02 21:20:04 -07:00
|
|
|
|
SortOrder: "Ascending",
|
2014-06-07 14:06:01 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio",
|
2014-03-18 10:05:57 -07:00
|
|
|
|
StartIndex: 0
|
|
|
|
|
};
|
2014-05-28 19:21:41 -07:00
|
|
|
|
|
2014-05-27 14:17:48 -07:00
|
|
|
|
function getPageSizes() {
|
|
|
|
|
|
|
|
|
|
var sizes = [];
|
|
|
|
|
|
|
|
|
|
if (!maxPageSize || maxPageSize >= 10) sizes.push(10);
|
|
|
|
|
if (!maxPageSize || maxPageSize >= 20) sizes.push(20);
|
|
|
|
|
if (!maxPageSize || maxPageSize >= 30) sizes.push(30);
|
|
|
|
|
if (!maxPageSize || maxPageSize >= 40) sizes.push(40);
|
|
|
|
|
if (!maxPageSize || maxPageSize >= 50) sizes.push(50);
|
|
|
|
|
if (!maxPageSize || maxPageSize >= 100) sizes.push(100);
|
2014-05-28 19:21:41 -07:00
|
|
|
|
|
2014-05-27 14:17:48 -07:00
|
|
|
|
return sizes;
|
|
|
|
|
}
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
|
|
|
|
function getSavedQueryId() {
|
2014-05-27 14:17:48 -07:00
|
|
|
|
return 'channels-1-' + getParameterByName('id') + (getParameterByName('folderId') || '');
|
2014-03-18 10:05:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
function showLoadingMessage(page) {
|
|
|
|
|
|
|
|
|
|
$('#popupDialog', page).popup('open');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideLoadingMessage(page) {
|
|
|
|
|
$('#popupDialog', page).popup('close');
|
|
|
|
|
}
|
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');
|
|
|
|
|
|
2014-07-01 22:16:59 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("Channels/" + channelId + "/Features", query)).done(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
|
|
|
|
|
|
|
|
|
maxPageSize = features.MaxPageSize;
|
|
|
|
|
|
2014-05-28 19:21:41 -07:00
|
|
|
|
if (maxPageSize) {
|
|
|
|
|
query.Limit = Math.min(maxPageSize, query.Limit || maxPageSize);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-27 14:17:48 -07:00
|
|
|
|
updateSortOrders(page, 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-05-27 14:17:48 -07:00
|
|
|
|
function updateSortOrders(page, fields) {
|
|
|
|
|
|
|
|
|
|
updateSortOrder(page, fields, 'Name');
|
|
|
|
|
updateSortOrder(page, fields, 'CommunityRating');
|
|
|
|
|
updateSortOrder(page, fields, 'PremiereDate');
|
|
|
|
|
updateSortOrder(page, fields, 'PlayCount');
|
|
|
|
|
updateSortOrder(page, fields, 'Runtime');
|
|
|
|
|
updateSortOrder(page, fields, 'DateCreated');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateSortOrder(page, fields, name) {
|
2014-05-28 19:21:41 -07:00
|
|
|
|
|
2014-05-27 14:17:48 -07:00
|
|
|
|
var cssClass = "sortby" + name;
|
|
|
|
|
|
|
|
|
|
if (fields.indexOf(name) == -1) {
|
|
|
|
|
|
|
|
|
|
$('.' + cssClass, page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.' + cssClass, page).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 10:05:57 -07:00
|
|
|
|
function reloadItems(page) {
|
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
showLoadingMessage(page);
|
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
|
|
|
|
|
|
|
|
|
query.UserId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
2014-05-23 07:09:58 -07:00
|
|
|
|
if (folderId) {
|
2014-05-19 12:51:56 -07:00
|
|
|
|
|
2014-05-23 07:09:58 -07:00
|
|
|
|
ApiClient.getItem(query.UserId, folderId).done(function (item) {
|
2014-05-19 12:51:56 -07:00
|
|
|
|
|
|
|
|
|
$('.categoryTitle', page).show().html(item.Name);
|
|
|
|
|
$('.channelHeader', page).show().html('<a href="channelitems.html?id=' + item.ChannelId + '">' + item.ChannelName + '</a>').trigger('create');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
ApiClient.getItem(query.UserId, channelId).done(function (item) {
|
2014-05-04 17:46:52 -07:00
|
|
|
|
|
2014-05-19 12:51:56 -07:00
|
|
|
|
$('.categoryTitle', page).hide().html(item.Name);
|
|
|
|
|
$('.channelHeader', page).show().html('<a href="channelitems.html?id=' + item.Id + '">' + item.Name + '</a>');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-23 07:09:58 -07:00
|
|
|
|
query.folderId = folderId;
|
2014-05-28 19:21:41 -07:00
|
|
|
|
|
2014-07-01 22:16:59 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("Channels/" + channelId + "/Items", query)).done(function (result) {
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
|
|
|
$(document).scrollTop(0);
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2014-07-19 21:46:29 -07:00
|
|
|
|
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
|
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
viewButton: true,
|
|
|
|
|
showLimit: false,
|
|
|
|
|
updatePageSizeSetting: false
|
|
|
|
|
});
|
|
|
|
|
|
2014-05-31 21:11:04 -07:00
|
|
|
|
$('.listTopPaging', page).html(pagingHtml).trigger('create');
|
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,
|
2014-05-18 12:58:42 -07:00
|
|
|
|
centerText: true,
|
|
|
|
|
coverImage: true
|
2014-03-18 10:05:57 -07:00
|
|
|
|
});
|
|
|
|
|
|
2014-06-01 12:41:35 -07:00
|
|
|
|
html += pagingHtml;
|
2014-05-08 13:09:53 -07:00
|
|
|
|
|
2014-08-01 19:34:45 -07:00
|
|
|
|
$('#items', page).html(html).trigger('create').createCardMenus();
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryId(), query);
|
|
|
|
|
|
2014-05-19 12:51:56 -07:00
|
|
|
|
|
|
|
|
|
}).always(function () {
|
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
hideLoadingMessage(page);
|
2014-03-18 10:05:57 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateFilterControls(page) {
|
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
// Reset form values using the last used query
|
|
|
|
|
$('.radioSortBy', page).each(function () {
|
|
|
|
|
|
|
|
|
|
this.checked = (query.SortBy || '').toLowerCase() == this.getAttribute('data-sortby').toLowerCase();
|
|
|
|
|
|
|
|
|
|
}).checkboxradio('refresh');
|
|
|
|
|
|
|
|
|
|
$('.radioSortOrder', page).each(function () {
|
|
|
|
|
|
|
|
|
|
this.checked = (query.SortOrder || '').toLowerCase() == this.getAttribute('data-sortorder').toLowerCase();
|
|
|
|
|
|
|
|
|
|
}).checkboxradio('refresh');
|
|
|
|
|
|
|
|
|
|
$('.chkStandardFilter', page).each(function () {
|
|
|
|
|
|
|
|
|
|
var filters = "," + (query.Filters || "");
|
|
|
|
|
var filterName = this.getAttribute('data-filter');
|
|
|
|
|
|
|
|
|
|
this.checked = filters.indexOf(',' + filterName) != -1;
|
|
|
|
|
|
|
|
|
|
}).checkboxradio('refresh');
|
|
|
|
|
|
|
|
|
|
$('.alphabetPicker', page).alphaValue(query.NameStartsWith);
|
2014-07-19 21:46:29 -07:00
|
|
|
|
$('#selectPageSize', page).val(query.Limit).selectmenu('refresh');
|
2014-03-18 10:05:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
$(document).on('pageinit', "#channelItemsPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('.radioSortBy', this).on('click', function () {
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
query.SortBy = this.getAttribute('data-sortby');
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.radioSortOrder', this).on('click', function () {
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
query.SortOrder = this.getAttribute('data-sortorder');
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.chkStandardFilter', this).on('change', function () {
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
query.NameStartsWithOrGreater = character;
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
|
|
|
|
|
}).on('alphaclear', function (e) {
|
|
|
|
|
|
|
|
|
|
query.NameStartsWithOrGreater = '';
|
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
2014-07-19 21:46:29 -07:00
|
|
|
|
$('#selectPageSize', page).on('change', function () {
|
|
|
|
|
query.Limit = parseInt(this.value);
|
|
|
|
|
query.StartIndex = 0;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
}).on('pagebeforeshow', "#channelItemsPage", function () {
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
|
|
|
|
|
}).on('pageshow', "#channelItemsPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
2014-03-18 10:05:57 -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;
|
|
|
|
|
}
|
2014-05-19 12:51:56 -07:00
|
|
|
|
query.StartIndex = 0;
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(getSavedQueryId(), query);
|
|
|
|
|
|
2014-05-27 10:57:29 -07:00
|
|
|
|
reloadFeatures(page);
|
2014-03-18 10:05:57 -07:00
|
|
|
|
|
2014-05-02 21:20:04 -07:00
|
|
|
|
updateFilterControls(page);
|
2014-03-18 10:05:57 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(jQuery, document);
|