jellyfin-web/dashboard-ui/scripts/playlistedit.js

129 lines
3.4 KiB
JavaScript
Raw Normal View History

(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;
}
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-08-19 21:06:49 -07:00
return getWindowUrl();
2015-02-04 22:29:37 -07:00
}
2015-08-19 21:06:49 -07:00
function reloadItems(page, item) {
Dashboard.showLoadingMsg();
2015-08-19 21:06:49 -07:00
var query = getQuery();
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
// Scroll back up so they can see the results from the beginning
2015-06-28 07:45:21 -07:00
window.scrollTo(0, 0);
var html = '';
2015-08-19 21:06:49 -07:00
html += LibraryBrowser.getQueryPagingHtml({
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
});
2015-08-19 21:06:49 -07:00
var view = getPageData().view;
2015-08-19 21:06:49 -07:00
if (view == "List") {
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
2015-08-19 21:06:49 -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-06-28 18:10:45 -07:00
$(elem).trigger('create');
2015-06-28 07:45:21 -07:00
ImageLoader.lazyChildren(elem);
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 () {
query.StartIndex += query.Limit;
2015-08-19 21:06:49 -07:00
reloadItems(page, item);
});
2015-08-19 21:06:49 -07:00
$('.btnPreviousPage', elem).on('click', function () {
query.StartIndex -= query.Limit;
2015-08-19 21:06:49 -07:00
reloadItems(page, item);
});
Dashboard.hideLoadingMsg();
});
}
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);
}
2015-08-19 21:06:49 -07:00
};
})(jQuery, document);