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

127 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-07-29 13:06:58 -07:00
define(['events', 'libraryBrowser', 'imageLoader', 'cardBuilder'], function (events, libraryBrowser, imageLoader, cardBuilder) {
2016-05-15 11:52:36 -07:00
return function (view, params, tabContent) {
var self = this;
var data = {};
2016-06-17 12:56:29 -07:00
function getPageData(context) {
var key = getSavedQueryKey(context);
2016-05-15 11:52:36 -07:00
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
2016-08-01 22:55:52 -07:00
Fields: "PrimaryImageAspectRatio,SortName",
2016-05-15 11:52:36 -07:00
StartIndex: 0,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
Limit: LibraryBrowser.getDefaultPageSize()
},
view: libraryBrowser.getSavedView(key) || 'Poster'
2016-05-15 11:52:36 -07:00
};
2016-06-17 12:56:29 -07:00
pageData.query.ParentId = params.topParentId;
libraryBrowser.loadSavedQueryValues(key, pageData.query);
2016-05-15 11:52:36 -07:00
}
return pageData;
}
2016-06-17 12:56:29 -07:00
function getQuery(context) {
2016-05-15 11:52:36 -07:00
2016-06-17 12:56:29 -07:00
return getPageData(context).query;
2016-05-15 11:52:36 -07:00
}
2016-06-17 12:56:29 -07:00
function getSavedQueryKey(context) {
2016-05-15 11:52:36 -07:00
2016-06-17 12:56:29 -07:00
if (!context.savedQueryKey) {
context.savedQueryKey = libraryBrowser.getSavedQueryKey('folders');
}
return context.savedQueryKey;
2016-05-15 11:52:36 -07:00
}
2016-06-17 12:56:29 -07:00
function reloadItems(page) {
2016-05-15 11:52:36 -07:00
Dashboard.showLoadingMsg();
2016-06-17 12:56:29 -07:00
var query = getQuery(page);
2016-05-15 11:52:36 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false,
2016-06-17 12:56:29 -07:00
addLayoutButton: false,
sortButton: false,
filterButton: false
2016-05-15 11:52:36 -07:00
});
2016-07-29 13:06:58 -07:00
var html = cardBuilder.getCardsHtml({
2016-06-17 12:56:29 -07:00
items: result.Items,
shape: "square",
context: 'folders',
showTitle: true,
showParentTitle: true,
lazy: true,
centerText: true,
overlayPlayButton: true
});
2016-05-15 11:52:36 -07:00
2016-06-17 12:56:29 -07:00
var i, length;
var elems = tabContent.querySelectorAll('.paging');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].innerHTML = pagingHtml;
}
2016-05-15 11:52:36 -07:00
2016-06-17 12:56:29 -07:00
function onNextPageClick() {
2016-05-15 11:52:36 -07:00
query.StartIndex += query.Limit;
2016-06-17 12:56:29 -07:00
reloadItems(tabContent);
}
2016-05-15 11:52:36 -07:00
2016-06-17 12:56:29 -07:00
function onPreviousPageClick() {
2016-05-15 11:52:36 -07:00
query.StartIndex -= query.Limit;
2016-06-17 12:56:29 -07:00
reloadItems(tabContent);
}
elems = tabContent.querySelectorAll('.btnNextPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onNextPageClick);
}
elems = tabContent.querySelectorAll('.btnPreviousPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onPreviousPageClick);
}
var itemsContainer = tabContent.querySelector('.itemsContainer');
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
2016-05-15 11:52:36 -07:00
Dashboard.hideLoadingMsg();
});
}
2016-06-17 12:56:29 -07:00
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
};
self.renderTab = function () {
2016-05-15 11:52:36 -07:00
reloadItems(tabContent);
};
2016-06-17 12:56:29 -07:00
self.destroy = function () {
};
};
});