rework collection editor
This commit is contained in:
parent
39d4daa2fb
commit
0e1c7cbb7a
21 changed files with 436 additions and 402 deletions
|
@ -214,7 +214,7 @@
|
|||
|
||||
var invalidTypes = ['Person', 'Genre', 'MusicGenre', 'Studio', 'GameGenre', 'BoxSet', 'Playlist', 'UserView', 'CollectionFolder', 'Audio', 'Episode'];
|
||||
|
||||
return item.LocationType == 'FileSystem' && !item.CollectionType && invalidTypes.indexOf(item.Type) == -1 && item.MediaType != 'Photo';
|
||||
return !item.CollectionType && invalidTypes.indexOf(item.Type) == -1 && item.MediaType != 'Photo';
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,267 +0,0 @@
|
|||
(function ($, document, window, FileReader, escape) {
|
||||
|
||||
var currentItem;
|
||||
|
||||
function reload(page) {
|
||||
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
$('#btnRemoveItems', page).buttonEnabled(false);
|
||||
|
||||
MetadataEditor.getItemPromise().done(function (item) {
|
||||
|
||||
currentItem = item;
|
||||
|
||||
LibraryBrowser.renderName(item, $('.itemName', page), true);
|
||||
|
||||
reloadTitles(page, item);
|
||||
});
|
||||
}
|
||||
|
||||
function getTitleHtml(item) {
|
||||
|
||||
var html = '<div style="display:inline-block;margin:5px;vertical-align:top;">';
|
||||
|
||||
html += '<div style="width:120px;height:180px;">';
|
||||
if (item.ImageTags.Primary) {
|
||||
|
||||
var imgUrl = ApiClient.getScaledImageUrl(item.Id, {
|
||||
type: "Primary",
|
||||
maxWidth: 120,
|
||||
maxHeight: 180,
|
||||
tag: item.ImageTags.Primary
|
||||
});
|
||||
|
||||
html += '<img src="' + imgUrl + '" style="max-width:120px;max-height:180px;" />';
|
||||
|
||||
}
|
||||
html += '</div>';
|
||||
|
||||
html += '<div style="text-align:center;margin-top:4px;max-width:100px;overflow:hidden;height: 32px;">' + item.Name + '</div>';
|
||||
|
||||
if (item.ParentId != currentItem.Id) {
|
||||
html += '<label for="chkRemove' + item.Id + '">' + Globalize.translate("ButtonRemove") + '</label><input id="chkRemove' + item.Id + '" class="chkRemoveItem" type="checkbox" data-itemid="' + item.Id + '" data-mini="true" />';
|
||||
}
|
||||
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function getSearchResultHtml(item) {
|
||||
|
||||
var html = '<div style="display:inline-block;margin:3px;vertical-align:top;">';
|
||||
|
||||
html += '<div style="width:100px;height:150px;">';
|
||||
|
||||
if (item.PrimaryImageTag) {
|
||||
|
||||
var imgUrl = ApiClient.getScaledImageUrl(item.ItemId, {
|
||||
type: "Primary",
|
||||
maxWidth: 100,
|
||||
maxHeight: 150,
|
||||
tag: item.PrimaryImageTag
|
||||
});
|
||||
|
||||
html += '<img src="' + imgUrl + '" style="max-width:100px;max-height:150px;" />';
|
||||
|
||||
}
|
||||
html += '</div>';
|
||||
|
||||
html += '<div style="text-align:center;margin-top:4px;max-width:100px;overflow:hidden;height: 32px;">' + item.Name + '</div>';
|
||||
|
||||
html += '<label for="chkAdd' + item.ItemId + '">' + Globalize.translate("ButtonAdd") + '</label><input id="chkAdd' + item.ItemId + '" class="chkAddItem" type="checkbox" data-itemid="' + item.ItemId + '" data-mini="true" />';
|
||||
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function reloadTitles(page, item) {
|
||||
|
||||
ApiClient.getItems(Dashboard.getCurrentUserId(), {
|
||||
|
||||
ParentId: item.Id
|
||||
|
||||
}).done(function (result) {
|
||||
|
||||
// Scroll back up so they can see the results from the beginning
|
||||
window.scrollTo(0, 0);
|
||||
|
||||
var html = result.Items.map(getTitleHtml).join('');
|
||||
|
||||
var elem = $('.collectionItems', page).html(html).trigger('create');
|
||||
|
||||
$('.chkRemoveItem', elem).on('change', function () {
|
||||
|
||||
if ($('.chkRemoveItem:checked', elem).length) {
|
||||
$('#btnRemoveItems', page).buttonEnabled(true);
|
||||
} else {
|
||||
$('#btnRemoveItems', page).buttonEnabled(false);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Dashboard.hideLoadingMsg();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function showSearchResults(page, searchTerm) {
|
||||
|
||||
ApiClient.getSearchHints({
|
||||
|
||||
userId: Dashboard.getCurrentUserId(),
|
||||
searchTerm: searchTerm,
|
||||
limit: 30,
|
||||
|
||||
includePeople: false,
|
||||
includeGenres: false,
|
||||
includeStudios: false,
|
||||
includeArtists: false,
|
||||
|
||||
IncludeItemTypes: "Movie,Series,Game,MusicAlbum,Book"
|
||||
|
||||
}).done(function (result) {
|
||||
|
||||
renderSearchResults(page, result.SearchHints);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function renderSearchResults(page, items) {
|
||||
|
||||
var existingIds = $('.chkRemoveItem', page).get().map(function (c) {
|
||||
return c.getAttribute('data-itemid');
|
||||
});
|
||||
|
||||
var html = items.filter(function (i) {
|
||||
|
||||
return existingIds.indexOf(i.ItemId) == -1;
|
||||
|
||||
}).map(getSearchResultHtml).join('');
|
||||
|
||||
var elem = $('.collectionItemSearchResults', page).html(html).trigger('create');
|
||||
|
||||
$('.chkAddItem', elem).on('change', function () {
|
||||
|
||||
if ($('.chkAddItem:checked', elem).length) {
|
||||
$('#btnAddItems', page).buttonEnabled(true);
|
||||
} else {
|
||||
$('#btnAddItems', page).buttonEnabled(false);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function addItemsToCollection(page) {
|
||||
|
||||
var items = $('.chkAddItem:checked', page).get().map(function (c) {
|
||||
|
||||
return c.getAttribute('data-itemid');
|
||||
|
||||
});
|
||||
|
||||
if (!items.length) {
|
||||
Dashboard.alert(Globalize.translate("MessagePleaseSelectOneItem"));
|
||||
return;
|
||||
}
|
||||
|
||||
var url = ApiClient.getUrl("Collections/" + currentItem.Id + "/Items", {
|
||||
|
||||
Ids: items.join(',')
|
||||
|
||||
});
|
||||
|
||||
ApiClient.ajax({
|
||||
type: "POST",
|
||||
url: url
|
||||
|
||||
}).done(function () {
|
||||
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
||||
$('.popupIdentifyCollection', page).popup('close');
|
||||
|
||||
reload(page);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function removeItemsFromCollection(page) {
|
||||
var items = $('.chkRemoveItem:checked', page).get().map(function (c) {
|
||||
|
||||
return c.getAttribute('data-itemid');
|
||||
|
||||
});
|
||||
|
||||
if (!items.length) {
|
||||
Dashboard.alert(Globalize.translate("MessagePleaseSelectOneItem"));
|
||||
return;
|
||||
}
|
||||
|
||||
var url = ApiClient.getUrl("Collections/" + currentItem.Id + "/Items", {
|
||||
|
||||
Ids: items.join(',')
|
||||
|
||||
});
|
||||
|
||||
ApiClient.ajax({
|
||||
type: "DELETE",
|
||||
url: url
|
||||
|
||||
}).done(function () {
|
||||
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
||||
reload(page);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function onSearchFormSubmit() {
|
||||
var page = $(this).parents('.page');
|
||||
|
||||
showSearchResults(page, $('#txtLookupName', this).val());
|
||||
return false;
|
||||
}
|
||||
|
||||
$(document).on('pageinit', "#editItemMetadataPage", function () {
|
||||
|
||||
var page = this;
|
||||
|
||||
$('#btnAddItem', page).on('click', function () {
|
||||
|
||||
|
||||
var popup = $('.popupIdentifyCollection', page).popup('open');
|
||||
|
||||
$('#txtLookupName', popup).val('');
|
||||
$('.collectionItemSearchResults', popup).empty();
|
||||
$('#btnAddItems', popup).buttonEnabled(false);
|
||||
});
|
||||
|
||||
$('#btnAddItems', page).on('click', function () {
|
||||
|
||||
addItemsToCollection(page);
|
||||
});
|
||||
|
||||
$('#btnRemoveItems', page).on('click', function () {
|
||||
|
||||
|
||||
removeItemsFromCollection(page);
|
||||
});
|
||||
|
||||
$('.collectionItemSearchForm').off('submit', onSearchFormSubmit).on('submit', onSearchFormSubmit);
|
||||
|
||||
$(page.querySelector('paper-tabs')).on('tabchange', function () {
|
||||
|
||||
if (parseInt(this.selected) == 2) {
|
||||
var tabContent = page.querySelector('.collectionItemsTabContent');
|
||||
|
||||
reload(tabContent);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
})(jQuery, document, window, window.FileReader, escape);
|
|
@ -566,7 +566,7 @@
|
|||
|
||||
$(page.querySelector('paper-tabs')).on('tabchange', function () {
|
||||
|
||||
if (parseInt(this.selected) == 3) {
|
||||
if (parseInt(this.selected) == 2) {
|
||||
var tabContent = page.querySelector('.imageEditorTab');
|
||||
|
||||
reload(tabContent);
|
||||
|
|
|
@ -46,12 +46,6 @@
|
|||
setFieldVisibilities(page, item);
|
||||
fillItemInfo(page, item, metadataEditorInfo.ParentalRatingOptions);
|
||||
|
||||
if (item.Type == "BoxSet") {
|
||||
page.querySelector('.collectionItemsTabButton').classList.remove('hide');
|
||||
} else {
|
||||
page.querySelector('.collectionItemsTabButton').classList.add('hide');
|
||||
}
|
||||
|
||||
if (item.MediaType == "Video" && item.LocationType == "FileSystem" && item.Type !== 'TvChannel') {
|
||||
page.querySelector('.subtitleTabButton').classList.remove('hide');
|
||||
} else {
|
||||
|
|
|
@ -90,7 +90,6 @@ if (!Array.prototype.filter) {
|
|||
};
|
||||
}
|
||||
|
||||
// TODO: There should be notification services, where each defines what it supports and the best service is chosen based on params
|
||||
var WebNotifications = {
|
||||
|
||||
show: function (data) {
|
||||
|
|
|
@ -893,7 +893,7 @@
|
|||
{ name: Globalize.translate('HeaderBooks'), type: 'Book' }
|
||||
];
|
||||
|
||||
renderCollectionItems(page, collectionItemTypes, result.Items, user, context);
|
||||
renderCollectionItems(page, item, collectionItemTypes, result.Items, user, context);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -947,7 +947,10 @@
|
|||
});
|
||||
}
|
||||
|
||||
function renderCollectionItems(page, types, items, user) {
|
||||
function renderCollectionItems(page, parentItem, types, items, user) {
|
||||
|
||||
// First empty out existing content
|
||||
page.querySelector('.collectionItems').innerHTML = '';
|
||||
|
||||
for (var i = 0, length = types.length; i < length; i++) {
|
||||
|
||||
|
@ -960,7 +963,7 @@
|
|||
});
|
||||
|
||||
if (typeItems.length) {
|
||||
renderCollectionItemType(page, type, typeItems, user);
|
||||
renderCollectionItemType(page, parentItem, type, typeItems, user);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -977,17 +980,17 @@
|
|||
});
|
||||
|
||||
if (otherTypeItems.length) {
|
||||
renderCollectionItemType(page, otherType, otherTypeItems, user);
|
||||
renderCollectionItemType(page, parentItem, otherType, otherTypeItems, user);
|
||||
}
|
||||
|
||||
if (!items.length) {
|
||||
renderCollectionItemType(page, { name: Globalize.translate('HeaderItems') }, items, user);
|
||||
renderCollectionItemType(page, parentItem, { name: Globalize.translate('HeaderItems') }, items, user);
|
||||
}
|
||||
|
||||
$('.collectionItems', page).createCardMenus();
|
||||
}
|
||||
|
||||
function renderCollectionItemType(page, type, items, user, context) {
|
||||
function renderCollectionItemType(page, parentItem, type, items, user, context) {
|
||||
|
||||
var html = '';
|
||||
|
||||
|
@ -996,10 +999,6 @@
|
|||
html += '<h1>';
|
||||
html += '<span>' + type.name + '</span>';
|
||||
|
||||
if (user.Policy.IsAdministrator) {
|
||||
html += '<a class="detailSectionHeaderButton clearLink" style="margin-top:-8px;display:inline-block;" href="edititemmetadata.html?tab=2&id=' + currentItem.Id + '" title="' + Globalize.translate('ButtonEdit') + '" style="display:none;"><paper-icon-button icon="mode-edit"></paper-icon-button></a>';
|
||||
}
|
||||
|
||||
html += '</h1>';
|
||||
|
||||
html += '<div class="detailSectionContent">';
|
||||
|
@ -1013,7 +1012,10 @@
|
|||
centerText: true,
|
||||
context: context,
|
||||
lazy: true,
|
||||
showDetailsMenu: true
|
||||
showDetailsMenu: true,
|
||||
overlayMoreButton: true,
|
||||
showAddToCollection: false,
|
||||
showRemoveFromCollection: true
|
||||
});
|
||||
html += '</div>';
|
||||
|
||||
|
@ -1022,6 +1024,31 @@
|
|||
var collectionItems = page.querySelector('.collectionItems');
|
||||
$(collectionItems).append(html);
|
||||
ImageLoader.lazyChildren(collectionItems);
|
||||
|
||||
$(collectionItems).off('removefromcollection').on('removefromcollection', function (e, itemId) {
|
||||
|
||||
removeFromCollection(page, parentItem, [itemId], user, context);
|
||||
});
|
||||
}
|
||||
|
||||
function removeFromCollection(page, parentItem, itemIds, user, context) {
|
||||
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
var url = ApiClient.getUrl("Collections/" + parentItem.Id + "/Items", {
|
||||
|
||||
Ids: itemIds.join(',')
|
||||
});
|
||||
|
||||
ApiClient.ajax({
|
||||
type: "DELETE",
|
||||
url: url
|
||||
|
||||
}).done(function () {
|
||||
|
||||
renderChildren(page, parentItem, user, context);
|
||||
Dashboard.hideLoadingMsg();
|
||||
});
|
||||
}
|
||||
|
||||
function renderUserDataIcons(page, item) {
|
||||
|
|
|
@ -1375,8 +1375,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (BoxSetEditor.supportsAddingToCollection(item)) {
|
||||
itemCommands.push('addtocollection');
|
||||
if (options.showAddToCollection !== false) {
|
||||
if (BoxSetEditor.supportsAddingToCollection(item)) {
|
||||
itemCommands.push('addtocollection');
|
||||
}
|
||||
}
|
||||
|
||||
if (options.showRemoveFromCollection) {
|
||||
itemCommands.push('removefromcollection');
|
||||
}
|
||||
|
||||
if (options.playFromHere) {
|
||||
|
|
|
@ -327,6 +327,14 @@
|
|||
});
|
||||
}
|
||||
|
||||
if (commands.indexOf('removefromcollection') != -1) {
|
||||
items.push({
|
||||
name: Globalize.translate('ButtonRemoveFromCollection'),
|
||||
id: 'removefromcollection',
|
||||
ironIcon: 'remove'
|
||||
});
|
||||
}
|
||||
|
||||
if (commands.indexOf('removefromplaylist') != -1) {
|
||||
items.push({
|
||||
name: Globalize.translate('ButtonRemoveFromPlaylist'),
|
||||
|
@ -476,6 +484,9 @@
|
|||
case 'removefromplaylist':
|
||||
$(card).parents('.itemsContainer').trigger('removefromplaylist', [playlistItemId]);
|
||||
break;
|
||||
case 'removefromcollection':
|
||||
$(card).parents('.collectionItems').trigger('removefromcollection', [itemId]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -860,7 +860,6 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
// TODO: Need to verify the host is going to be reachable
|
||||
return mediaSource.Path.toLowerCase().replace('https:', 'http').indexOf(ApiClient.serverAddress().toLowerCase().replace('https:', 'http').substring(0, 14)) == 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
}
|
||||
})();
|
||||
|
||||
// TODO: Deprecated in 1.9
|
||||
$.support.cors = true;
|
||||
|
||||
$(document).one('click', WebNotifications.requestPermission);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue