diff --git a/src/controllers/medialibrarypage.js b/src/controllers/medialibrarypage.js index 405d38bfa7..d8be309720 100644 --- a/src/controllers/medialibrarypage.js +++ b/src/controllers/medialibrarypage.js @@ -1,48 +1,54 @@ -define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "globalize", "dom", "indicators", "scripts/imagehelper", "cardStyle", "emby-itemrefreshindicator"], function($, appHost, taskButton, loading, libraryMenu, globalize, dom, indicators, imageHelper) { +define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "globalize", "dom", "indicators", "scripts/imagehelper", "cardStyle", "emby-itemrefreshindicator"], function ($, appHost, taskButton, loading, libraryMenu, globalize, dom, indicators, imageHelper) { "use strict"; function addVirtualFolder(page) { - require(["medialibrarycreator"], function(medialibrarycreator) { - (new medialibrarycreator).show({ - collectionTypeOptions: getCollectionTypeOptions().filter(function(f) { + require(["medialibrarycreator"], function (medialibrarycreator) { + new medialibrarycreator().show({ + collectionTypeOptions: getCollectionTypeOptions().filter(function (f) { return !f.hidden; }), refresh: shouldRefreshLibraryAfterChanges(page) - }).then(function(hasChanges) { - hasChanges && reloadLibrary(page); - }) - }) + }).then(function (hasChanges) { + if (hasChanges) { + reloadLibrary(page); + } + }); + }); } function editVirtualFolder(page, virtualFolder) { - require(["medialibraryeditor"], function(medialibraryeditor) { - (new medialibraryeditor).show({ + require(["medialibraryeditor"], function (medialibraryeditor) { + new medialibraryeditor().show({ refresh: shouldRefreshLibraryAfterChanges(page), library: virtualFolder - }).then(function(hasChanges) { - hasChanges && reloadLibrary(page); - }) - }) + }).then(function (hasChanges) { + if (hasChanges) { + reloadLibrary(page); + } + }); + }); } function deleteVirtualFolder(page, virtualFolder) { var msg = globalize.translate("MessageAreYouSureYouWishToRemoveMediaFolder"); + if (virtualFolder.Locations.length) { msg += "

" + globalize.translate("MessageTheFollowingLocationWillBeRemovedFromLibrary") + "

"; msg += virtualFolder.Locations.join("
"); } - require(["confirm"], function(confirm) { - confirm(msg, globalize.translate("HeaderRemoveMediaFolder")).then(function() { + + require(["confirm"], function (confirm) { + confirm(msg, globalize.translate("HeaderRemoveMediaFolder")).then(function () { var refreshAfterChange = shouldRefreshLibraryAfterChanges(page); - ApiClient.removeVirtualFolder(virtualFolder.Name, refreshAfterChange).then(function() { + ApiClient.removeVirtualFolder(virtualFolder.Name, refreshAfterChange).then(function () { reloadLibrary(page); - }) - }) - }) + }); + }); + }); } function refreshVirtualFolder(page, virtualFolder) { - require(["refreshDialog"], function(refreshDialog) { + require(["refreshDialog"], function (refreshDialog) { new refreshDialog({ itemIds: [virtualFolder.ItemId], serverId: ApiClient.serverId(), @@ -52,14 +58,14 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl } function renameVirtualFolder(page, virtualFolder) { - require(["prompt"], function(prompt) { + require(["prompt"], function (prompt) { prompt({ label: globalize.translate("LabelNewName"), confirmText: globalize.translate("ButtonRename") - }).then(function(newName) { + }).then(function (newName) { if (newName && newName != virtualFolder.Name) { var refreshAfterChange = shouldRefreshLibraryAfterChanges(page); - ApiClient.renameVirtualFolder(virtualFolder.Name, newName, refreshAfterChange).then(function() { + ApiClient.renameVirtualFolder(virtualFolder.Name, newName, refreshAfterChange).then(function () { reloadLibrary(page); }); } @@ -97,24 +103,29 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl id: "refresh", ironIcon: "refresh" }); - require(["actionsheet"], function(actionsheet) { + + require(["actionsheet"], function (actionsheet) { actionsheet.show({ items: menuItems, positionTo: elem, - callback: function(resultId) { + callback: function (resultId) { switch (resultId) { case "edit": editVirtualFolder(page, virtualFolder); break; + case "editimages": editImages(page, virtualFolder); break; + case "rename": renameVirtualFolder(page, virtualFolder); break; + case "delete": deleteVirtualFolder(page, virtualFolder); break; + case "refresh": refreshVirtualFolder(page, virtualFolder); } @@ -125,7 +136,7 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl function reloadLibrary(page) { loading.show(); - ApiClient.getVirtualFolders().then(function(result) { + ApiClient.getVirtualFolders().then(function (result) { reloadVirtualFolders(page, result); }); } @@ -148,36 +159,40 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl for (var i = 0; i < virtualFolders.length; i++) { var virtualFolder = virtualFolders[i]; - html += getVirtualFolderHtml(page, virtualFolder, i) + html += getVirtualFolderHtml(page, virtualFolder, i); } + var divVirtualFolders = page.querySelector("#divVirtualFolders"); divVirtualFolders.innerHTML = html; divVirtualFolders.classList.add("itemsContainer"); divVirtualFolders.classList.add("vertical-wrap"); - $(".btnCardMenu", divVirtualFolders).on("click", function() { + $(".btnCardMenu", divVirtualFolders).on("click", function () { showCardMenu(page, this, virtualFolders); }); - divVirtualFolders.querySelector(".addLibrary").addEventListener("click", function() { + divVirtualFolders.querySelector(".addLibrary").addEventListener("click", function () { addVirtualFolder(page); }); - $(".editLibrary", divVirtualFolders).on("click", function() { + $(".editLibrary", divVirtualFolders).on("click", function () { var card = $(this).parents(".card")[0]; var index = parseInt(card.getAttribute("data-index")); var virtualFolder = virtualFolders[index]; - virtualFolder.ItemId && editVirtualFolder(page, virtualFolder); + + if (virtualFolder.ItemId) { + editVirtualFolder(page, virtualFolder); + } }); loading.hide(); } function editImages(page, virtualFolder) { - require(["imageEditor"], function(imageEditor) { + require(["imageEditor"], function (imageEditor) { imageEditor.show({ itemId: virtualFolder.ItemId, serverId: ApiClient.serverId() - }).then(function() { + }).then(function () { reloadLibrary(page); }); - }) + }); } function getLink(text, url) { @@ -214,25 +229,32 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl name: globalize.translate("FolderTypeUnset"), value: "mixed", message: globalize.translate("MessageUnsetContentHelp") - }] + }]; } function getVirtualFolderHtml(page, virtualFolder, index) { var html = ""; var style = ""; - page.classList.contains("wizardPage") && (style += "min-width:33.3%;"); + + if (page.classList.contains("wizardPage")) { + style += "min-width:33.3%;"; + } + html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; var imgUrl = ""; + if (virtualFolder.PrimaryImageItemId) { imgUrl = ApiClient.getScaledImageUrl(virtualFolder.PrimaryImageItemId, { type: "Primary" }); } + var hasCardImageContainer; + if (imgUrl) { html += '
"; hasCardImageContainer = true; @@ -241,38 +263,60 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl html += '' + (virtualFolder.icon || imageHelper.getLibraryIcon(virtualFolder.CollectionType)) + ""; hasCardImageContainer = true; } + if (hasCardImageContainer) { html += '
'; html += '
'; html += "
"; html += "
"; } + if (!imgUrl && virtualFolder.showNameWithIcon) { html += '

'; html += '' + (virtualFolder.icon || imageHelper.getLibraryIcon(virtualFolder.CollectionType)) + ""; - virtualFolder.showNameWithIcon && (html += '
', html += virtualFolder.Name, html += "
"); + + if (virtualFolder.showNameWithIcon) { + html += '
'; + html += virtualFolder.Name; + html += "
"; + } + html += "

"; } - html += "
"; - html += "
"; - html += '
'; - // always show menu unless explicitly hidden + html += "
"; + html += "
"; + html += '
'; // always show menu unless explicitly hidden + if (virtualFolder.showMenu !== false) { html += '
'; html += ''; html += "
"; } + html += "
"; - virtualFolder.showNameWithIcon ? html += " " : html += virtualFolder.Name; + + if (virtualFolder.showNameWithIcon) { + html += " "; + } else { + html += virtualFolder.Name; + } + html += "
"; - var typeName = getCollectionTypeOptions().filter(function(t) { - return t.value == virtualFolder.CollectionType + var typeName = getCollectionTypeOptions().filter(function (t) { + return t.value == virtualFolder.CollectionType; })[0]; typeName = typeName ? typeName.name : globalize.translate("FolderTypeUnset"); html += "
"; - virtualFolder.showType === false ? html += " " : html += typeName; + + if (virtualFolder.showType === false) { + html += " "; + } else { + html += typeName; + } + html += "
"; + if (virtualFolder.showLocations === false) { html += "
"; html += " "; @@ -286,6 +330,7 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl html += globalize.translate("NumLocationsValue", virtualFolder.Locations.length); html += "
"; } + html += "
"; html += "
"; html += ""; @@ -305,18 +350,18 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl }, { href: "metadatanfo.html", name: globalize.translate("TabNfoSettings") - }] + }]; } window.WizardLibraryPage = { - next: function() { - Dashboard.navigate("wizardsettings.html") + next: function () { + Dashboard.navigate("wizardsettings.html"); } }; - pageClassOn("pageshow", "mediaLibraryPage", function() { + pageClassOn("pageshow", "mediaLibraryPage", function () { reloadLibrary(this); }); - pageIdOn("pageshow", "mediaLibraryPage", function() { + pageIdOn("pageshow", "mediaLibraryPage", function () { libraryMenu.setTabs("librarysetup", 0, getTabs); var page = this; taskButton({ @@ -326,7 +371,7 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl button: page.querySelector(".btnRefresh") }); }); - pageIdOn("pagebeforehide", "mediaLibraryPage", function() { + pageIdOn("pagebeforehide", "mediaLibraryPage", function () { var page = this; taskButton({ mode: "off",