// HEJ MOR
function scrollToElement(elementId)
{
const elm = document.getElementById(elementId);
console.log(elementId + ' -> ' + elm);
if (elm !== null)
{
document.getElementById(elementId).scrollIntoView({
behavior: 'auto',
block: 'center',
inline: 'center'
});
}
}
function formDataToJSONWithMaps(formData) {
const data = {};
for (const [key, value] of formData.entries()) {
//console.log('key = \\\"' + key + '\\\", value = \\\"' + value + '\\\"');
const match = key.match(/^(.+)\[(.+)\]$/); // Match pattern with variable name and index
if (match) {
const varName = match[1];
const index = match[2];
console.log('varName = "' + varName + '", index = "' + index + '"');
// Create map for variable if it doesn't exist
if (!data[varName]) {
data[varName] = {};
}
data[varName][index] = value;
} else {
data[key] = value; // Handle regular key-value pairs
}
console.log(data);
}
const json = JSON.stringify(data);
console.log(data, json);
return json;
}
function setJson(form) {
try {
document.getElementById('json').value = formDataToJSONWithMaps(new FormData(form));
return (1==1);
} catch (error) {
console.log('FUCK: ' + error)
return (1==0);
}
}
function showErrorDialog(errors)
{
if (errors == '') {
return;
}
var errorDialog = document.getElementById('errorDialog');
if (typeof errorDialog.showModal === "function") {
errorDialog.style.visibility = 'visible';
var html = errors.replace(/#/g, '
');
document.getElementById('error').innerHTML = html;
errorDialog.showModal();
}
else {
alert(errors.replace(/@/g, '\\n'));
}
}
function localDateTimeToString(ldtArray)
{
var res = '';
res += ldtArray[2] + '/' + ldtArray[1] + '-' + ldtArray[0] + ' ';
res += ('' + ldtArray[3]).padStart(2, '0') + ':' + ('' + ldtArray[4]).padStart(2, '0');
return res;
}