From e833225ab370743d162ef06eac2a32de0d5fddc9 Mon Sep 17 00:00:00 2001 From: dkanada Date: Mon, 6 May 2019 19:47:02 -0700 Subject: [PATCH] minor code cleanup --- .../medialibrarycreator.js | 108 ++++++++++-------- .../medialibrarycreator.template.html | 10 +- .../medialibraryeditor.template.html | 2 +- src/controllers/medialibrarypage.js | 11 +- 4 files changed, 74 insertions(+), 57 deletions(-) diff --git a/src/components/medialibrarycreator/medialibrarycreator.js b/src/components/medialibrarycreator/medialibrarycreator.js index d02f0940cb..80f95dc855 100644 --- a/src/components/medialibrarycreator/medialibrarycreator.js +++ b/src/components/medialibrarycreator/medialibrarycreator.js @@ -14,30 +14,31 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed type: "error" }) }); - } else { - isCreating = true; - loading.show(); - - var form = this, - dlg = $(form).parents(".dialog")[0], - name = $("#txtValue", form).val(), - type = $("#selectCollectionType", form).val(); - if (type == "mixed") type = null; - var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions")); - libraryOptions.PathInfos = pathInfos; - ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function() { - hasChanges = true; - isCreating = false; - loading.hide(); - dialogHelper.close(dlg); - }, function() { - require(["toast"], function(toast) { - toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder")) - }) - isCreating = false; - loading.hide(); - }); + return false; } + + isCreating = true; + loading.show(); + + var form = this; + var dlg = $(form).parents(".dialog")[0]; + var name = $("#txtValue", form).val(); + var type = $("#selectCollectionType", form).val(); + if (type == "mixed") type = null; + var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions")); + libraryOptions.PathInfos = pathInfos; + ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function() { + hasChanges = true; + isCreating = false; + loading.hide(); + dialogHelper.close(dlg); + }, function() { + require(["toast"], function(toast) { + toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder")) + }) + isCreating = false; + loading.hide(); + }); return false; } @@ -49,13 +50,14 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed function initEditor(page, collectionTypeOptions) { $("#selectCollectionType", page).html(getCollectionTypeOptionsHtml(collectionTypeOptions)).val("").on("change", function() { - var value = this.value, - dlg = $(this).parents(".dialog")[0]; + var value = this.value; + var dlg = $(this).parents(".dialog")[0]; libraryoptionseditor.setContentType(dlg.querySelector(".libraryOptions"), value == "mixed" ? "" : value); - if (value) + if (value) { dlg.querySelector(".libraryOptions").classList.remove("hide"); - else + } else { dlg.querySelector(".libraryOptions").classList.add("hide"); + } if (value != "mixed") { var index = this.selectedIndex; @@ -73,7 +75,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed function onToggleAdvancedChange() { var dlg = dom.parentWithClass(this, "dlg-librarycreator"); - libraryoptionseditor.setAdvancedVisible(dlg.querySelector(".libraryOptions"), this.checked) + libraryoptionseditor.setAdvancedVisible(dlg.querySelector(".libraryOptions"), this.checked); } function onAddButtonClick() { @@ -83,7 +85,8 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed picker.show({ enableNetworkSharePath: true, callback: function(path, networkSharePath) { - path && addMediaLocation(page, path, networkSharePath), picker.close() + path && addMediaLocation(page, path, networkSharePath); + picker.close(); } }) }) @@ -95,31 +98,36 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed } function renderPaths(page) { - var foldersHtml = pathInfos.map(getFolderHtml).join(""), - folderList = page.querySelector(".folderList"); - folderList.innerHTML = foldersHtml, foldersHtml ? folderList.classList.remove("hide") : folderList.classList.add("hide") + var foldersHtml = pathInfos.map(getFolderHtml).join(""); + var folderList = page.querySelector(".folderList"); + folderList.innerHTML = foldersHtml; + foldersHtml ? folderList.classList.remove("hide") : folderList.classList.add("hide"); } function addMediaLocation(page, path, networkSharePath) { var pathLower = path.toLowerCase(); - if (0 == pathInfos.filter(function(p) { - return p.Path.toLowerCase() == pathLower - }).length) { + var path = pathInfos.filter(function(p) { + return p.Path.toLowerCase() == pathLower; + }); + if (path.length === 0) { var pathInfo = { Path: path }; - networkSharePath && (pathInfo.NetworkPath = networkSharePath), pathInfos.push(pathInfo), renderPaths(page) + networkSharePath && (pathInfo.NetworkPath = networkSharePath); + pathInfos.push(pathInfo); + renderPaths(page); } } function onRemoveClick(e) { - var button = dom.parentWithClass(e.target, "btnRemovePath"), - index = parseInt(button.getAttribute("data-index")), - location = pathInfos[index].Path, - locationLower = location.toLowerCase(); + var button = dom.parentWithClass(e.target, "btnRemovePath"); + var index = parseInt(button.getAttribute("data-index")); + var location = pathInfos[index].Path; + var locationLower = location.toLowerCase(); pathInfos = pathInfos.filter(function(p) { - return p.Path.toLowerCase() != locationLower - }), renderPaths(dom.parentWithClass(button, "dlg-librarycreator")) + return p.Path.toLowerCase() != locationLower; + }); + renderPaths(dom.parentWithClass(button, "dlg-librarycreator")); } function onDialogClosed() { @@ -131,14 +139,17 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed function initLibraryOptions(dlg) { libraryoptionseditor.embed(dlg.querySelector(".libraryOptions")).then(function() { - $("#selectCollectionType", dlg).trigger("change"), onToggleAdvancedChange.call(dlg.querySelector(".chkAdvanced")) + $("#selectCollectionType", dlg).trigger("change"); + onToggleAdvancedChange.call(dlg.querySelector(".chkAdvanced")); }) } function editor() { this.show = function(options) { return new Promise(function(resolve, reject) { - currentOptions = options, currentResolve = resolve, hasChanges = false; + currentOptions = options; + currentResolve = resolve; + hasChanges = false; var xhr = new XMLHttpRequest; xhr.open("GET", "components/medialibrarycreator/medialibrarycreator.template.html", true); xhr.onload = function(e) { @@ -168,6 +179,13 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed }) } } - var currentResolve, hasChanges, currentOptions, pathInfos = [], isCreating = false; + + var pathInfos = []; + var currentResolve; + var currentOptions; + + var hasChanges; + var isCreating = false; + return editor }); diff --git a/src/components/medialibrarycreator/medialibrarycreator.template.html b/src/components/medialibrarycreator/medialibrarycreator.template.html index eee1aee51e..c133bfd3f6 100644 --- a/src/components/medialibrarycreator/medialibrarycreator.template.html +++ b/src/components/medialibrarycreator/medialibrarycreator.template.html @@ -1,14 +1,11 @@
-

- ${ButtonAddMediaLibrary} -

+

${ButtonAddMediaLibrary}

-
+
+

${HeadersFolders}

+
-
-
diff --git a/src/controllers/medialibrarypage.js b/src/controllers/medialibrarypage.js index c8b1f8b478..362f89519f 100644 --- a/src/controllers/medialibrarypage.js +++ b/src/controllers/medialibrarypage.js @@ -157,12 +157,13 @@ define(["jQuery", "apphost", "scripts/taskbutton", "loading", "libraryMenu", "gl Name: globalize.translate("ButtonAddMediaLibrary"), icon: "add_circle", Locations: [], - showType: !1, - showLocations: !1, - showMenu: !1, - showNameWithIcon: !0 + showType: false, + showLocations: false, + showMenu: false, + showNameWithIcon: true }); - for (var i = 0, length = virtualFolders.length; i < length; i++) { + + for (var i = 0; i < virtualFolders.length; i++) { var virtualFolder = virtualFolders[i]; html += getVirtualFolderHtml(page, virtualFolder, i) }