2016-07-15 22:05:40 -07:00
|
|
|
|
define(['appStorage', 'jQuery', 'listView'], function (appStorage, $, listView) {
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
var data = {};
|
|
|
|
|
function getPageData() {
|
|
|
|
|
var key = getSavedQueryKey();
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SyncInfo",
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
StartIndex: 0,
|
2016-02-25 13:29:38 -07:00
|
|
|
|
Limit: 200
|
2015-08-19 21:06:49 -07:00
|
|
|
|
},
|
|
|
|
|
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('List', 'List')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pageData.query.ParentId = LibraryMenu.getTopParentId();
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
|
|
|
|
return pageData;
|
2014-08-02 19:16:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
function getQuery() {
|
2015-02-04 22:29:37 -07:00
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
return getPageData().query;
|
|
|
|
|
}
|
2015-02-04 22:29:37 -07:00
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
function getSavedQueryKey() {
|
2015-02-04 22:29:37 -07:00
|
|
|
|
|
2015-10-14 21:32:10 -07:00
|
|
|
|
return LibraryBrowser.getSavedQueryKey();
|
2015-02-04 22:29:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
function reloadItems(page, item) {
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
var query = getQuery();
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
query.UserId = Dashboard.getCurrentUserId();
|
2014-08-04 20:41:56 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Playlists/' + item.Id + '/Items', query)).then(function (result) {
|
2014-08-04 20:41:56 -07:00
|
|
|
|
|
2014-08-02 19:16:37 -07:00
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
2015-06-28 07:45:21 -07:00
|
|
|
|
window.scrollTo(0, 0);
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
html += LibraryBrowser.getQueryPagingHtml({
|
2014-08-02 19:16:37 -07:00
|
|
|
|
startIndex: query.StartIndex,
|
|
|
|
|
limit: query.Limit,
|
|
|
|
|
totalRecordCount: result.TotalRecordCount,
|
2015-06-18 21:23:55 -07:00
|
|
|
|
showLimit: false,
|
|
|
|
|
updatePageSizeSetting: false
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
});
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
var view = getPageData().view;
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
if (view == "List") {
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
2016-07-15 22:05:40 -07:00
|
|
|
|
html = listView.getListViewHtml({
|
2015-08-19 21:06:49 -07:00
|
|
|
|
items: result.Items,
|
|
|
|
|
sortBy: query.SortBy,
|
|
|
|
|
showIndex: false,
|
|
|
|
|
showRemoveFromPlaylist: true,
|
|
|
|
|
playFromHere: true,
|
2016-07-15 22:05:40 -07:00
|
|
|
|
action: 'playallfromhere',
|
2016-07-16 11:02:39 -07:00
|
|
|
|
smallIcon: true,
|
2016-07-20 13:45:50 -07:00
|
|
|
|
dragHandle: true,
|
|
|
|
|
playlistId: item.Id
|
2015-08-19 21:06:49 -07:00
|
|
|
|
});
|
2014-08-02 19:16:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
var elem = page.querySelector('#childrenContent .itemsContainer');
|
2015-06-28 07:45:21 -07:00
|
|
|
|
elem.innerHTML = html;
|
2015-09-05 21:53:37 -07:00
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2015-08-19 21:06:49 -07:00
|
|
|
|
|
|
|
|
|
$('.btnNextPage', elem).on('click', function () {
|
2014-08-02 19:16:37 -07:00
|
|
|
|
query.StartIndex += query.Limit;
|
2015-08-19 21:06:49 -07:00
|
|
|
|
reloadItems(page, item);
|
2014-08-02 19:16:37 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
$('.btnPreviousPage', elem).on('click', function () {
|
2014-08-02 19:16:37 -07:00
|
|
|
|
query.StartIndex -= query.Limit;
|
2015-08-19 21:06:49 -07:00
|
|
|
|
reloadItems(page, item);
|
2014-08-02 19:16:37 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 23:08:47 -07:00
|
|
|
|
function init(page, item) {
|
|
|
|
|
|
|
|
|
|
var elem = page.querySelector('#childrenContent .itemsContainer');
|
|
|
|
|
|
2016-07-19 13:23:28 -07:00
|
|
|
|
elem.enableDragReordering(true);
|
|
|
|
|
|
2016-06-01 23:08:47 -07:00
|
|
|
|
elem.addEventListener('needsrefresh', function () {
|
|
|
|
|
|
|
|
|
|
reloadItems(page, item);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
window.PlaylistViewer = {
|
|
|
|
|
render: function (page, item) {
|
2015-10-16 10:10:48 -07:00
|
|
|
|
|
2016-06-01 23:08:47 -07:00
|
|
|
|
if (!page.playlistInit) {
|
|
|
|
|
page.playlistInit = true;
|
|
|
|
|
init(page, item);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
reloadItems(page, item);
|
2014-08-02 19:16:37 -07:00
|
|
|
|
}
|
2015-08-19 21:06:49 -07:00
|
|
|
|
};
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
2016-03-07 12:13:58 -07:00
|
|
|
|
});
|