2016-06-06 22:42:26 -07:00
|
|
|
|
define(['jQuery', 'alphaPicker'], function ($, alphaPicker) {
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
return function (view, params, tabContent) {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
var data = {};
|
|
|
|
|
function getPageData(context) {
|
|
|
|
|
var key = getSavedQueryKey(context);
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,DateCreated,SyncInfo,ItemCounts",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
|
|
|
|
},
|
|
|
|
|
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pageData.query.ParentId = LibraryMenu.getTopParentId();
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
2015-07-08 09:10:34 -07:00
|
|
|
|
}
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
function getQuery(context) {
|
2014-05-01 19:54:33 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
return getPageData(context).query;
|
2016-02-26 12:02:53 -07:00
|
|
|
|
}
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
function getSavedQueryKey(context) {
|
2015-07-08 09:10:34 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
if (!context.savedQueryKey) {
|
|
|
|
|
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('albumartists');
|
|
|
|
|
}
|
|
|
|
|
return context.savedQueryKey;
|
|
|
|
|
}
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
function reloadItems(page) {
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2015-09-03 12:04:29 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
var query = getQuery(page);
|
2015-01-28 12:30:45 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
ApiClient.getAlbumArtists(Dashboard.getCurrentUserId(), query).then(function (result) {
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
|
|
|
window.scrollTo(0, 0);
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
var view = getPageData(page).view;
|
2014-07-05 14:15:25 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
var html = '';
|
|
|
|
|
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
|
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
showLimit: false,
|
|
|
|
|
updatePageSizeSetting: false,
|
|
|
|
|
addLayoutButton: true,
|
|
|
|
|
currentLayout: view,
|
|
|
|
|
filterButton: true
|
2014-07-05 14:15:25 -07:00
|
|
|
|
});
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
|
|
|
|
|
|
|
|
|
|
updateFilterControls(page);
|
|
|
|
|
|
|
|
|
|
if (view == "List") {
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getListViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
context: 'music',
|
|
|
|
|
sortBy: query.SortBy
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "Poster") {
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "square",
|
|
|
|
|
context: 'music',
|
|
|
|
|
showTitle: true,
|
|
|
|
|
coverImage: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
overlayPlayButton: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "PosterCard") {
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "square",
|
|
|
|
|
context: 'music',
|
|
|
|
|
showTitle: true,
|
|
|
|
|
coverImage: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
cardLayout: true,
|
|
|
|
|
showSongCount: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var elem = page.querySelector('#items');
|
|
|
|
|
elem.innerHTML = html + pagingHtml;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
|
|
|
|
|
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
|
|
|
|
|
getPageData(page).view = layout;
|
|
|
|
|
LibraryBrowser.saveViewSetting(getSavedQueryKey(page), layout);
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
2015-09-03 12:04:29 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
$('.btnFilter', page).on('click', function () {
|
|
|
|
|
showFilterMenu(page);
|
|
|
|
|
});
|
2016-02-15 09:57:51 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2013-11-21 13:48:26 -07:00
|
|
|
|
});
|
2016-05-15 11:52:36 -07:00
|
|
|
|
}
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
function showFilterMenu(page) {
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
|
2015-07-08 09:10:34 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
var filterDialog = new filterDialogFactory({
|
|
|
|
|
query: getQuery(page),
|
|
|
|
|
mode: 'albumartists'
|
|
|
|
|
});
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
});
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
filterDialog.show();
|
2016-02-15 09:57:51 -07:00
|
|
|
|
});
|
2016-05-15 11:52:36 -07:00
|
|
|
|
}
|
2014-05-23 16:58:28 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
function updateFilterControls(tabContent) {
|
2015-07-08 09:10:34 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
var query = getQuery(tabContent);
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2016-06-06 22:42:26 -07:00
|
|
|
|
self.alphaPicker.value(query.NameStartsWithOrGreater);
|
2016-05-15 11:52:36 -07:00
|
|
|
|
}
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-06-06 22:42:26 -07:00
|
|
|
|
var alphaPickerElement = tabContent.querySelector('.alphaPicker');
|
|
|
|
|
alphaPickerElement.addEventListener('alphavaluechanged', function (e) {
|
|
|
|
|
var newValue = e.detail.value;
|
2016-02-26 12:02:53 -07:00
|
|
|
|
var query = getQuery(tabContent);
|
2016-06-06 22:42:26 -07:00
|
|
|
|
query.NameStartsWithOrGreater = newValue;
|
2013-11-21 13:48:26 -07:00
|
|
|
|
query.StartIndex = 0;
|
2016-02-15 09:57:51 -07:00
|
|
|
|
reloadItems(tabContent);
|
2016-06-06 22:42:26 -07:00
|
|
|
|
});
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-06-06 22:42:26 -07:00
|
|
|
|
self.alphaPicker = new alphaPicker({
|
2016-06-07 22:24:25 -07:00
|
|
|
|
element: alphaPickerElement,
|
|
|
|
|
valueChangeEvent: 'click'
|
2014-07-19 21:46:29 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
self.renderTab = function () {
|
2014-05-01 19:54:33 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
};
|
2015-09-03 12:04:29 -07:00
|
|
|
|
};
|
2013-11-21 13:48:26 -07:00
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|