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