Format function now allows to choose source and target IDs

This commit is contained in:
2023-02-23 13:39:57 +01:00
parent 5db10ab1c1
commit 9bc3370f3b
2 changed files with 18 additions and 20 deletions

View File

@@ -96,18 +96,20 @@ function refreshTooltip() {
document.getElementById("xsltelementsheader").innerText = XSLTheader;
}
function performRequest(endpoint, checkXML, checkTransform){
var xmlData = document.getElementById("xmlArea").value.trim();
var transformData = document.getElementById("transformArea").value.trim();
var xmlData = document.getElementById(sourceId).value.trim();
var transformData = document.getElementById(targetId).value.trim();
var empty = false;
if (defaultStrings.includes(xmlData) && checkXML) {
document.getElementById("xmlArea").style.backgroundColor = color_red;
document.getElementById(sourceId).style.backgroundColor = color_red;
xmlData = "";
empty = true;
}
if (defaultStrings.includes(transformData) && checkTransform) {
document.getElementById("transformArea").style.backgroundColor = color_red;
document.getElementById(targetId).style.backgroundColor = color_red;
empty = true;
}
if (!empty) {
@@ -128,34 +130,30 @@ function performRequest(endpoint, checkXML, checkTransform){
}
function performFormatRequest(endpoint, checkXML){
var xmlData = document.getElementById("xmlArea").value.trim();
function performFormatRequest(endpoint, checkXML, sourceId, targetId){
var xmlData = document.getElementById(sourceId).value.trim();
var empty = false;
if (defaultStrings.includes(xmlData) && checkXML) {
document.getElementById("xmlArea").style.backgroundColor = color_red;
document.getElementById(sourceId).style.backgroundColor = color_red;
xmlData = "";
empty = true;
}
if (!empty) {
var result = restRequest(endpoint, xmlData, null);
document.getElementById("resultArea").value = result.result;
document.getElementById("procinfo").innerText = ' Computed using '.concat(" ", result.processor);
if (response.ok) {
document.getElementById("procinfo").innerText = document.getElementById("procinfo").innerText.concat(" in ", result.time, "ms");
procinfo.style.color = "#30aa58";
} else {
procinfo.style.color = "#aa3030";
}
restRequest(endpoint, xmlData, "").then(function(result) {
document.getElementById(targetId).value = result.result;
});
}else{
document.getElementById("resultArea").value = "No data provided!";
document.getElementById(targetId).value = "No data provided!";
return false;
}
}
//Form REST request, send, receive and display in resultArea
//Form REST request, send and return received data
async function restRequest(endpoint, xmlData, transformData) {
const escapeChar = "specialEscapeChar";
var port = ":8081/"

View File

@@ -29,9 +29,9 @@
onfocus="clearDefaultContent(this, 'Insert XML here');"></textarea>
<br><br>
<button id="requestButton" class="max-width block-label action-button active"
onclick="performFormatRequest('prettifypost', true)">Prettify XML</button>
onclick="performFormatRequest('prettifypost', true, 'xmlArea', 'resultArea')">Prettify XML</button>
<button id="requestButton" class="max-width block-label action-button active"
onclick="performFormatRequest('minimizepost', true)">Minimize XML</button>
onclick="performFormatRequest('minimizepost', true, 'xmlArea', 'resultArea')">Minimize XML</button>
<br><br>
<label for="resultArea"><b>Result:<span id="procinfo"></span></b></label>