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

210 lines
6.0 KiB
JavaScript
Raw Normal View History

(function ($, document) {
2015-05-17 12:50:37 -07:00
var view = LibraryBrowser.getDefaultItemsView('Poster', 'PosterCard');
// The base query options
var query = {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "MusicVideo",
Recursive: true,
2014-12-10 23:20:28 -07:00
Fields: "DateCreated,SyncInfo",
StartIndex: 0
};
2014-05-01 19:54:33 -07:00
function getSavedQueryKey() {
return 'musicvideos' + (query.ParentId || '');
}
function reloadItems(page) {
Dashboard.showLoadingMsg();
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
// Scroll back up so they can see the results from the beginning
2015-06-28 07:45:21 -07:00
window.scrollTo(0, 0);
var html = '';
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,
viewButton: true,
showLimit: false
2015-01-22 23:15:15 -07:00
})).trigger('create');
2013-10-18 09:09:47 -07:00
updateFilterControls(page);
2015-05-12 21:55:19 -07:00
if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "square",
context: 'music',
showTitle: true,
lazy: true,
2015-05-14 19:16:57 -07:00
centerText: true,
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
}
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "square",
context: 'music',
showTitle: true,
centerText: true,
cardLayout: true,
lazy: true,
2015-05-14 19:16:57 -07:00
showParentTitle: true,
showDetailsMenu: true
2015-05-12 21:55:19 -07:00
});
}
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('#items');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
2014-05-01 19:54:33 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
Dashboard.hideLoadingMsg();
});
}
2013-10-18 09:09:47 -07:00
function updateFilterControls(page) {
// 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.NameStartsWithOrGreater);
$('#selectPageSize', page).val(query.Limit).selectmenu('refresh');
}
2013-10-18 09:09:47 -07:00
var filtersLoaded;
function reloadFiltersIfNeeded(page) {
2013-10-18 09:09:47 -07:00
if (!filtersLoaded) {
2013-10-18 09:09:47 -07:00
filtersLoaded = true;
2013-10-18 09:09:47 -07:00
QueryFilters.loadFilters(page, Dashboard.getCurrentUserId(), query, function () {
2013-10-18 09:09:47 -07:00
reloadItems(page);
});
}
2013-10-18 09:09:47 -07:00
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#musicVideosPage", function () {
var page = this;
$('.viewPanel', page).on('panelopen', function () {
reloadFiltersIfNeeded(page);
});
$('.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);
});
2015-08-31 23:22:46 -07:00
}).on('pagebeforeshow', "#musicVideosPage", function () {
var page = this;
2014-06-04 19:32:40 -07:00
query.ParentId = LibraryMenu.getTopParentId();
2014-05-01 19:54:33 -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-05-01 19:54:33 -07:00
LibraryBrowser.loadSavedQueryValues(getSavedQueryKey(), query);
QueryFilters.onPageShow(page, query);
reloadItems(page);
2013-10-18 09:09:47 -07:00
updateFilterControls(this);
});
})(jQuery, document);