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

483 lines
14 KiB
JavaScript
Raw Normal View History

2016-07-30 13:47:18 -07:00
define(['jQuery', 'apphost', 'cardStyle'], function ($, appHost) {
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
function changeCollectionType(page, virtualFolder) {
2013-12-01 13:17:40 -07:00
2016-02-26 13:29:27 -07:00
require(['alert'], function (alert) {
alert({
title: Globalize.translate('HeaderChangeFolderType'),
text: Globalize.translate('HeaderChangeFolderTypeHelp')
});
2013-12-26 19:23:57 -07:00
});
2015-10-15 10:21:18 -07:00
}
2013-12-01 13:17:40 -07:00
2015-10-15 11:48:43 -07:00
function addVirtualFolder(page) {
2013-07-12 12:56:40 -07:00
2015-10-15 19:06:44 -07:00
require(['medialibrarycreator'], function (medialibrarycreator) {
2013-02-20 18:33:05 -07:00
2015-10-15 19:06:44 -07:00
new medialibrarycreator().show({
2013-09-04 12:16:41 -07:00
2016-08-12 23:33:31 -07:00
collectionTypeOptions: getCollectionTypeOptions().filter(function (f) {
return !f.hidden;
}),
2015-10-26 11:12:20 -07:00
refresh: shouldRefreshLibraryAfterChanges(page)
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
}).then(function (hasChanges) {
2013-02-20 18:33:05 -07:00
2015-10-15 11:48:43 -07:00
if (hasChanges) {
reloadLibrary(page);
}
});
2013-02-20 18:33:05 -07:00
});
2015-10-15 10:21:18 -07:00
}
2013-02-20 18:33:05 -07:00
2015-10-15 20:17:42 -07:00
function editVirtualFolder(page, virtualFolder) {
require(['medialibraryeditor'], function (medialibraryeditor) {
new medialibraryeditor().show({
2015-10-26 11:12:20 -07:00
refresh: shouldRefreshLibraryAfterChanges(page),
2015-10-15 20:17:42 -07:00
library: virtualFolder
2015-12-14 08:43:03 -07:00
}).then(function (hasChanges) {
2015-10-15 20:17:42 -07:00
if (hasChanges) {
reloadLibrary(page);
}
});
});
}
2015-10-15 10:21:18 -07:00
function deleteVirtualFolder(page, virtualFolder) {
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
var msg = Globalize.translate('MessageAreYouSureYouWishToRemoveMediaFolder');
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
if (virtualFolder.Locations.length) {
msg += "<br/><br/>" + Globalize.translate("MessageTheFollowingLocationWillBeRemovedFromLibrary") + "<br/><br/>";
msg += virtualFolder.Locations.join("<br/>");
}
2013-02-20 18:33:05 -07:00
2016-02-22 12:12:06 -07:00
require(['confirm'], function (confirm) {
2013-02-20 18:33:05 -07:00
2016-02-22 12:12:06 -07:00
confirm(msg, Globalize.translate('HeaderRemoveMediaFolder')).then(function () {
2013-02-20 18:33:05 -07:00
2015-10-26 11:12:20 -07:00
var refreshAfterChange = shouldRefreshLibraryAfterChanges(page);
2013-09-05 10:05:39 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.removeVirtualFolder(virtualFolder.Name, refreshAfterChange).then(function () {
2015-10-26 11:12:20 -07:00
reloadLibrary(page);
});
2016-02-22 12:12:06 -07:00
});
2013-02-20 18:33:05 -07:00
});
2015-10-15 10:21:18 -07:00
}
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
function renameVirtualFolder(page, virtualFolder) {
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
require(['prompt'], function (prompt) {
2015-10-15 10:21:18 -07:00
prompt({
2016-02-15 07:41:07 -07:00
label: Globalize.translate('LabelNewName')
2016-02-15 07:41:07 -07:00
}).then(function (newName) {
if (newName && newName != virtualFolder.Name) {
2015-10-13 12:22:45 -07:00
2016-02-15 07:41:07 -07:00
var refreshAfterChange = shouldRefreshLibraryAfterChanges(page);
2015-10-15 10:21:18 -07:00
2016-02-15 07:41:07 -07:00
ApiClient.renameVirtualFolder(virtualFolder.Name, newName, refreshAfterChange).then(function () {
reloadLibrary(page);
});
2015-10-15 10:21:18 -07:00
}
2015-10-13 12:22:45 -07:00
});
});
2015-10-15 10:21:18 -07:00
}
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
function showCardMenu(page, elem, virtualFolders) {
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
var card = $(elem).parents('.card')[0];
var index = parseInt(card.getAttribute('data-index'));
var virtualFolder = virtualFolders[index];
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
var menuItems = [];
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
menuItems.push({
2015-10-15 12:04:51 -07:00
name: Globalize.translate('ButtonChangeContentType'),
2015-10-15 10:21:18 -07:00
id: 'changetype',
2015-10-15 22:36:16 -07:00
ironIcon: 'videocam'
2015-10-15 10:21:18 -07:00
});
2013-02-20 18:33:05 -07:00
2016-04-11 21:03:07 -07:00
menuItems.push({
name: Globalize.translate('ButtonEditImages'),
id: 'editimages',
ironIcon: 'photo'
});
2015-10-15 21:46:41 -07:00
menuItems.push({
2015-10-15 22:36:16 -07:00
name: Globalize.translate('ButtonManageFolders'),
2015-10-15 21:46:41 -07:00
id: 'edit',
2016-07-23 11:43:07 -07:00
ironIcon: 'folder_open'
2015-10-15 21:46:41 -07:00
});
2015-10-15 10:21:18 -07:00
menuItems.push({
name: Globalize.translate('ButtonRemove'),
id: 'delete',
ironIcon: 'remove'
});
2013-07-12 12:56:40 -07:00
2015-10-15 10:21:18 -07:00
menuItems.push({
name: Globalize.translate('ButtonRename'),
id: 'rename',
2016-07-23 11:43:07 -07:00
ironIcon: 'mode_edit'
2015-10-15 10:21:18 -07:00
});
2013-07-12 12:56:40 -07:00
2016-01-30 21:04:00 -07:00
require(['actionsheet'], function (actionsheet) {
2015-10-15 10:21:18 -07:00
2016-01-30 21:04:00 -07:00
actionsheet.show({
2015-10-15 10:21:18 -07:00
items: menuItems,
positionTo: elem,
callback: function (resultId) {
switch (resultId) {
case 'changetype':
changeCollectionType(page, virtualFolder);
break;
2015-10-15 21:46:41 -07:00
case 'edit':
editVirtualFolder(page, virtualFolder);
break;
2016-04-11 21:03:07 -07:00
case 'editimages':
editImages(page, virtualFolder);
break;
2015-10-15 10:21:18 -07:00
case 'rename':
renameVirtualFolder(page, virtualFolder);
break;
case 'delete':
deleteVirtualFolder(page, virtualFolder);
break;
default:
break;
}
}
});
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
});
}
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
function reloadLibrary(page) {
2013-07-12 12:56:40 -07:00
2015-10-15 10:21:18 -07:00
Dashboard.showLoadingMsg();
2015-12-14 08:43:03 -07:00
ApiClient.getVirtualFolders().then(function (result) {
2015-10-15 10:21:18 -07:00
reloadVirtualFolders(page, result);
});
}
2013-12-01 13:17:40 -07:00
2015-10-26 11:12:20 -07:00
function shouldRefreshLibraryAfterChanges(page) {
2015-10-26 11:12:20 -07:00
return $(page).is('#mediaLibraryPage');
2015-10-15 10:21:18 -07:00
}
2013-07-12 12:56:40 -07:00
2015-10-15 10:21:18 -07:00
function reloadVirtualFolders(page, virtualFolders) {
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
var html = '';
virtualFolders.push({
2015-10-15 10:37:27 -07:00
Name: Globalize.translate('ButtonAddMediaLibrary'),
2016-07-23 11:43:07 -07:00
icon: 'add_circle',
2015-10-15 10:21:18 -07:00
Locations: [],
showType: false,
showLocations: false,
showMenu: false,
2015-10-15 19:06:44 -07:00
showNameWithIcon: true
2013-02-20 18:33:05 -07:00
});
2015-10-15 10:21:18 -07:00
for (var i = 0, length = virtualFolders.length; i < length; i++) {
2013-07-12 12:56:40 -07:00
2015-10-15 10:21:18 -07:00
var virtualFolder = virtualFolders[i];
2015-10-26 11:12:20 -07:00
html += getVirtualFolderHtml(page, virtualFolder, i);
2015-10-15 10:21:18 -07:00
}
var divVirtualFolders = page.querySelector('#divVirtualFolders');
divVirtualFolders.innerHTML = html;
2016-07-30 13:47:18 -07:00
divVirtualFolders.classList.add('itemsContainer');
divVirtualFolders.classList.add('vertical-wrap');
2015-10-15 10:21:18 -07:00
$('.btnCardMenu', divVirtualFolders).on('click', function () {
showCardMenu(page, this, virtualFolders);
});
$('.addLibrary', divVirtualFolders).on('click', function () {
addVirtualFolder(page);
});
2015-10-15 20:17:42 -07:00
$('.editLibrary', divVirtualFolders).on('click', function () {
var card = $(this).parents('.card')[0];
var index = parseInt(card.getAttribute('data-index'));
var virtualFolder = virtualFolders[index];
2015-10-15 22:36:16 -07:00
2015-10-16 10:06:31 -07:00
if (!virtualFolder.ItemId) {
return;
}
2016-04-11 21:03:07 -07:00
editVirtualFolder(page, virtualFolder);
2015-10-15 20:17:42 -07:00
});
2015-10-15 10:21:18 -07:00
Dashboard.hideLoadingMsg();
}
2016-04-11 21:03:07 -07:00
function editImages(page, virtualFolder) {
2016-04-14 19:39:39 -07:00
2016-04-11 21:03:07 -07:00
require(['components/imageeditor/imageeditor'], function (ImageEditor) {
ImageEditor.show(virtualFolder.ItemId, {
theme: 'a'
2016-06-24 09:51:13 -07:00
}).then(function () {
reloadLibrary(page);
2016-04-11 21:03:07 -07:00
});
});
}
2015-10-15 10:21:18 -07:00
function getCollectionTypeOptions() {
2013-07-12 12:56:40 -07:00
return [
{ name: "", value: "" },
2014-08-24 08:48:06 -07:00
{ name: Globalize.translate('FolderTypeMovies'), value: "movies" },
{ name: Globalize.translate('FolderTypeMusic'), value: "music" },
{ name: Globalize.translate('FolderTypeTvShows'), value: "tvshows" },
2014-12-19 23:06:27 -07:00
{ name: Globalize.translate('FolderTypeBooks'), value: "books", message: Globalize.translate('MessageBookPluginRequired') },
{ name: Globalize.translate('FolderTypeGames'), value: "games", message: Globalize.translate('MessageGamePluginRequired') },
2016-08-12 23:33:31 -07:00
{ name: Globalize.translate('OptionHomeVideos'), value: "homevideos" },
2014-08-24 08:48:06 -07:00
{ name: Globalize.translate('FolderTypeMusicVideos'), value: "musicvideos" },
{ name: Globalize.translate('FolderTypePhotos'), value: "photos" },
2014-12-27 23:21:39 -07:00
{ name: Globalize.translate('FolderTypeUnset'), value: "mixed", message: Globalize.translate('MessageUnsetContentHelp') }
2013-07-12 12:56:40 -07:00
];
2015-10-15 10:21:18 -07:00
}
2013-07-12 12:56:40 -07:00
2015-10-15 10:21:18 -07:00
function getIcon(type) {
switch (type) {
case "movies":
2016-07-30 13:47:18 -07:00
return "local_movies";
2015-10-15 10:21:18 -07:00
case "music":
2016-07-30 13:47:18 -07:00
return "library_music";
2015-10-15 10:21:18 -07:00
case "photos":
return "photo";
case "livetv":
2016-07-30 13:47:18 -07:00
return "live_tv";
2015-10-15 10:21:18 -07:00
case "tvshows":
2016-07-30 13:47:18 -07:00
return "live_tv";
2015-10-15 10:21:18 -07:00
case "games":
return "folder";
case "trailers":
2016-07-30 13:47:18 -07:00
return "local_movies";
2015-10-15 10:21:18 -07:00
case "homevideos":
2016-07-30 13:47:18 -07:00
return "video_library";
2015-10-15 10:21:18 -07:00
case "musicvideos":
2016-07-30 13:47:18 -07:00
return "video_library";
2015-10-15 10:21:18 -07:00
case "books":
return "folder";
case "channels":
return "folder";
case "playlists":
return "folder";
default:
return "folder";
}
}
2013-02-20 18:33:05 -07:00
2015-10-26 11:12:20 -07:00
function getVirtualFolderHtml(page, virtualFolder, index) {
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
var html = '';
2015-10-15 20:17:42 -07:00
var style = "";
2015-10-26 11:12:20 -07:00
if (page.classList.contains('wizardPage')) {
2015-10-15 20:17:42 -07:00
style += "min-width:33.3%;";
}
2016-07-30 13:47:18 -07:00
html += '<div class="card backdropCard scalableCard" style="' + style + '" data-index="' + index + '">';
2013-09-04 12:16:41 -07:00
2015-10-15 10:21:18 -07:00
html += '<div class="cardBox visualCardBox">';
html += '<div class="cardScalable">';
2013-02-20 18:33:05 -07:00
2016-08-11 13:28:49 -07:00
html += '<div class="cardPadder cardPadder-backdrop"></div>';
2013-02-20 18:33:05 -07:00
2015-10-15 19:06:44 -07:00
html += '<div class="cardContent">';
2015-10-15 10:21:18 -07:00
var imgUrl = '';
2015-10-15 10:37:27 -07:00
if (virtualFolder.PrimaryImageItemId) {
imgUrl = ApiClient.getScaledImageUrl(virtualFolder.PrimaryImageItemId, {
type: 'Primary'
});
}
2015-10-15 10:21:18 -07:00
if (imgUrl) {
2016-07-30 13:47:18 -07:00
html += '<div class="cardImageContainer editLibrary" style="cursor:pointer;background-image:url(\'' + imgUrl + '\');"></div>';
2015-10-15 19:06:44 -07:00
} else if (!virtualFolder.showNameWithIcon) {
2016-07-30 13:47:18 -07:00
html += '<div class="cardImageContainer editLibrary" style="cursor:pointer;">';
html += '<i class="cardImageIcon md-icon" style="color:#444;">' + (virtualFolder.icon || getIcon(virtualFolder.CollectionType)) + '</i>';
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
html += '</div>';
}
2013-02-20 18:33:05 -07:00
2015-10-15 19:06:44 -07:00
if (!imgUrl && virtualFolder.showNameWithIcon) {
2016-07-30 13:47:18 -07:00
html += '<h1 class="cardImageContainer addLibrary" style="position:absolute;top:0;left:0;right:0;bottom:0;cursor:pointer;flex-direction:column;">';
2015-10-15 19:06:44 -07:00
2016-08-04 09:39:19 -07:00
html += '<i class="cardImageIcon md-icon" style="font-size:300%;color:#888;height:auto;width:auto;">' + (virtualFolder.icon || getIcon(virtualFolder.CollectionType)) + '</i>';
2015-10-15 19:06:44 -07:00
if (virtualFolder.showNameWithIcon) {
2016-08-04 09:39:19 -07:00
html += '<div style="margin:1em 0;position:width:100%;font-weight:500;color:#444;">';
2015-10-15 19:06:44 -07:00
html += virtualFolder.Name;
html += "</div>";
}
2016-02-11 21:33:14 -07:00
html += '</h1>';
2015-10-15 19:06:44 -07:00
}
2016-07-31 10:26:11 -07:00
// cardContent
html += "</div>";
// cardScalable
html += "</div>";
2015-10-15 10:21:18 -07:00
html += '<div class="cardFooter">';
2015-10-15 10:21:18 -07:00
if (virtualFolder.showMenu !== false) {
2016-07-23 11:43:07 -07:00
var moreIcon = appHost.moreIcon == 'dots-horiz' ? '&#xE5D3;' : '&#xE5D4;';
2016-07-30 13:47:18 -07:00
html += '<div style="text-align:right; float:right;padding-top:5px;">';
2016-07-23 11:43:07 -07:00
html += '<button type="button" is="paper-icon-button-light" class="btnCardMenu autoSize"><i class="md-icon">' + moreIcon + '</i></button>';
2015-10-15 10:21:18 -07:00
html += "</div>";
2013-02-20 18:33:05 -07:00
}
2015-10-15 10:21:18 -07:00
html += "<div class='cardText'>";
if (virtualFolder.showNameWithIcon) {
html += '&nbsp;';
} else {
html += virtualFolder.Name;
}
html += "</div>";
2015-10-15 10:21:18 -07:00
var typeName = getCollectionTypeOptions().filter(function (t) {
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
return t.value == virtualFolder.CollectionType;
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
})[0];
2013-09-05 10:05:39 -07:00
2015-10-15 10:21:18 -07:00
typeName = typeName ? typeName.name : Globalize.translate('FolderTypeUnset');
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
html += "<div class='cardText'>";
if (virtualFolder.showType === false) {
html += '&nbsp;';
} else {
html += typeName;
}
html += "</div>";
if (virtualFolder.showLocations === false) {
html += "<div class='cardText'>";
html += '&nbsp;';
html += "</div>";
} else if (!virtualFolder.Locations.length) {
html += "<div class='cardText' style='color:#cc3333;'>";
html += Globalize.translate('NumLocationsValue', virtualFolder.Locations.length);
html += "</div>";
}
else if (virtualFolder.Locations.length == 1) {
html += "<div class='cardText'>";
html += virtualFolder.Locations[0];
html += "</div>";
}
else {
html += "<div class='cardText'>";
html += Globalize.translate('NumLocationsValue', virtualFolder.Locations.length);
html += "</div>";
}
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
// cardFooter
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
// cardBox
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
// card
html += "</div>";
2013-02-20 18:33:05 -07:00
2015-10-15 10:21:18 -07:00
return html;
}
2013-02-20 18:33:05 -07:00
2016-03-19 15:31:00 -07:00
window.WizardLibraryPage = {
2013-02-20 18:33:05 -07:00
2016-03-19 15:31:00 -07:00
next: function () {
2016-03-19 15:31:00 -07:00
Dashboard.showLoadingMsg();
2014-07-10 21:27:46 -07:00
2016-03-19 15:31:00 -07:00
var apiClient = ApiClient;
2014-07-10 21:27:46 -07:00
2016-03-19 15:31:00 -07:00
apiClient.ajax({
type: "POST",
url: apiClient.getUrl('System/Configuration/MetadataPlugins/Autoset')
2014-11-14 19:31:03 -07:00
2016-03-19 15:31:00 -07:00
}).then(function () {
2014-07-10 21:27:46 -07:00
2016-03-19 15:31:00 -07:00
Dashboard.hideLoadingMsg();
Dashboard.navigate('wizardsettings.html');
});
}
};
2016-04-14 09:30:37 -07:00
function getTabs() {
return [
{
href: 'library.html',
name: Globalize.translate('TabFolders')
},
2016-06-03 22:51:33 -07:00
{
href: 'librarydisplay.html',
name: Globalize.translate('TabDisplay')
},
2016-04-14 09:30:37 -07:00
{
href: 'librarypathmapping.html',
name: Globalize.translate('TabPathSubstitution')
2016-04-14 19:39:39 -07:00
},
{
href: 'librarysettings.html',
name: Globalize.translate('TabAdvanced')
2016-04-14 09:30:37 -07:00
}];
}
2016-03-19 15:31:00 -07:00
pageClassOn('pageshow', "mediaLibraryPage", function () {
2014-07-10 21:27:46 -07:00
2016-03-19 15:31:00 -07:00
var page = this;
reloadLibrary(page);
2014-07-10 21:27:46 -07:00
2016-03-19 15:31:00 -07:00
});
2015-10-15 10:21:18 -07:00
pageIdOn('pageshow', "mediaLibraryPage", function () {
2015-01-20 13:19:54 -07:00
2016-04-14 09:30:37 -07:00
LibraryMenu.setTabs('librarysetup', 0, getTabs);
2015-01-20 13:19:54 -07:00
var page = this;
// on here
$('.btnRefresh', page).taskButton({
mode: 'on',
2015-09-12 09:39:24 -07:00
progressElem: page.querySelector('.refreshProgress'),
2015-01-20 13:19:54 -07:00
taskKey: 'RefreshLibrary'
});
2015-10-15 10:21:18 -07:00
});
pageIdOn('pagebeforehide', "mediaLibraryPage", function () {
2015-01-20 13:19:54 -07:00
var page = this;
// off here
$('.btnRefresh', page).taskButton({
mode: 'off'
});
});
});