minor code cleanup

This commit is contained in:
dkanada 2019-05-06 19:47:02 -07:00
parent fa27a839f3
commit e833225ab3
4 changed files with 74 additions and 57 deletions

View File

@ -14,14 +14,16 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
type: "error"
})
});
} else {
return false;
}
isCreating = true;
loading.show();
var form = this,
dlg = $(form).parents(".dialog")[0],
name = $("#txtValue", form).val(),
type = $("#selectCollectionType", form).val();
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;
@ -37,7 +39,6 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
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
});

View File

@ -1,14 +1,11 @@
<div class="formDialogHeader">
<button type="button" is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><i class="md-icon">&#xE5C4;</i></button>
<h3 class="formDialogHeaderTitle">
${ButtonAddMediaLibrary}
</h3>
<h3 class="formDialogHeaderTitle">${ButtonAddMediaLibrary}</h3>
</div>
<div class="formDialogContent scrollY" style="padding-top:2em;">
<div class="dialogContentInner dialog-content-centered">
<form style="margin:auto;">
<div class="inputContainer" style="text-align:right;">
<label style="width:auto;">
<input is="emby-toggle" type="checkbox" class="chkAdvanced noautofocus" />
@ -21,19 +18,20 @@
<div class="collectionTypeFieldDescription fieldDescription">
</div>
</div>
<div class="inputContainer">
<input is="emby-input" type="text" id="txtValue" required="required" label="${LabelDisplayName}" />
</div>
<div style="display: flex; align-items: center;">
<h1 style="margin: .5em 0;">${HeadersFolders}</h1>
<button is="emby-button" type="button" class="fab btnAddFolder submit" style="margin-left:1em;" title="${ButtonAdd}">
<i class="md-icon">add</i>
</button>
</div>
<div class="paperList folderList hide" style="margin-bottom:2em;"></div>
</div>
<div class="libraryOptions"></div>
<br />
<div class="formDialogFooter">
<button is="emby-button" type="submit" class="raised button-submit block formDialogFooterItem">

View File

@ -5,7 +5,6 @@
<div class="formDialogContent scrollY" style="padding-top:2em;">
<div class="dialogContentInner dialog-content-centered">
<div class="infoBanner" style="margin-bottom:1.8em;">
${ChangingMetadataImageSettingsNewContent}
</div>
@ -26,6 +25,7 @@
</div>
<div class="paperList folderList" style="margin-bottom:2em;"></div>
</div>
<div class="libraryOptions"></div>
</div>
</div>

View File

@ -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)
}