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

524 lines
16 KiB
JavaScript
Raw Normal View History

2013-04-03 21:21:46 -07:00
(function ($, document) {
2015-05-26 08:31:50 -07:00
var view = LibraryBrowser.getDefaultItemsView('Poster', 'Poster');
2013-04-29 19:00:42 -07:00
// The base query options
var query = {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "BoxSet",
Recursive: true,
2015-02-05 22:39:07 -07:00
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo,CanDelete",
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"
2013-04-29 19:00:42 -07:00
};
2013-04-03 21:21:46 -07:00
2014-05-06 19:28:19 -07:00
function getSavedQueryKey() {
return 'collections' + (query.ParentId || '');
}
2013-04-29 19:00:42 -07:00
function reloadItems(page) {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
Dashboard.showLoadingMsg();
2013-04-03 21:21:46 -07:00
2014-07-19 21:46:29 -07:00
var promise1 = ApiClient.getItems(Dashboard.getCurrentUserId(), query);
var promise2 = Dashboard.getCurrentUser();
$.when(promise1, promise2).done(function (response1, response2) {
var result = response1[0];
var user = response2[0];
2013-04-03 21:21:46 -07:00
2013-05-17 12:18:54 -07:00
// Scroll back up so they can see the results from the beginning
$(document).scrollTop(0);
2013-04-29 19:00:42 -07:00
var html = '';
2013-04-03 21:21:46 -07:00
2014-12-19 23:06:27 -07:00
var addiontalButtonsHtml = user.Policy.IsAdministrator ?
2014-07-19 21:46:29 -07:00
('<button class="btnNewCollection" data-mini="true" data-icon="plus" data-inline="true" data-iconpos="notext">' + Globalize.translate('ButtonNew') + '</button>') :
'';
2015-01-22 23:15:15 -07:00
$('.listTopPaging', page).html(LibraryBrowser.getQueryPagingHtml({
2014-07-19 21:46:29 -07:00
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
viewButton: true,
showLimit: false,
additionalButtonsHtml: addiontalButtonsHtml
2015-01-22 23:15:15 -07:00
})).trigger('create');
2013-04-03 21:21:46 -07:00
2013-10-18 09:09:47 -07:00
updateFilterControls(page);
2015-01-22 23:15:15 -07:00
var trigger = false;
2013-10-18 09:09:47 -07:00
if (result.TotalRecordCount) {
2014-05-31 07:30:59 -07:00
if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
context: 'movies',
sortBy: query.SortBy
});
2015-01-22 23:15:15 -07:00
trigger = true;
}
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
2015-01-22 23:15:15 -07:00
shape: "auto",
context: 'movies',
2015-01-22 23:15:15 -07:00
showTitle: true,
centerText: true,
lazy: true
});
}
2015-05-12 21:55:19 -07:00
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "auto",
context: 'movies',
showTitle: true,
cardLayout: true,
lazy: true,
showItemCounts: true
});
}
2015-04-02 14:01:42 -07:00
else if (view == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
context: 'movies',
showTitle: true,
centerText: true,
lazy: true,
preferThumb: true
});
}
2015-05-12 21:55:19 -07:00
else if (view == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
context: 'movies',
showTitle: true,
lazy: true,
preferThumb: true,
cardLayout: true,
showItemCounts: true
});
}
2014-05-31 07:30:59 -07:00
2014-05-30 12:23:56 -07:00
$('.noItemsMessage', page).hide();
2014-07-19 21:46:29 -07:00
} else {
2014-05-31 07:30:59 -07:00
2014-05-30 12:23:56 -07:00
$('.noItemsMessage', page).show();
}
2013-04-11 08:43:57 -07:00
2015-01-22 23:15:15 -07:00
$('.itemsContainer', page).html(html).lazyChildren();
if (trigger) {
$('.itemsContainer', page).trigger('create');
}
2013-04-11 08:43:57 -07:00
2013-04-29 19:00:42 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
2013-04-15 15:03:05 -07:00
2013-04-29 19:00:42 -07:00
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
2013-04-15 15:03:05 -07:00
2014-05-06 19:28:19 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2013-10-18 09:09:47 -07:00
2013-04-29 19:00:42 -07:00
Dashboard.hideLoadingMsg();
});
}
2013-04-03 21:21:46 -07:00
2013-10-18 09:09:47 -07:00
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');
2013-10-18 09:09:47 -07:00
$('#chkTrailer', page).checked(query.HasTrailer == true).checkboxradio('refresh');
$('#chkThemeSong', page).checked(query.HasThemeSong == true).checkboxradio('refresh');
$('#chkThemeVideo', page).checked(query.HasThemeVideo == true).checkboxradio('refresh');
$('.alphabetPicker', page).alphaValue(query.NameStartsWithOrGreater);
2014-07-19 21:46:29 -07:00
$('#selectPageSize', page).val(query.Limit).selectmenu('refresh');
2013-10-18 09:09:47 -07:00
}
2015-05-19 12:15:40 -07:00
$(document).on('pageinitdepends', "#boxsetsPage", function () {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
var page = this;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('.radioSortBy', this).on('click', function () {
query.SortBy = this.getAttribute('data-sortby');
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('.radioSortOrder', this).on('click', function () {
query.SortOrder = this.getAttribute('data-sortorder');
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('.chkStandardFilter', this).on('change', function () {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.Filters || "";
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
filters = (',' + filters).replace(',' + filterName, '').substring(1);
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
query.StartIndex = 0;
query.Filters = filters;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('#chkTrailer', this).on('change', function () {
2013-04-29 19:00:42 -07:00
query.StartIndex = 0;
query.HasTrailer = this.checked ? true : null;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('#chkThemeSong', this).on('change', function () {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
query.StartIndex = 0;
query.HasThemeSong = this.checked ? true : null;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
$('#chkThemeVideo', this).on('change', function () {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
query.StartIndex = 0;
query.HasThemeVideo = this.checked ? true : null;
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
reloadItems(page);
});
2013-04-03 21:21:46 -07:00
$('.alphabetPicker', this).on('alphaselect', function (e, character) {
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = character;
2013-05-17 11:05:49 -07:00
query.StartIndex = 0;
reloadItems(page);
}).on('alphaclear', function (e) {
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = '';
reloadItems(page);
});
$('#selectView', this).on('change', function () {
view = this.value;
reloadItems(page);
LibraryBrowser.saveViewSetting(getSavedQueryKey(), view);
});
2014-07-19 21:46:29 -07:00
$('#selectPageSize', page).on('change', function () {
query.Limit = parseInt(this.value);
query.StartIndex = 0;
reloadItems(page);
});
2015-06-07 12:13:28 -07:00
}).on('pageshowready', "#boxsetsPage", function () {
2013-04-03 21:21:46 -07:00
var page = this;
2014-07-19 21:46:29 -07:00
var context = getParameterByName('context');
if (context == 'movies') {
$('.collectionTabs', page).hide();
$('.movieTabs', page).show();
2015-01-24 15:33:26 -07:00
// TODO: Improve in the future to limit scope
query.ParentId = null;
} else {
$('.collectionTabs', page).show();
$('.movieTabs', page).hide();
2015-01-24 15:33:26 -07:00
query.ParentId = LibraryMenu.getTopParentId();
2015-06-07 12:13:28 -07:00
// Doing this for now due to reports of the page being empty for AutoBoxSet users
query.ParentId = null;
}
2013-05-15 12:40:47 -07:00
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);
LibraryBrowser.getSavedViewSetting(viewkey).done(function (val) {
if (val) {
$('#selectView', page).val(val).selectmenu('refresh').trigger('change');
} else {
reloadItems(page);
}
});
2013-04-03 21:21:46 -07:00
2013-10-18 09:09:47 -07:00
updateFilterControls(this);
2014-05-31 07:30:59 -07:00
});
})(jQuery, document);
(function ($, document) {
2015-01-23 21:50:45 -07:00
function getNewCollectionPanel(createIfNeeded) {
2014-05-31 07:30:59 -07:00
2015-01-23 21:50:45 -07:00
var panel = $('.newCollectionPanel');
2014-05-31 07:30:59 -07:00
2015-01-23 21:50:45 -07:00
if (createIfNeeded && !panel.length) {
2014-06-03 20:34:36 -07:00
2015-01-23 21:50:45 -07:00
var html = '';
html += '<div>';
html += '<div data-role="panel" class="newCollectionPanel" data-position="right" data-display="overlay" data-position-fixed="true" data-theme="a">';
html += '<form class="newCollectionForm">';
html += '<h3>' + Globalize.translate('HeaderAddToCollection') + '</h3>';
html += '<div class="fldSelectCollection">';
html += '<br />';
html += '<label for="selectCollectionToAddTo">' + Globalize.translate('LabelSelectCollection') + '</label>';
html += '<select id="selectCollectionToAddTo" data-mini="true"></select>';
html += '</div>';
html += '<div class="newCollectionInfo">';
html += '<br />';
html += '<div>';
html += '<label for="txtNewCollectionName">' + Globalize.translate('LabelName') + '</label>';
html += '<input type="text" id="txtNewCollectionName" required="required" />';
html += '<div class="fieldDescription">' + Globalize.translate('NewCollectionNameExample') + '</div>';
html += '</div>';
html += '<br />';
html += '<div>';
html += '<label for="chkEnableInternetMetadata">' + Globalize.translate('OptionSearchForInternetMetadata') + '</label>';
html += '<input type="checkbox" id="chkEnableInternetMetadata" data-mini="true" />';
html += '</div>';
// newCollectionInfo
html += '</div>';
html += '<br />';
html += '<p>';
html += '<input class="fldSelectedItemIds" type="hidden" />';
html += '<button type="submit" data-icon="plus" data-mini="true" data-theme="b">' + Globalize.translate('ButtonSubmit') + '</button>';
html += '</p>';
html += '</form>';
html += '</div>';
html += '</div>';
panel = $(html).appendTo(document.body).trigger('create').find('.newCollectionPanel');
$('#selectCollectionToAddTo', panel).on('change', function () {
if (this.value) {
$('.newCollectionInfo', panel).hide();
$('#txtNewCollectionName', panel).removeAttr('required');
} else {
$('.newCollectionInfo', panel).show();
$('#txtNewCollectionName', panel).attr('required', 'required');
}
});
$('.newCollectionForm', panel).off('submit', BoxSetEditor.onNewCollectionSubmit).on('submit', BoxSetEditor.onNewCollectionSubmit);
}
return panel;
2014-06-03 20:34:36 -07:00
}
2015-01-23 21:50:45 -07:00
function showCollectionPanel(items) {
2014-06-03 20:34:36 -07:00
2015-01-23 21:50:45 -07:00
var panel = getNewCollectionPanel(true).panel('toggle');
2014-06-03 20:34:36 -07:00
2015-01-23 21:50:45 -07:00
$('.fldSelectedItemIds', panel).val(items.join(','));
2014-06-03 20:34:36 -07:00
2015-01-23 21:50:45 -07:00
if (items.length) {
$('.fldSelectCollection', panel).show();
populateCollections(panel);
} else {
$('.fldSelectCollection', panel).hide();
$('#selectCollectionToAddTo', panel).html('').val('').selectmenu('refresh').trigger('change');
2014-06-03 20:34:36 -07:00
}
2015-01-23 21:50:45 -07:00
}
function populateCollections(panel) {
var select = $('#selectCollectionToAddTo', panel);
2014-06-03 20:34:36 -07:00
$('.newCollectionInfo', panel).hide();
var options = {
Recursive: true,
2015-05-15 08:46:20 -07:00
IncludeItemTypes: "BoxSet",
SortBy: "SortName"
2014-06-03 20:34:36 -07:00
};
ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) {
var html = '';
html += '<option value="">' + Globalize.translate('OptionNewCollection') + '</option>';
html += result.Items.map(function (i) {
return '<option value="' + i.Id + '">' + i.Name + '</option>';
});
select.html(html).val('').selectmenu('refresh').trigger('change');
});
2014-05-31 07:30:59 -07:00
}
2015-05-19 12:15:40 -07:00
$(document).on('pageinitdepends', ".collectionEditorPage", function () {
2014-05-31 07:30:59 -07:00
var page = this;
2015-01-22 23:15:15 -07:00
// The button is created dynamically
$(page).on('click', '.btnNewCollection', function () {
2014-05-31 07:30:59 -07:00
2015-04-25 21:39:40 -07:00
showCollectionPanel([]);
2014-05-31 07:30:59 -07:00
});
2013-04-29 19:00:42 -07:00
});
2013-04-03 21:21:46 -07:00
function redirectToCollection(id) {
var context = getParameterByName('context');
ApiClient.getItem(Dashboard.getCurrentUserId(), id).done(function (item) {
Dashboard.navigate(LibraryBrowser.getHref(item, context));
});
}
2015-01-23 21:50:45 -07:00
function createCollection(panel) {
2014-06-03 20:34:36 -07:00
var url = ApiClient.getUrl("Collections", {
2015-01-23 21:50:45 -07:00
Name: $('#txtNewCollectionName', panel).val(),
IsLocked: !$('#chkEnableInternetMetadata', panel).checked(),
Ids: $('.fldSelectedItemIds', panel).val() || ''
2014-06-03 20:34:36 -07:00
//ParentId: getParameterByName('parentId') || LibraryMenu.getTopParentId()
});
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-06-03 20:34:36 -07:00
type: "POST",
url: url,
dataType: "json"
2014-05-31 07:30:59 -07:00
2014-06-03 20:34:36 -07:00
}).done(function (result) {
2014-05-31 07:30:59 -07:00
2014-06-03 20:34:36 -07:00
Dashboard.hideLoadingMsg();
2014-06-03 20:34:36 -07:00
var id = result.Id;
2015-01-23 21:50:45 -07:00
panel.panel('toggle');
redirectToCollection(id);
2014-06-03 20:34:36 -07:00
});
}
2015-01-23 21:50:45 -07:00
function addToCollection(panel, id) {
2014-06-03 20:34:36 -07:00
var url = ApiClient.getUrl("Collections/" + id + "/Items", {
2015-01-23 21:50:45 -07:00
Ids: $('.fldSelectedItemIds', panel).val() || ''
2014-06-03 20:34:36 -07:00
});
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-06-03 20:34:36 -07:00
type: "POST",
url: url
}).done(function () {
Dashboard.hideLoadingMsg();
2015-01-23 21:50:45 -07:00
panel.panel('toggle');
2014-06-03 20:34:36 -07:00
2015-01-23 21:50:45 -07:00
Dashboard.alert(Globalize.translate('MessageItemsAdded'));
2014-06-03 20:34:36 -07:00
});
}
window.BoxSetEditor = {
2015-01-23 21:50:45 -07:00
showPanel: function (items) {
showCollectionPanel(items);
2014-06-03 20:34:36 -07:00
},
onNewCollectionSubmit: function () {
Dashboard.showLoadingMsg();
2015-01-23 21:50:45 -07:00
var panel = getNewCollectionPanel(false);
2014-06-03 20:34:36 -07:00
2015-01-23 21:50:45 -07:00
var collectionId = $('#selectCollectionToAddTo', panel).val();
2014-06-03 20:34:36 -07:00
if (collectionId) {
2015-01-23 21:50:45 -07:00
addToCollection(panel, collectionId);
2014-06-03 20:34:36 -07:00
} else {
2015-01-23 21:50:45 -07:00
createCollection(panel);
2014-06-03 20:34:36 -07:00
}
2014-03-05 22:17:13 -07:00
return false;
2015-01-23 21:50:45 -07:00
},
supportsAddingToCollection: function (item) {
2015-01-31 13:28:18 -07:00
var invalidTypes = ['Person', 'Genre', 'MusicGenre', 'Studio', 'GameGenre', 'BoxSet', 'Playlist', 'UserView', 'CollectionFolder', 'Audio', 'Episode'];
2015-01-23 21:50:45 -07:00
2015-04-19 08:54:20 -07:00
return item.LocationType == 'FileSystem' && !item.CollectionType && invalidTypes.indexOf(item.Type) == -1 && item.MediaType != 'Photo';
2014-03-05 22:17:13 -07:00
}
};
2013-04-03 21:21:46 -07:00
})(jQuery, document);