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

234 lines
6.7 KiB
JavaScript
Raw Normal View History

(function ($, document) {
var view = LibraryBrowser.getDefaultItemsView('List', 'List');
2014-08-04 20:41:56 -07:00
var currentItem;
// The base query options
var query = {
2015-02-11 20:54:31 -07:00
Fields: "PrimaryImageAspectRatio,SyncInfo",
2014-11-30 12:01:33 -07:00
StartIndex: 0,
ImageTypeLimit: 1,
2014-12-01 05:43:34 -07:00
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
};
function getSavedQueryKey() {
return 'playlists' + (query.ParentId || '');
}
2015-02-04 22:29:37 -07:00
function getItemsFunction(itemsQuery) {
itemsQuery = $.extend({}, itemsQuery);
2015-02-11 20:54:31 -07:00
itemsQuery.SortBy = null;
itemsQuery.SortOrder = null;
2015-02-04 22:29:37 -07:00
return function (index, limit, fields) {
itemsQuery.StartIndex = index;
itemsQuery.Limit = limit;
itemsQuery.Fields = fields;
return ApiClient.getItems(Dashboard.getCurrentUserId(), itemsQuery);
};
}
var _childrenItemsFunction = null;
function reloadItems(page) {
Dashboard.showLoadingMsg();
query.ParentId = getParameterByName('id');
2015-03-22 14:14:50 -07:00
query.UserId = Dashboard.getCurrentUserId();
2015-03-22 14:14:50 -07:00
var promise1 = ApiClient.getJSON(ApiClient.getUrl('Playlists/' + query.ParentId + '/Items', query));
var promise2 = Dashboard.getCurrentUser();
var promise3 = ApiClient.getItem(Dashboard.getCurrentUserId(), query.ParentId);
$.when(promise1, promise2, promise3).done(function (response1, response2, response3) {
var result = response1[0];
var user = response2[0];
var item = response3[0];
2015-04-05 08:01:57 -07:00
$('.playlistName', page).html(item.Name);
2015-02-04 22:29:37 -07:00
_childrenItemsFunction = getItemsFunction(query);
2014-08-04 20:41:56 -07:00
currentItem = item;
if (MediaController.canPlay(item)) {
$('.btnPlay', page).removeClass('hide');
}
else {
$('.btnPlay', page).addClass('hide');
}
if (item.LocalTrailerCount && item.PlayAccess == 'Full') {
$('.btnPlayTrailer', page).removeClass('hide');
} else {
$('.btnPlayTrailer', page).addClass('hide');
}
// Scroll back up so they can see the results from the beginning
$(document).scrollTop(0);
var html = '';
2015-01-22 23:15:15 -07:00
$('.listTopPaging', page).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-01-22 23:15:15 -07:00
})).trigger('create');
updateFilterControls(page);
if (result.TotalRecordCount) {
if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
context: 'playlists',
sortBy: query.SortBy,
showIndex: false,
2014-08-05 21:18:13 -07:00
title: item.Name,
2014-08-15 09:35:41 -07:00
showRemoveFromPlaylist: true,
2014-08-30 07:26:29 -07:00
playFromHere: true,
2015-06-07 14:21:30 -07:00
defaultAction: 'playallfromhere',
smallIcon: true
});
}
$('.noItemsMessage', page).hide();
} else {
$('.noItemsMessage', page).show();
}
2015-03-22 14:14:50 -07:00
$('.itemsContainer', page).html(html).trigger('create').lazyChildren();
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
Dashboard.hideLoadingMsg();
});
}
2014-08-11 16:41:11 -07:00
function removeFromPlaylist(page, ids) {
ApiClient.ajax({
url: ApiClient.getUrl('Playlists/' + currentItem.Id + '/Items', {
EntryIds: ids.join(',')
}),
type: 'DELETE'
}).done(function () {
reloadItems(page);
});
}
function updateFilterControls(page) {
// Reset form values using the last used query
$('.radioSortBy', page).each(function () {
this.checked = (query.SortBy || '').toLowerCase() == this.getAttribute('data-sortby').toLowerCase();
}).checkboxradio('refresh');
$('.radioSortOrder', page).each(function () {
this.checked = (query.SortOrder || '').toLowerCase() == this.getAttribute('data-sortorder').toLowerCase();
}).checkboxradio('refresh');
$('.chkStandardFilter', page).each(function () {
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
}).checkboxradio('refresh');
$('#selectView', page).val(view).selectmenu('refresh');
}
2015-06-08 14:32:20 -07:00
$(document).on('pageinitdepends', "#playlistEditorPage", function () {
var page = this;
2014-08-04 20:41:56 -07:00
$('.btnPlay', page).on('click', function () {
var userdata = currentItem.UserData || {};
var mediaType = currentItem.MediaType;
if (currentItem.Type == "MusicArtist" || currentItem.Type == "MusicAlbum") {
mediaType = "Audio";
}
2015-06-19 15:01:47 -07:00
LibraryBrowser.showPlayMenu(null, currentItem.Id, currentItem.Type, currentItem.IsFolder, mediaType, userdata.PlaybackPositionTicks);
2014-08-04 20:41:56 -07:00
});
2014-08-05 21:18:13 -07:00
$('.itemsContainer', page).on('needsrefresh', function () {
reloadItems(page);
2014-08-11 16:41:11 -07:00
}).on('removefromplaylist', function (e, playlistItemId) {
removeFromPlaylist(page, [playlistItemId]);
2014-08-21 08:55:35 -07:00
}).on('playallfromhere', function (e, index) {
2015-02-04 22:29:37 -07:00
LibraryBrowser.playAllFromHere(_childrenItemsFunction, index);
2014-08-21 08:55:35 -07:00
}).on('queueallfromhere', function (e, index) {
2015-02-04 22:29:37 -07:00
LibraryBrowser.queueAllFromHere(_childrenItemsFunction, index);
2014-08-21 08:55:35 -07:00
2014-08-05 21:18:13 -07:00
});
2015-06-18 21:23:55 -07:00
}).on('pagebeforeshowready', "#playlistEditorPage", function () {
var page = this;
query.ParentId = LibraryMenu.getTopParentId();
var limit = LibraryBrowser.getDefaultPageSize();
// If the default page size has changed, the start index will have to be reset
if (limit != query.Limit) {
query.Limit = limit;
query.StartIndex = 0;
}
var viewkey = getSavedQueryKey();
LibraryBrowser.loadSavedQueryValues(viewkey, query);
reloadItems(page);
updateFilterControls(this);
});
})(jQuery, document);