mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
172 lines
5.9 KiB
Plaintext
172 lines
5.9 KiB
Plaintext
@model UploadViewModel?;
|
|
|
|
<div class="ha-adminuploadfields" id="ha-adminuploadfields">
|
|
@foreach (var item in Model.AvailableRoots.OrderBy(x => x.Type)) {
|
|
<a class="ha-uploadfield" asp-controller="Upload" asp-action="Index" asp-route-id="@item.Prefix">
|
|
<div class="ha-uploadfieldname">@item.Type</div>
|
|
@if (Model.UsedFiles != null && Model.UsedFiles.ContainsKey(item.Prefix)) {
|
|
<div class="ha-uploadusedfiles">
|
|
@foreach(var file in Model.UsedFiles[item.Prefix].GetFileList()!) {
|
|
@if (file == Model.UsedFiles[item.Prefix].GetFileList()!.Last())
|
|
{
|
|
<span class="ha-uploadusedfile">@file.FileName</span>
|
|
}
|
|
else
|
|
{
|
|
<span class="ha-uploadusedfile">@file.FileName;</span>
|
|
}
|
|
}
|
|
</div>
|
|
}
|
|
else {
|
|
<div class="ha-uploadusedfiles ha-uploadusedfilesnotfound">Keine Datei geladen!</div>
|
|
}
|
|
</a>
|
|
}
|
|
<div class="ha-uploadpublishforms">
|
|
<form class="ha-uploadform" id="uploadForm" asp-controller="API" asp-action="Upload" method="post" enctype="multipart/form-data">
|
|
<label class="ha-uploadfilelabel" id="dropzone">
|
|
<input class="hidden" id="file" type="file" accept=".xml" name="file" />
|
|
<div class="ha-uploadtext">Upload</div>
|
|
<div class="ha-lds-ellipsis" id="ha-lds-ellipsis"><div></div><div></div><div></div><div></div></div>
|
|
</label>
|
|
<div class="ha-uploadmessage" id="ha-uploadmessage">
|
|
Fehler!<br/>
|
|
<output form="uploadForm" name="upload-result"></output>
|
|
</div>
|
|
</form>
|
|
|
|
<form class="ha-publishform" action="Upload" method="post" enctype="multipart/form-data">
|
|
<label class="filelabel">
|
|
<input class="hidden" type="file" accept=".xml" name="file" />
|
|
Veröffentlichen
|
|
</label>
|
|
<div class="ha-uploadmessage">
|
|
|
|
<output form="uploadForm" name="result"></output>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="ha-uploadheader">
|
|
<h1 class="ha-uploadtitle">@Model.ActiveTitle</h1>
|
|
@if (Model.Prefix != null) {
|
|
<div class="ha-usedfilesheader">
|
|
<div class="ha-usedfilesheaderlist">
|
|
@if(Model.UsedFiles != null && Model.UsedFiles.ContainsKey(Model.Prefix)) {
|
|
@foreach (var item in Model.UsedFiles[Model.Prefix].GetFileList())
|
|
{
|
|
<div class="ha-usedfilesheaderfile">@item.File.Name</div>
|
|
}
|
|
}
|
|
else {
|
|
<div class="ha-usedfilesnone">Keine Datei geladen</div>
|
|
}
|
|
@if (Model.AvailableFiles != null)
|
|
{
|
|
<div class="ha-availablefilechooser"><div class="ha-plussign"></div><a class="ha-loadotherfilesbtn">Andere Dateien laden...</a></div>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
<div class="ha-uploadcontainer">
|
|
@if (Model.UsedFiles != null && Model.Prefix != null && Model.UsedFiles.ContainsKey(Model.Prefix)) {
|
|
<div class="ha-errorswarnings">
|
|
<div class="ha-criticalerrors">
|
|
|
|
</div>
|
|
<div class="ha-warnings">
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="ha-crossfilechecking">
|
|
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
@section Scripts {
|
|
|
|
<script>
|
|
"use strict";
|
|
const dropHandler = function (formelement, ev, dropzone) {
|
|
ev.preventDefault();
|
|
if (ev.dataTransfer.items) {
|
|
if (ev.dataTransfer.items[0].kind === 'file') {
|
|
var file = ev.dataTransfer.items[0].getAsFile();
|
|
UPLOADSubmit(formelement, file);
|
|
} else {
|
|
var file = ev.dataTransfer.files[0];
|
|
UPLOADSubmit(formelement, file);
|
|
}
|
|
}
|
|
}
|
|
|
|
const dragOverHandler = function (ev, dropzone) {
|
|
ev.preventDefault();
|
|
}
|
|
|
|
const dragLeaveHander = function (ev, dropzone) {
|
|
ev.preventDefault();
|
|
}
|
|
|
|
const dragEnterHandler = function (ev, dropzone) {
|
|
ev.preventDefault();
|
|
}
|
|
|
|
const UPLOADSubmit = async function (oFormElement, file = null) {
|
|
var fd = new FormData();
|
|
if (file !== null) fd.append("file", file);
|
|
else fd = new FormData(oFormElement);
|
|
document.getElementById("ha-lds-ellipsis").style.display = "inline-block";
|
|
document.getElementById("ha-uploadmessage").style.opacity = "0";
|
|
await fetch(oFormElement.action, {
|
|
method: 'POST',
|
|
headers: {
|
|
'RequestVerificationToken': getCookie('RequestVerificationToken')
|
|
},
|
|
body: fd
|
|
})
|
|
.then(response => response.json())
|
|
.then(json => {
|
|
if ("Error" in json) {
|
|
document.getElementById("ha-lds-ellipsis").style.display = "none";
|
|
document.getElementById("ha-uploadmessage").style.opacity = "1";
|
|
oFormElement.elements.namedItem("upload-result").value = json.Error;
|
|
} else {
|
|
document.getElementById("ha-lds-ellipsis").style.display = "none";
|
|
oFormElement.elements.namedItem("upload-result").value = "Erfolg!";
|
|
if ("Prefix" in json[0]) {
|
|
window.location.replace("/Admin/Upload/" + json[0].Prefix);
|
|
}
|
|
}
|
|
})
|
|
.catch ((e) => console.log('Error:', e))
|
|
}
|
|
|
|
function getCookie(name) {
|
|
var value = "; " + document.cookie;
|
|
var parts = value.split("; " + name + "=");
|
|
if (parts.length == 2) return parts.pop().split(";").shift();
|
|
}
|
|
|
|
window.addEventListener("load", function () {
|
|
var submitelement = document.getElementById("file");
|
|
var formelement = document.getElementById("uploadForm");
|
|
var dropzone = document.getElementById("dropzone");
|
|
submitelement.addEventListener("change", () => UPLOADSubmit(formelement));
|
|
dropzone.addEventListener("drop", (ev) => dropHandler(formelement, ev, dropzone));
|
|
dropzone.addEventListener("dragover", (ev) => dragOverHandler(ev, dropzone));
|
|
dropzone.addEventListener("dragleave", (ev) => dragLeaveHander(ev, dropzone));
|
|
dropzone.addEventListener("dragenter", (ev) => dragEnterHandler(ev, dropzone));
|
|
});
|
|
|
|
|
|
</script>
|
|
}
|