jellyfin-web/dashboard-ui/scripts/channelitems.js

197 lines
5.7 KiB
JavaScript
Raw Normal View History

2014-03-18 10:05:57 -07:00
(function ($, document) {
// The base query options
var query = {
2014-05-02 21:20:04 -07:00
SortBy: "SortName",
SortOrder: "Ascending",
2014-03-18 10:05:57 -07:00
StartIndex: 0
};
function getSavedQueryId() {
2014-05-18 12:58:42 -07:00
return 'channels-' + getParameterByName('id') + (getParameterByName('categoryId') || '');
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-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-04 17:46:52 -07:00
var categoryId = getParameterByName('categoryId');
2014-03-18 10:05:57 -07:00
query.UserId = Dashboard.getCurrentUserId();
2014-05-04 17:46:52 -07:00
if (categoryId) {
ApiClient.getItem(query.UserId, categoryId).done(function (item) {
$('.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
$('.categoryTitle', page).hide().html(item.Name);
$('.channelHeader', page).show().html('<a href="channelitems.html?id=' + item.Id + '">' + item.Name + '</a>');
});
}
query.categoryId = categoryId;
query.Limit = 50;
2014-03-18 10:05:57 -07:00
$.getJSON(ApiClient.getUrl("Channels/" + channelId + "/Items", query)).done(function (result) {
// Scroll back up so they can see the results from the beginning
$(document).scrollTop(0);
var html = '';
$('.listTopPaging', page).html(LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, true)).trigger('create');
updateFilterControls(page);
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
2014-05-04 17:46:52 -07:00
shape: "auto",
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-05-08 13:09:53 -07:00
html += LibraryBrowser.getPagingHtml(query, result.TotalRecordCount);
2014-03-18 10:05:57 -07:00
$('#items', page).html(html).trigger('create').createPosterItemMenus();
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
$('.selectPageSize', page).on('change', function () {
query.Limit = parseInt(this.value);
query.StartIndex = 0;
reloadItems(page);
});
LibraryBrowser.saveQueryValues(getSavedQueryId(), query);
}).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-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);
});
}).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;
}
query.StartIndex = 0;
2014-03-18 10:05:57 -07:00
LibraryBrowser.loadSavedQueryValues(getSavedQueryId(), query);
2014-05-02 21:20:04 -07:00
reloadItems(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);