1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

medialibraryeditor.js

This commit is contained in:
grafixeyehero 2020-01-26 19:02:37 +03:00
parent 3682d3c222
commit 807a45505a

View file

@ -2,15 +2,15 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
"use strict"; "use strict";
function onEditLibrary() { function onEditLibrary() {
if (isCreating) return false; if (isCreating) {
return false;
}
isCreating = true; isCreating = true;
loading.show(); loading.show();
var dlg = dom.parentWithClass(this, "dlg-libraryeditor"); var dlg = dom.parentWithClass(this, "dlg-libraryeditor");
var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions")); var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions"));
libraryOptions = Object.assign(currentOptions.library.LibraryOptions || {}, libraryOptions); libraryOptions = Object.assign(currentOptions.library.LibraryOptions || {}, libraryOptions);
ApiClient.updateVirtualFolderOptions(currentOptions.library.ItemId, libraryOptions).then(function () { ApiClient.updateVirtualFolderOptions(currentOptions.library.ItemId, libraryOptions).then(function () {
hasChanges = true; hasChanges = true;
isCreating = false; isCreating = false;
@ -54,6 +54,7 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
function onRemoveClick(btnRemovePath, location) { function onRemoveClick(btnRemovePath, location) {
var button = btnRemovePath; var button = btnRemovePath;
var virtualFolder = currentOptions.library; var virtualFolder = currentOptions.library;
require(["confirm"], function (confirm) { require(["confirm"], function (confirm) {
confirm({ confirm({
title: Globalize.translate("HeaderRemoveMediaLocation"), title: Globalize.translate("HeaderRemoveMediaLocation"),
@ -76,13 +77,19 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
function onListItemClick(e) { function onListItemClick(e) {
var listItem = dom.parentWithClass(e.target, "listItem"); var listItem = dom.parentWithClass(e.target, "listItem");
if (listItem) { if (listItem) {
var index = parseInt(listItem.getAttribute("data-index")); var index = parseInt(listItem.getAttribute("data-index"));
var pathInfos = (currentOptions.library.LibraryOptions || {}).PathInfos || []; var pathInfos = (currentOptions.library.LibraryOptions || {}).PathInfos || [];
var pathInfo = null == index ? {} : pathInfos[index] || {}; var pathInfo = null == index ? {} : pathInfos[index] || {};
var originalPath = pathInfo.Path || (null == index ? null : currentOptions.library.Locations[index]); var originalPath = pathInfo.Path || (null == index ? null : currentOptions.library.Locations[index]);
var btnRemovePath = dom.parentWithClass(e.target, "btnRemovePath"); var btnRemovePath = dom.parentWithClass(e.target, "btnRemovePath");
if (btnRemovePath) return void onRemoveClick(btnRemovePath, originalPath);
if (btnRemovePath) {
onRemoveClick(btnRemovePath, originalPath);
return;
}
showDirectoryBrowser(dom.parentWithClass(listItem, "dlg-libraryeditor"), originalPath, pathInfo.NetworkPath); showDirectoryBrowser(dom.parentWithClass(listItem, "dlg-libraryeditor"), originalPath, pathInfo.NetworkPath);
} }
} }
@ -94,9 +101,11 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
html += '<h3 class="listItemBodyText">'; html += '<h3 class="listItemBodyText">';
html += pathInfo.Path; html += pathInfo.Path;
html += "</h3>"; html += "</h3>";
if (pathInfo.NetworkPath) { if (pathInfo.NetworkPath) {
html += '<div class="listItemBodyText secondary">' + pathInfo.NetworkPath + "</div>"; html += '<div class="listItemBodyText secondary">' + pathInfo.NetworkPath + "</div>";
} }
html += "</div>"; html += "</div>";
html += '<button type="button" is="paper-icon-button-light" class="listItemButton btnRemovePath" data-index="' + index + '"><i class="md-icon">remove_circle</i></button>'; html += '<button type="button" is="paper-icon-button-light" class="listItemButton btnRemovePath" data-index="' + index + '"><i class="md-icon">remove_circle</i></button>';
html += "</div>"; html += "</div>";
@ -106,8 +115,9 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
function refreshLibraryFromServer(page) { function refreshLibraryFromServer(page) {
ApiClient.getVirtualFolders().then(function (result) { ApiClient.getVirtualFolders().then(function (result) {
var library = result.filter(function (f) { var library = result.filter(function (f) {
return f.Name === currentOptions.library.Name return f.Name === currentOptions.library.Name;
})[0]; })[0];
if (library) { if (library) {
currentOptions.library = library; currentOptions.library = library;
renderLibrary(page, currentOptions); renderLibrary(page, currentOptions);
@ -117,16 +127,21 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
function renderLibrary(page, options) { function renderLibrary(page, options) {
var pathInfos = (options.library.LibraryOptions || {}).PathInfos || []; var pathInfos = (options.library.LibraryOptions || {}).PathInfos || [];
pathInfos.length || (pathInfos = options.library.Locations.map(function(p) {
if (!pathInfos.length) {
pathInfos = options.library.Locations.map(function (p) {
return { return {
Path: p Path: p
};
});
} }
}));
if (options.library.CollectionType === 'boxsets') { if (options.library.CollectionType === 'boxsets') {
page.querySelector(".folders").classList.add("hide"); page.querySelector(".folders").classList.add("hide");
} else { } else {
page.querySelector(".folders").classList.remove("hide"); page.querySelector(".folders").classList.remove("hide");
} }
page.querySelector(".folderList").innerHTML = pathInfos.map(getFolderHtml).join(""); page.querySelector(".folderList").innerHTML = pathInfos.map(getFolderHtml).join("");
} }
@ -136,23 +151,30 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
function showDirectoryBrowser(context, originalPath, networkPath) { function showDirectoryBrowser(context, originalPath, networkPath) {
require(["directorybrowser"], function (directoryBrowser) { require(["directorybrowser"], function (directoryBrowser) {
var picker = new directoryBrowser; var picker = new directoryBrowser();
picker.show({ picker.show({
enableNetworkSharePath: !0, enableNetworkSharePath: true,
pathReadOnly: null != originalPath, pathReadOnly: null != originalPath,
path: originalPath, path: originalPath,
networkSharePath: networkPath, networkSharePath: networkPath,
callback: function (path, networkSharePath) { callback: function (path, networkSharePath) {
path && (originalPath ? updateMediaLocation(context, originalPath, networkSharePath) : addMediaLocation(context, path, networkSharePath)); if (path) {
if (originalPath) {
updateMediaLocation(context, originalPath, networkSharePath);
} else {
addMediaLocation(context, path, networkSharePath);
}
}
picker.close(); picker.close();
} }
}) });
}) });
} }
function onToggleAdvancedChange() { function onToggleAdvancedChange() {
var dlg = dom.parentWithClass(this, "dlg-libraryeditor"); var dlg = dom.parentWithClass(this, "dlg-libraryeditor");
libraryoptionseditor.setAdvancedVisible(dlg.querySelector(".libraryOptions"), this.checked) libraryoptionseditor.setAdvancedVisible(dlg.querySelector(".libraryOptions"), this.checked);
} }
function initEditor(dlg, options) { function initEditor(dlg, options) {
@ -176,8 +198,9 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
currentOptions = options; currentOptions = options;
currentDeferred = deferred; currentDeferred = deferred;
hasChanges = false; hasChanges = false;
var xhr = new XMLHttpRequest; var xhr = new XMLHttpRequest();
xhr.open("GET", "components/medialibraryeditor/medialibraryeditor.template.html", true); xhr.open("GET", "components/medialibraryeditor/medialibraryeditor.template.html", true);
xhr.onload = function (e) { xhr.onload = function (e) {
var template = this.response; var template = this.response;
var dlg = dialogHelper.createDialog({ var dlg = dialogHelper.createDialog({
@ -200,16 +223,15 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
}); });
refreshLibraryFromServer(dlg); refreshLibraryFromServer(dlg);
}; };
xhr.send(); xhr.send();
return deferred.promise(); return deferred.promise();
} };
} }
var currentDeferred; var currentDeferred;
var currentOptions; var currentOptions;
var hasChanges = false; var hasChanges = false;
var isCreating = false; var isCreating = false;
return editor; return editor;
}); });