|
|
@ -182,7 +182,7 @@ function generateTemplateDOM(index, template) {
|
|
|
|
cropReadCell.innerText = `(${crop[0]}, ${crop[1]}) to (${crop[2]}, ${crop[3]})`;
|
|
|
|
cropReadCell.innerText = `(${crop[0]}, ${crop[1]}) to (${crop[2]}, ${crop[3]})`;
|
|
|
|
const cropEditCell = document.createElement("div");
|
|
|
|
const cropEditCell = document.createElement("div");
|
|
|
|
cropEditCell.classList.add("template-data-edit", "hidden");
|
|
|
|
cropEditCell.classList.add("template-data-edit", "hidden");
|
|
|
|
|
|
|
|
|
|
|
|
const cropXStartField = document.createElement("input");
|
|
|
|
const cropXStartField = document.createElement("input");
|
|
|
|
cropXStartField.name = "cropxstart";
|
|
|
|
cropXStartField.name = "cropxstart";
|
|
|
|
setCoordNumberFieldProps(cropXStartField, "X");
|
|
|
|
setCoordNumberFieldProps(cropXStartField, "X");
|
|
|
@ -213,7 +213,7 @@ function generateTemplateDOM(index, template) {
|
|
|
|
cropEditCell.appendChild(document.createTextNode(", "));
|
|
|
|
cropEditCell.appendChild(document.createTextNode(", "));
|
|
|
|
cropEditCell.appendChild(cropYEndField);
|
|
|
|
cropEditCell.appendChild(cropYEndField);
|
|
|
|
cropEditCell.appendChild(document.createTextNode(")"));
|
|
|
|
cropEditCell.appendChild(document.createTextNode(")"));
|
|
|
|
|
|
|
|
|
|
|
|
cropCell.appendChild(cropReadCell);
|
|
|
|
cropCell.appendChild(cropReadCell);
|
|
|
|
cropCell.appendChild(cropEditCell);
|
|
|
|
cropCell.appendChild(cropEditCell);
|
|
|
|
|
|
|
|
|
|
|
@ -282,7 +282,7 @@ function generateTemplateDOM(index, template) {
|
|
|
|
editReadCell.classList.add("template-data-view");
|
|
|
|
editReadCell.classList.add("template-data-view");
|
|
|
|
const switchToEditButton = document.createElement("button");
|
|
|
|
const switchToEditButton = document.createElement("button");
|
|
|
|
switchToEditButton.type = "button";
|
|
|
|
switchToEditButton.type = "button";
|
|
|
|
switchToEditButton.innerText = "Edit"
|
|
|
|
switchToEditButton.innerText = "Edit";
|
|
|
|
editReadCell.appendChild(switchToEditButton);
|
|
|
|
editReadCell.appendChild(switchToEditButton);
|
|
|
|
const editEditCell = document.createElement("div");
|
|
|
|
const editEditCell = document.createElement("div");
|
|
|
|
editEditCell.classList.add("template-data-edit", "hidden");
|
|
|
|
editEditCell.classList.add("template-data-edit", "hidden");
|
|
|
@ -356,9 +356,9 @@ function generateTemplateDOM(index, template) {
|
|
|
|
description: description,
|
|
|
|
description: description,
|
|
|
|
attribution: attribution,
|
|
|
|
attribution: attribution,
|
|
|
|
crop: [cropXStart, cropYStart, cropXEnd, cropYEnd],
|
|
|
|
crop: [cropXStart, cropYStart, cropXEnd, cropYEnd],
|
|
|
|
location: [locXStart, locYStart, locXEnd, locYEnd]
|
|
|
|
location: [locXStart, locYStart, locXEnd, locYEnd],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const imageFiles = imageEditField.files;
|
|
|
|
const imageFiles = imageEditField.files;
|
|
|
|
if (imageFiles.length > 0) {
|
|
|
|
if (imageFiles.length > 0) {
|
|
|
|
const fileReader = new FileReader();
|
|
|
|
const fileReader = new FileReader();
|
|
|
@ -367,7 +367,7 @@ function generateTemplateDOM(index, template) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
fileReader.readAsDataURL(imageFile);
|
|
|
|
fileReader.readAsDataURL(imageFile);
|
|
|
|
await fileReaderCompletePromise;
|
|
|
|
await fileReaderCompletePromise;
|
|
|
|
|
|
|
|
|
|
|
|
const imageDataURL = fileReader.result;
|
|
|
|
const imageDataURL = fileReader.result;
|
|
|
|
if (imageDataURL.startsWith("data:image/png;base64,")) {
|
|
|
|
if (imageDataURL.startsWith("data:image/png;base64,")) {
|
|
|
|
submitData.image = imageDataURL.substring(22);
|
|
|
|
submitData.image = imageDataURL.substring(22);
|
|
|
@ -384,10 +384,14 @@ function generateTemplateDOM(index, template) {
|
|
|
|
if (editErrors.hasChildNodes()) {
|
|
|
|
if (editErrors.hasChildNodes()) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const origName = templateData[index].name;
|
|
|
|
const origName = templateData[index].name;
|
|
|
|
const encodedName = encodeURIComponent(origName);
|
|
|
|
const encodedName = encodeURIComponent(origName);
|
|
|
|
const submitResponse = await fetch(`/thrimshim/update-template/${encodedName}`, { method: "POST", body: JSON.stringify(submitData), headers: { "Content-Type": "application/json" }});
|
|
|
|
const submitResponse = await fetch(`/thrimshim/update-template/${encodedName}`, {
|
|
|
|
|
|
|
|
method: "POST",
|
|
|
|
|
|
|
|
body: JSON.stringify(submitData),
|
|
|
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
|
|
|
});
|
|
|
|
if (!submitResponse.ok) {
|
|
|
|
if (!submitResponse.ok) {
|
|
|
|
const submitError = document.createElement("li");
|
|
|
|
const submitError = document.createElement("li");
|
|
|
|
submitError.innerText = await submitResponse.text();
|
|
|
|
submitError.innerText = await submitResponse.text();
|
|
|
@ -407,7 +411,7 @@ function generateTemplateDOM(index, template) {
|
|
|
|
const templateDOM = generateTemplateDOM(index, templateData[index]);
|
|
|
|
const templateDOM = generateTemplateDOM(index, templateData[index]);
|
|
|
|
templateRow.replaceWith(templateDOM);
|
|
|
|
templateRow.replaceWith(templateDOM);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return templateRow;
|
|
|
|
return templateRow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|