2014-08-02 19:16:37 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
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,
|
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
|
|
|
|
},
|
|
|
|
|
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-08-19 21:06:49 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Playlists/' + item.Id + '/Items', query)).done(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
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
html = LibraryBrowser.getListViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
sortBy: query.SortBy,
|
|
|
|
|
showIndex: false,
|
|
|
|
|
showRemoveFromPlaylist: true,
|
|
|
|
|
playFromHere: true,
|
|
|
|
|
defaultAction: 'playallfromhere',
|
|
|
|
|
smallIcon: true
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
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-10-14 22:48:03 -07:00
|
|
|
|
var listItems = [];
|
|
|
|
|
var elems = elem.querySelectorAll('PAPER-ICON-ITEM');
|
|
|
|
|
for (var i = 0, length = elems.length; i < length; i++) {
|
|
|
|
|
listItems.push(elems[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dashboard.loadDragula(function (dragula) {
|
|
|
|
|
|
|
|
|
|
dragula([elem.querySelector('.paperList')], {
|
|
|
|
|
direction: 'vertical',
|
|
|
|
|
revertOnSpill: true
|
|
|
|
|
}).on('drop', function (el, target, source, sibling) {
|
|
|
|
|
onDrop(el, target, source, sibling, page, item);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2014-08-02 19:16:37 -07:00
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
$(elem).off('needsrefresh').on('needsrefresh', function () {
|
|
|
|
|
|
|
|
|
|
reloadItems(page, item);
|
|
|
|
|
|
|
|
|
|
}).off('removefromplaylist').on('removefromplaylist', function (e, playlistItemId) {
|
|
|
|
|
|
|
|
|
|
removeFromPlaylist(page, item, [playlistItemId]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.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();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 22:48:03 -07:00
|
|
|
|
function onDrop(el, target, source, sibling, page, item) {
|
|
|
|
|
|
|
|
|
|
var parent = $(el).parents('.paperList')[0];
|
|
|
|
|
var newIndex;
|
|
|
|
|
|
|
|
|
|
if (sibling) {
|
|
|
|
|
|
|
|
|
|
newIndex = parseInt(sibling.getAttribute('data-index'));
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// dropped at the end
|
|
|
|
|
newIndex = parent.querySelectorAll('paper-icon-item').length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var itemId = el.getAttribute('data-playlistitemid');
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.ajax({
|
|
|
|
|
|
|
|
|
|
url: ApiClient.getUrl('Playlists/' + item.Id + '/Items/' + itemId + '/Move/' + newIndex),
|
|
|
|
|
|
|
|
|
|
type: 'POST'
|
|
|
|
|
|
|
|
|
|
}).done(function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
}).fail(function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
reloadItems(page, item);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
function removeFromPlaylist(page, item, ids) {
|
2014-08-11 16:41:11 -07:00
|
|
|
|
|
|
|
|
|
ApiClient.ajax({
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
url: ApiClient.getUrl('Playlists/' + item.Id + '/Items', {
|
2014-08-11 16:41:11 -07:00
|
|
|
|
EntryIds: ids.join(',')
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
type: 'DELETE'
|
|
|
|
|
|
|
|
|
|
}).done(function () {
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
reloadItems(page, item);
|
2014-08-11 16:41:11 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-19 21:06:49 -07:00
|
|
|
|
window.PlaylistViewer = {
|
|
|
|
|
render: function (page, item) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
})(jQuery, document);
|