2016-07-16 11:02:39 -07:00
|
|
|
|
define(['events', 'libraryBrowser', 'imageLoader', 'listView', 'emby-itemscontainer'], function (events, libraryBrowser, imageLoader, listView) {
|
2016-10-22 22:11:46 -07:00
|
|
|
|
'use strict';
|
2016-05-15 11:52:36 -07:00
|
|
|
|
|
|
|
|
|
return function (view, params, tabContent) {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
var data = {};
|
2016-06-17 12:44:19 -07:00
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
function getPageData(context) {
|
|
|
|
|
var key = getSavedQueryKey(context);
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
2016-06-17 12:44:19 -07:00
|
|
|
|
SortBy: "Album,SortName",
|
2016-05-15 11:52:36 -07:00
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
IncludeItemTypes: "Audio",
|
|
|
|
|
Recursive: true,
|
2016-08-01 22:55:52 -07:00
|
|
|
|
Fields: "AudioInfo,ParentId",
|
2016-05-15 11:52:36 -07:00
|
|
|
|
Limit: 100,
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
ImageTypeLimit: 1,
|
2016-07-04 22:40:18 -07:00
|
|
|
|
EnableImageTypes: "Primary"
|
2016-05-15 11:52:36 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
pageData.query.ParentId = params.topParentId;
|
|
|
|
|
libraryBrowser.loadSavedQueryValues(key, pageData.query);
|
2016-05-15 11:52:36 -07:00
|
|
|
|
}
|
|
|
|
|
return pageData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQuery(context) {
|
|
|
|
|
|
|
|
|
|
return getPageData(context).query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSavedQueryKey(context) {
|
|
|
|
|
|
|
|
|
|
if (!context.savedQueryKey) {
|
2016-06-17 12:44:19 -07:00
|
|
|
|
context.savedQueryKey = libraryBrowser.getSavedQueryKey('songs');
|
2016-05-15 11:52:36 -07:00
|
|
|
|
}
|
|
|
|
|
return context.savedQueryKey;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
function reloadItems(page) {
|
2016-05-15 11:52:36 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2016-06-17 12:44:19 -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);
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
updateFilterControls(page);
|
|
|
|
|
|
2016-05-15 11:52:36 -07:00
|
|
|
|
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
|
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
|
|
|
|
showLimit: false,
|
|
|
|
|
updatePageSizeSetting: false,
|
2016-06-17 12:44:19 -07:00
|
|
|
|
addLayoutButton: false,
|
|
|
|
|
sortButton: false,
|
|
|
|
|
filterButton: false
|
2016-05-15 11:52:36 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-07-15 22:05:40 -07:00
|
|
|
|
var html = listView.getListViewHtml({
|
2016-05-15 11:52:36 -07:00
|
|
|
|
items: result.Items,
|
2016-07-15 22:05:40 -07:00
|
|
|
|
action: 'playallfromhere',
|
2016-05-15 11:52:36 -07:00
|
|
|
|
smallIcon: true
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-17 12:44:19 -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:44:19 -07:00
|
|
|
|
function onNextPageClick() {
|
2016-05-15 11:52:36 -07:00
|
|
|
|
query.StartIndex += query.Limit;
|
2016-06-17 12:44:19 -07:00
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
}
|
2016-05-15 11:52:36 -07:00
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
function onPreviousPageClick() {
|
2016-05-15 11:52:36 -07:00
|
|
|
|
query.StartIndex -= query.Limit;
|
2016-06-17 12:44:19 -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);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.showFilterMenu = function () {
|
|
|
|
|
|
|
|
|
|
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
|
|
|
|
|
|
|
|
|
|
var filterDialog = new filterDialogFactory({
|
|
|
|
|
query: getQuery(tabContent),
|
|
|
|
|
mode: 'songs'
|
2016-05-15 11:52:36 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
Events.on(filterDialog, 'filterchange', function () {
|
|
|
|
|
getQuery(tabContent).StartIndex = 0;
|
|
|
|
|
reloadItems(tabContent);
|
2016-05-15 11:52:36 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
filterDialog.show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateFilterControls(tabContent) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initPage(tabContent) {
|
|
|
|
|
|
|
|
|
|
tabContent.querySelector('.btnFilter').addEventListener('click', function () {
|
|
|
|
|
self.showFilterMenu();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tabContent.querySelector('.btnSort').addEventListener('click', function (e) {
|
|
|
|
|
libraryBrowser.showSortMenu({
|
|
|
|
|
items: [{
|
|
|
|
|
name: Globalize.translate('OptionTrackName'),
|
|
|
|
|
id: 'Name'
|
|
|
|
|
},
|
2016-05-15 11:52:36 -07:00
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionAlbum'),
|
|
|
|
|
id: 'Album,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionAlbumArtist'),
|
|
|
|
|
id: 'AlbumArtist,Album,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionArtist'),
|
|
|
|
|
id: 'Artist,Album,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionDateAdded'),
|
|
|
|
|
id: 'DateCreated,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionDatePlayed'),
|
|
|
|
|
id: 'DatePlayed,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionPlayCount'),
|
|
|
|
|
id: 'PlayCount,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionReleaseDate'),
|
|
|
|
|
id: 'PremiereDate,AlbumArtist,Album,SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: Globalize.translate('OptionRuntime'),
|
|
|
|
|
id: 'Runtime,AlbumArtist,Album,SortName'
|
|
|
|
|
}],
|
2016-06-17 12:44:19 -07:00
|
|
|
|
callback: function () {
|
|
|
|
|
getQuery(tabContent).StartIndex = 0;
|
|
|
|
|
reloadItems(tabContent);
|
|
|
|
|
},
|
|
|
|
|
query: getQuery(tabContent),
|
|
|
|
|
button: e.target
|
2016-05-15 11:52:36 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
self.getCurrentViewStyle = function () {
|
|
|
|
|
return getPageData(tabContent).view;
|
|
|
|
|
};
|
2016-05-15 11:52:36 -07:00
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
initPage(tabContent);
|
2016-05-15 11:52:36 -07:00
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
self.renderTab = function () {
|
2016-05-15 11:52:36 -07:00
|
|
|
|
|
|
|
|
|
reloadItems(tabContent);
|
2016-06-17 12:44:19 -07:00
|
|
|
|
updateFilterControls(tabContent);
|
2016-05-15 11:52:36 -07:00
|
|
|
|
};
|
|
|
|
|
|
2016-06-17 12:44:19 -07:00
|
|
|
|
self.destroy = function () {
|
|
|
|
|
};
|
|
|
|
|
};
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|