2016-06-17 12:10:05 -07:00
|
|
|
|
define([], function () {
|
|
|
|
|
|
|
|
|
|
return function (view, params, tabContent) {
|
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
var self = this;
|
2016-06-17 12:10:05 -07:00
|
|
|
|
|
|
|
|
|
var data = {};
|
|
|
|
|
function getPageData() {
|
|
|
|
|
var key = getSavedQueryKey();
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
2016-06-22 13:07:52 -07:00
|
|
|
|
IncludeItemTypes: "Audio,MusicAlbum",
|
2016-06-17 12:10:05 -07:00
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "DateCreated,SyncInfo,ItemCounts",
|
|
|
|
|
StartIndex: 0
|
|
|
|
|
},
|
|
|
|
|
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Thumb', 'Thumb')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pageData.query.ParentId = params.topParentId;
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQuery() {
|
|
|
|
|
|
|
|
|
|
return getPageData().query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSavedQueryKey() {
|
|
|
|
|
|
|
|
|
|
return LibraryBrowser.getSavedQueryKey('genres');
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-29 10:43:34 -07:00
|
|
|
|
function getPromise() {
|
2016-06-17 12:10:05 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
2016-06-29 10:43:34 -07:00
|
|
|
|
return ApiClient.getGenres(Dashboard.getCurrentUserId(), query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reloadItems(context, promise) {
|
|
|
|
|
|
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
|
|
|
|
promise.then(function (result) {
|
2016-06-17 12:10:05 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
var viewStyle = self.getCurrentViewStyle();
|
|
|
|
|
|
|
|
|
|
if (viewStyle == "Thumb") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
context: 'music',
|
|
|
|
|
showItemCounts: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true,
|
2016-06-29 10:43:34 -07:00
|
|
|
|
overlayMoreButton: true
|
2016-06-17 12:10:05 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (viewStyle == "ThumbCard") {
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "backdrop",
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
context: 'music',
|
|
|
|
|
showItemCounts: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showTitle: true,
|
|
|
|
|
lazy: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (viewStyle == "PosterCard") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "portrait",
|
|
|
|
|
context: 'music',
|
|
|
|
|
showItemCounts: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showTitle: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (viewStyle == "Poster") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "portrait",
|
|
|
|
|
context: 'music',
|
|
|
|
|
centerText: true,
|
|
|
|
|
showItemCounts: true,
|
|
|
|
|
lazy: true,
|
2016-06-29 10:43:34 -07:00
|
|
|
|
overlayMoreButton: true
|
2016-06-17 12:10:05 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var elem = context.querySelector('#items');
|
|
|
|
|
elem.innerHTML = html;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
2015-09-03 09:39:24 -07:00
|
|
|
|
}
|
2016-06-17 12:10:05 -07:00
|
|
|
|
self.getViewStyles = function () {
|
|
|
|
|
return 'Poster,PosterCard,Thumb,ThumbCard'.split(',');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.getCurrentViewStyle = function () {
|
|
|
|
|
return getPageData(tabContent).view;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.setCurrentViewStyle = function (viewStyle) {
|
|
|
|
|
getPageData(tabContent).view = viewStyle;
|
|
|
|
|
LibraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
|
2016-06-29 10:43:34 -07:00
|
|
|
|
fullyReload();
|
2016-06-17 12:10:05 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.enableViewSelection = true;
|
2016-06-29 10:43:34 -07:00
|
|
|
|
var promise;
|
|
|
|
|
|
|
|
|
|
self.preRender = function () {
|
|
|
|
|
promise = getPromise();
|
|
|
|
|
};
|
2016-06-17 12:10:05 -07:00
|
|
|
|
|
|
|
|
|
self.renderTab = function () {
|
|
|
|
|
|
2016-06-29 10:43:34 -07:00
|
|
|
|
reloadItems(tabContent, promise);
|
2016-06-17 12:10:05 -07:00
|
|
|
|
};
|
|
|
|
|
|
2016-06-29 10:43:34 -07:00
|
|
|
|
function fullyReload() {
|
|
|
|
|
self.preRender();
|
|
|
|
|
self.renderTab();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
var btnSelectView = tabContent.querySelector('.btnSelectView');
|
|
|
|
|
btnSelectView.addEventListener('click', function (e) {
|
2016-06-17 12:10:05 -07:00
|
|
|
|
|
|
|
|
|
LibraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), self.getViewStyles());
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
btnSelectView.addEventListener('layoutchange', function (e) {
|
2016-06-17 12:10:05 -07:00
|
|
|
|
|
|
|
|
|
self.setCurrentViewStyle(e.detail.viewStyle);
|
|
|
|
|
});
|
|
|
|
|
};
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|