mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
medialibraryeditor.js
This commit is contained in:
parent
3682d3c222
commit
807a45505a
1 changed files with 64 additions and 42 deletions
|
@ -1,22 +1,22 @@
|
||||||
define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionseditor/libraryoptionseditor", "emby-button", "listViewStyle", "paper-icon-button-light", "formDialogStyle", "emby-toggle", "flexStyles"], function(jQuery, loading, dialogHelper, dom, libraryoptionseditor) {
|
define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionseditor/libraryoptionseditor", "emby-button", "listViewStyle", "paper-icon-button-light", "formDialogStyle", "emby-toggle", "flexStyles"], function (jQuery, loading, dialogHelper, dom, libraryoptionseditor) {
|
||||||
"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;
|
||||||
loading.hide();
|
loading.hide();
|
||||||
dialogHelper.close(dlg);
|
dialogHelper.close(dlg);
|
||||||
}, function() {
|
}, function () {
|
||||||
isCreating = false;
|
isCreating = false;
|
||||||
loading.hide();
|
loading.hide();
|
||||||
});
|
});
|
||||||
|
@ -26,11 +26,11 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
|
||||||
function addMediaLocation(page, path, networkSharePath) {
|
function addMediaLocation(page, path, networkSharePath) {
|
||||||
var virtualFolder = currentOptions.library;
|
var virtualFolder = currentOptions.library;
|
||||||
var refreshAfterChange = currentOptions.refresh;
|
var refreshAfterChange = currentOptions.refresh;
|
||||||
ApiClient.addMediaPath(virtualFolder.Name, path, networkSharePath, refreshAfterChange).then(function() {
|
ApiClient.addMediaPath(virtualFolder.Name, path, networkSharePath, refreshAfterChange).then(function () {
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
refreshLibraryFromServer(page);
|
refreshLibraryFromServer(page);
|
||||||
}, function() {
|
}, function () {
|
||||||
require(["toast"], function(toast) {
|
require(["toast"], function (toast) {
|
||||||
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"));
|
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -41,11 +41,11 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
|
||||||
ApiClient.updateMediaPath(virtualFolder.Name, {
|
ApiClient.updateMediaPath(virtualFolder.Name, {
|
||||||
Path: path,
|
Path: path,
|
||||||
NetworkPath: networkSharePath
|
NetworkPath: networkSharePath
|
||||||
}).then(function() {
|
}).then(function () {
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
refreshLibraryFromServer(page);
|
refreshLibraryFromServer(page);
|
||||||
}, function() {
|
}, function () {
|
||||||
require(["toast"], function(toast) {
|
require(["toast"], function (toast) {
|
||||||
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"));
|
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -54,19 +54,20 @@ 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"),
|
||||||
text: Globalize.translate("MessageConfirmRemoveMediaLocation"),
|
text: Globalize.translate("MessageConfirmRemoveMediaLocation"),
|
||||||
confirmText: Globalize.translate("ButtonDelete"),
|
confirmText: Globalize.translate("ButtonDelete"),
|
||||||
primary: "delete"
|
primary: "delete"
|
||||||
}).then(function() {
|
}).then(function () {
|
||||||
var refreshAfterChange = currentOptions.refresh;
|
var refreshAfterChange = currentOptions.refresh;
|
||||||
ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).then(function() {
|
ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).then(function () {
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
refreshLibraryFromServer(dom.parentWithClass(button, "dlg-libraryeditor"));
|
refreshLibraryFromServer(dom.parentWithClass(button, "dlg-libraryeditor"));
|
||||||
}, function() {
|
}, function () {
|
||||||
require(["toast"], function(toast) {
|
require(["toast"], function (toast) {
|
||||||
toast(Globalize.translate("DefaultErrorMessage"));
|
toast(Globalize.translate("DefaultErrorMessage"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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>";
|
||||||
|
@ -104,10 +113,11 @@ 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) {
|
|
||||||
return {
|
if (!pathInfos.length) {
|
||||||
Path: p
|
pathInfos = options.library.Locations.map(function (p) {
|
||||||
}
|
return {
|
||||||
}));
|
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("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,24 +150,31 @@ 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) {
|
||||||
|
@ -161,7 +183,7 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
|
||||||
dlg.querySelector(".folderList").addEventListener("click", onListItemClick);
|
dlg.querySelector(".folderList").addEventListener("click", onListItemClick);
|
||||||
dlg.querySelector(".chkAdvanced").addEventListener("change", onToggleAdvancedChange);
|
dlg.querySelector(".chkAdvanced").addEventListener("change", onToggleAdvancedChange);
|
||||||
dlg.querySelector(".btnSubmit").addEventListener("click", onEditLibrary);
|
dlg.querySelector(".btnSubmit").addEventListener("click", onEditLibrary);
|
||||||
libraryoptionseditor.embed(dlg.querySelector(".libraryOptions"), options.library.CollectionType, options.library.LibraryOptions).then(function() {
|
libraryoptionseditor.embed(dlg.querySelector(".libraryOptions"), options.library.CollectionType, options.library.LibraryOptions).then(function () {
|
||||||
onToggleAdvancedChange.call(dlg.querySelector(".chkAdvanced"));
|
onToggleAdvancedChange.call(dlg.querySelector(".chkAdvanced"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -171,14 +193,15 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
|
||||||
}
|
}
|
||||||
|
|
||||||
function editor() {
|
function editor() {
|
||||||
this.show = function(options) {
|
this.show = function (options) {
|
||||||
var deferred = jQuery.Deferred();
|
var deferred = jQuery.Deferred();
|
||||||
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({
|
||||||
size: "medium-tall",
|
size: "medium-tall",
|
||||||
|
@ -195,21 +218,20 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed
|
||||||
initEditor(dlg, options);
|
initEditor(dlg, options);
|
||||||
dlg.addEventListener("close", onDialogClosed);
|
dlg.addEventListener("close", onDialogClosed);
|
||||||
dialogHelper.open(dlg);
|
dialogHelper.open(dlg);
|
||||||
dlg.querySelector(".btnCancel").addEventListener("click", function() {
|
dlg.querySelector(".btnCancel").addEventListener("click", function () {
|
||||||
dialogHelper.close(dlg);
|
dialogHelper.close(dlg);
|
||||||
});
|
});
|
||||||
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;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue