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

204 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-07-15 22:05:40 -07:00
define(['appStorage', 'jQuery', 'listView'], function (appStorage, $, listView) {
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;
}
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) {
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-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
// 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") {
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,
dragHandle: 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-09-05 21:53:37 -07:00
2016-07-16 11:02:39 -07:00
var listParent = elem;
2016-07-16 11:02:39 -07:00
require(['sortable'], function (Sortable) {
2016-07-16 11:02:39 -07:00
var sortable = new Sortable(listParent, {
2015-10-22 08:03:08 -07:00
2016-07-16 11:02:39 -07:00
draggable: ".listItem",
handle: '.listViewDragHandle',
2015-10-22 08:03:08 -07:00
2016-07-16 11:02:39 -07:00
// dragging ended
onEnd: function (/**Event*/evt) {
2015-10-22 08:03:08 -07:00
2016-07-16 11:02:39 -07:00
onDrop(evt, page, item);
}
2015-10-22 08:03:08 -07:00
});
2016-07-16 11:02:39 -07:00
});
2015-06-28 07:45:21 -07:00
ImageLoader.lazyChildren(elem);
2016-06-01 23:08:47 -07:00
LibraryBrowser.createCardMenus(elem);
2015-08-19 21:06:49 -07:00
$('.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-10-22 08:03:08 -07:00
function onDrop(evt, page, item) {
2016-07-16 11:02:39 -07:00
Dashboard.showLoadingMsg();
2015-10-22 08:03:08 -07:00
var el = evt.item;
2016-07-11 11:59:46 -07:00
2015-10-22 08:03:08 -07:00
var newIndex = evt.newIndex;
var itemId = el.getAttribute('data-playlistitemid');
ApiClient.ajax({
url: ApiClient.getUrl('Playlists/' + item.Id + '/Items/' + itemId + '/Move/' + newIndex),
type: 'POST'
2015-12-14 08:43:03 -07:00
}).then(function () {
2016-07-11 11:59:46 -07:00
el.setAttribute('data-index', newIndex);
Dashboard.hideLoadingMsg();
2015-12-14 08:43:03 -07:00
}, 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'
2015-12-14 08:43:03 -07:00
}).then(function () {
2014-08-11 16:41:11 -07:00
2015-08-19 21:06:49 -07:00
reloadItems(page, item);
2014-08-11 16:41:11 -07:00
});
}
2015-10-16 10:10:48 -07:00
function showDragAndDropHelp() {
2015-10-22 08:03:08 -07:00
if (AppInfo.isTouchPreferred) {
2015-10-16 10:10:48 -07:00
// Not implemented for mobile yet
return;
}
var expectedValue = "7";
if (appStorage.getItem("playlistitemdragdrophelp") == expectedValue) {
return;
}
appStorage.setItem("playlistitemdragdrophelp", expectedValue);
Dashboard.alert({
message: Globalize.translate('TryDragAndDropMessage'),
title: Globalize.translate('HeaderTryDragAndDrop')
});
}
2016-06-01 23:08:47 -07:00
function init(page, item) {
var elem = page.querySelector('#childrenContent .itemsContainer');
elem.addEventListener('removefromplaylist', function (e) {
var playlistItemId = e.detail.playlistItemId;
removeFromPlaylist(page, item, [playlistItemId]);
});
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);
2015-10-16 10:10:48 -07:00
showDragAndDropHelp();
}
2015-08-19 21:06:49 -07:00
};
2016-03-07 12:13:58 -07:00
});