medialibrarycreator.js
This commit is contained in:
parent
2c4cc578ca
commit
3682d3c222
1 changed files with 71 additions and 38 deletions
|
@ -2,25 +2,31 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
"use strict";
|
||||
|
||||
function onAddLibrary() {
|
||||
if (isCreating) return false;
|
||||
if (isCreating) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pathInfos.length == 0) {
|
||||
require(["alert"], function (alert) {
|
||||
alert({
|
||||
text: Globalize.translate("PleaseAddAtLeastOneFolder"),
|
||||
type: "error"
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
isCreating = true;
|
||||
loading.show();
|
||||
|
||||
var dlg = dom.parentWithClass(this, "dlg-librarycreator");
|
||||
var name = $("#txtValue", dlg).val();
|
||||
var type = $("#selectCollectionType", dlg).val();
|
||||
if (type == "mixed") type = null;
|
||||
|
||||
if (type == "mixed") {
|
||||
type = null;
|
||||
}
|
||||
|
||||
var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions"));
|
||||
libraryOptions.PathInfos = pathInfos;
|
||||
ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function () {
|
||||
|
@ -32,6 +38,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
require(["toast"], function (toast) {
|
||||
toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder"));
|
||||
});
|
||||
|
||||
isCreating = false;
|
||||
loading.hide();
|
||||
});
|
||||
|
@ -49,6 +56,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
var value = this.value;
|
||||
var dlg = $(this).parents(".dialog")[0];
|
||||
libraryoptionseditor.setContentType(dlg.querySelector(".libraryOptions"), value == "mixed" ? "" : value);
|
||||
|
||||
if (value) {
|
||||
dlg.querySelector(".libraryOptions").classList.remove("hide");
|
||||
} else {
|
||||
|
@ -57,17 +65,17 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
|
||||
if (value != "mixed") {
|
||||
var index = this.selectedIndex;
|
||||
|
||||
if (index != -1) {
|
||||
var name = this.options[index].innerHTML.replace("*", "").replace("&", "&");
|
||||
$("#txtValue", dlg).val(name);
|
||||
var folderOption = collectionTypeOptions.filter(function (i) {
|
||||
return i.value == value
|
||||
return i.value == value;
|
||||
})[0];
|
||||
$(".collectionTypeFieldDescription", dlg).html(folderOption.message || "")
|
||||
$(".collectionTypeFieldDescription", dlg).html(folderOption.message || "");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
page.querySelector(".btnAddFolder").addEventListener("click", onAddButtonClick);
|
||||
page.querySelector(".btnSubmit").addEventListener("click", onAddLibrary);
|
||||
page.querySelector(".folderList").addEventListener("click", onRemoveClick);
|
||||
|
@ -81,28 +89,48 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
|
||||
function onAddButtonClick() {
|
||||
var page = dom.parentWithClass(this, "dlg-librarycreator");
|
||||
|
||||
require(["directorybrowser"], function (directoryBrowser) {
|
||||
var picker = new directoryBrowser;
|
||||
var picker = new directoryBrowser();
|
||||
picker.show({
|
||||
enableNetworkSharePath: true,
|
||||
callback: function (path, networkSharePath) {
|
||||
path && addMediaLocation(page, path, networkSharePath);
|
||||
if (path) {
|
||||
addMediaLocation(page, path, networkSharePath);
|
||||
}
|
||||
|
||||
picker.close();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getFolderHtml(pathInfo, index) {
|
||||
var html = "";
|
||||
return html += '<div class="listItem listItem-border lnkPath" style="padding-left:.5em;">', html += '<div class="' + (pathInfo.NetworkPath ? "listItemBody two-line" : "listItemBody") + '">', html += '<div class="listItemBodyText">' + pathInfo.Path + "</div>", pathInfo.NetworkPath && (html += '<div class="listItemBodyText secondary">' + pathInfo.NetworkPath + "</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 += "</div>"
|
||||
html += '<div class="listItem listItem-border lnkPath" style="padding-left:.5em;">';
|
||||
html += '<div class="' + (pathInfo.NetworkPath ? "listItemBody two-line" : "listItemBody") + '">';
|
||||
html += '<div class="listItemBodyText">' + pathInfo.Path + "</div>";
|
||||
|
||||
if (pathInfo.NetworkPath) {
|
||||
html += '<div class="listItemBodyText secondary">' + pathInfo.NetworkPath + "</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 += "</div>";
|
||||
return html;
|
||||
}
|
||||
|
||||
function renderPaths(page) {
|
||||
var foldersHtml = pathInfos.map(getFolderHtml).join("");
|
||||
var folderList = page.querySelector(".folderList");
|
||||
folderList.innerHTML = foldersHtml;
|
||||
foldersHtml ? folderList.classList.remove("hide") : folderList.classList.add("hide");
|
||||
|
||||
if (foldersHtml) {
|
||||
folderList.classList.remove("hide");
|
||||
} else {
|
||||
folderList.classList.add("hide");
|
||||
}
|
||||
}
|
||||
|
||||
function addMediaLocation(page, path, networkSharePath) {
|
||||
|
@ -110,11 +138,16 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
var pathFilter = pathInfos.filter(function (p) {
|
||||
return p.Path.toLowerCase() == pathLower;
|
||||
});
|
||||
|
||||
if (!pathFilter.length) {
|
||||
var pathInfo = {
|
||||
Path: path
|
||||
};
|
||||
networkSharePath && (pathInfo.NetworkPath = networkSharePath);
|
||||
|
||||
if (networkSharePath) {
|
||||
pathInfo.NetworkPath = networkSharePath;
|
||||
}
|
||||
|
||||
pathInfos.push(pathInfo);
|
||||
renderPaths(page);
|
||||
}
|
||||
|
@ -139,7 +172,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
libraryoptionseditor.embed(dlg.querySelector(".libraryOptions")).then(function () {
|
||||
$("#selectCollectionType", dlg).trigger("change");
|
||||
onToggleAdvancedChange.call(dlg.querySelector(".chkAdvanced"));
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function editor() {
|
||||
|
@ -148,8 +181,9 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
currentOptions = options;
|
||||
currentResolve = resolve;
|
||||
hasChanges = false;
|
||||
var xhr = new XMLHttpRequest;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "components/medialibrarycreator/medialibrarycreator.template.html", true);
|
||||
|
||||
xhr.onload = function (e) {
|
||||
var template = this.response;
|
||||
var dlg = dialogHelper.createDialog({
|
||||
|
@ -167,23 +201,22 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed
|
|||
dlg.addEventListener("close", onDialogClosed);
|
||||
dialogHelper.open(dlg);
|
||||
dlg.querySelector(".btnCancel").addEventListener("click", function () {
|
||||
dialogHelper.close(dlg)
|
||||
dialogHelper.close(dlg);
|
||||
});
|
||||
pathInfos = [];
|
||||
renderPaths(dlg);
|
||||
initLibraryOptions(dlg);
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var pathInfos = [];
|
||||
var currentResolve;
|
||||
var currentOptions;
|
||||
|
||||
var hasChanges = false;
|
||||
var isCreating = false;
|
||||
|
||||
return editor
|
||||
return editor;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue