diff --git a/src/components/medialibraryeditor/medialibraryeditor.js b/src/components/medialibraryeditor/medialibraryeditor.js index a1ee53f72b..8336f9e175 100644 --- a/src/components/medialibraryeditor/medialibraryeditor.js +++ b/src/components/medialibraryeditor/medialibraryeditor.js @@ -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"; 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() { + ApiClient.updateVirtualFolderOptions(currentOptions.library.ItemId, libraryOptions).then(function () { hasChanges = true; isCreating = false; loading.hide(); dialogHelper.close(dlg); - }, function() { + }, function () { isCreating = false; loading.hide(); }); @@ -26,11 +26,11 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed function addMediaLocation(page, path, networkSharePath) { var virtualFolder = currentOptions.library; var refreshAfterChange = currentOptions.refresh; - ApiClient.addMediaPath(virtualFolder.Name, path, networkSharePath, refreshAfterChange).then(function() { + ApiClient.addMediaPath(virtualFolder.Name, path, networkSharePath, refreshAfterChange).then(function () { hasChanges = true; refreshLibraryFromServer(page); - }, function() { - require(["toast"], function(toast) { + }, function () { + require(["toast"], function (toast) { toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder")); }); }); @@ -41,11 +41,11 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed ApiClient.updateMediaPath(virtualFolder.Name, { Path: path, NetworkPath: networkSharePath - }).then(function() { + }).then(function () { hasChanges = true; refreshLibraryFromServer(page); - }, function() { - require(["toast"], function(toast) { + }, function () { + require(["toast"], function (toast) { toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder")); }); }); @@ -54,19 +54,20 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed function onRemoveClick(btnRemovePath, location) { var button = btnRemovePath; var virtualFolder = currentOptions.library; - require(["confirm"], function(confirm) { + + require(["confirm"], function (confirm) { confirm({ title: Globalize.translate("HeaderRemoveMediaLocation"), text: Globalize.translate("MessageConfirmRemoveMediaLocation"), confirmText: Globalize.translate("ButtonDelete"), primary: "delete" - }).then(function() { + }).then(function () { var refreshAfterChange = currentOptions.refresh; - ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).then(function() { + ApiClient.removeMediaPath(virtualFolder.Name, location, refreshAfterChange).then(function () { hasChanges = true; refreshLibraryFromServer(dom.parentWithClass(button, "dlg-libraryeditor")); - }, function() { - require(["toast"], function(toast) { + }, function () { + require(["toast"], function (toast) { toast(Globalize.translate("DefaultErrorMessage")); }); }); @@ -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 += '

'; html += pathInfo.Path; html += "

"; + if (pathInfo.NetworkPath) { html += '
' + pathInfo.NetworkPath + "
"; } + html += ""; html += ''; html += ""; @@ -104,10 +113,11 @@ 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 + ApiClient.getVirtualFolders().then(function (result) { + var library = result.filter(function (f) { + 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) { - return { - Path: 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(""); } @@ -135,24 +150,31 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed } function showDirectoryBrowser(context, originalPath, networkPath) { - require(["directorybrowser"], function(directoryBrowser) { - var picker = new directoryBrowser; + require(["directorybrowser"], function (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)); + callback: function (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) { @@ -161,7 +183,7 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed dlg.querySelector(".folderList").addEventListener("click", onListItemClick); dlg.querySelector(".chkAdvanced").addEventListener("change", onToggleAdvancedChange); 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")); }); } @@ -171,14 +193,15 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed } function editor() { - this.show = function(options) { + this.show = function (options) { var deferred = jQuery.Deferred(); 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) { + + xhr.onload = function (e) { var template = this.response; var dlg = dialogHelper.createDialog({ size: "medium-tall", @@ -195,21 +218,20 @@ define(["jQuery", "loading", "dialogHelper", "dom", "components/libraryoptionsed initEditor(dlg, options); dlg.addEventListener("close", onDialogClosed); dialogHelper.open(dlg); - dlg.querySelector(".btnCancel").addEventListener("click", function() { + dlg.querySelector(".btnCancel").addEventListener("click", function () { dialogHelper.close(dlg); }); refreshLibraryFromServer(dlg); }; + xhr.send(); return deferred.promise(); - } + }; } var currentDeferred; var currentOptions; - var hasChanges = false; var isCreating = false; - return editor; });