mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-30 01:35:32 +00:00
Creaded Upload Interface; Also added Wrapper around HaDocument to reload the Document
This commit is contained in:
@@ -1,42 +1,108 @@
|
||||
@model UploadViewModel;
|
||||
@model UploadViewModel?;
|
||||
|
||||
<div class="ha-adminuploadfields">
|
||||
<div class="ha-adminuploadfields" id="ha-adminuploadfields">
|
||||
@foreach (var item in Model.AvailableRoots.OrderBy(x => x.Type)) {
|
||||
<div class="ha-uploadfield">
|
||||
<div class="ha-uploadfieldname">@item.Type</div>
|
||||
@if (Model.UsedFiles != null && Model.UsedFiles.ContainsKey(item.Prefix)) {
|
||||
@foreach(var file in Model.UsedFiles[item.Prefix]) {
|
||||
<span>@file.File.Name</span>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<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]) {
|
||||
@if (file == Model.UsedFiles[item.Prefix].Last())
|
||||
{
|
||||
<span class="ha-uploadusedfile">@file.File.Name</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="ha-uploadusedfile">@file.File.Name;</span>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
else {
|
||||
<div class="ha-uploadusedfiles ha-uploadusedfilesnotfound">Keine Datei geladen!</div>
|
||||
}
|
||||
</a>
|
||||
}
|
||||
<form class="ha-uploadform" id="uploadForm" action="Upload" method="post" enctype="multipart/form-data">
|
||||
<label class="filelabel" id="dropzone">
|
||||
<input class="hidden" id="file" type="file" accept=".xml" name="file" />
|
||||
Upload2 es
|
||||
</label>
|
||||
<div class="ha-uploadmessage">
|
||||
<output form="uploadForm" name="result"></output>
|
||||
</div>
|
||||
</form>
|
||||
<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])
|
||||
{
|
||||
<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();
|
||||
AJAXSubmit(formelement, file);
|
||||
UPLOADSubmit(formelement, file);
|
||||
} else {
|
||||
var file = ev.dataTransfer.files[0];
|
||||
AJAXSubmit(formelement, file);
|
||||
UPLOADSubmit(formelement, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,11 +119,12 @@
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
const AJAXSubmit = async function (oFormElement, file = null) {
|
||||
const UPLOADSubmit = async function (oFormElement, file = null) {
|
||||
var fd = new FormData();
|
||||
if (file !== null) fd.append("file", file);
|
||||
else fd = new FormData(oFormElement);
|
||||
oFormElement.elements.namedItem("result").value = "Wait";
|
||||
document.getElementById("ha-lds-ellipsis").style.display = "inline-block";
|
||||
document.getElementById("ha-uploadmessage").style.opacity = "0";
|
||||
await fetch(oFormElement.action, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -68,12 +135,18 @@
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
if ("Error" in json) {
|
||||
oFormElement.elements.namedItem("result").value = json.Error;
|
||||
document.getElementById("ha-lds-ellipsis").style.display = "none";
|
||||
document.getElementById("ha-uploadmessage").style.opacity = "1";
|
||||
oFormElement.elements.namedItem("upload-result").value = json.Error;
|
||||
} else {
|
||||
oFormElement.elements.namedItem("result").value = "Erfolg!";
|
||||
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.error('Error:', error))
|
||||
.catch ((e) => console.log('Error:', e))
|
||||
}
|
||||
|
||||
function getCookie(name) {
|
||||
@@ -86,7 +159,7 @@
|
||||
var submitelement = document.getElementById("file");
|
||||
var formelement = document.getElementById("uploadForm");
|
||||
var dropzone = document.getElementById("dropzone");
|
||||
submitelement.addEventListener("change", () => AJAXSubmit(formelement));
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user