Fixed Asset creation not including custom attributes

This commit is contained in:
2025-10-10 11:22:39 +02:00
parent 2b5527a760
commit 220ef4d620

View File

@@ -263,62 +263,8 @@
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const createForm = document.getElementById('createAssetForm');
const createModalEl = document.getElementById('createAssetModal');
createForm.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(createForm);
const jsonData = {};
// Convert form data into nested JSON for AssetsCreateRequestModel
for (const [key, value] of formData.entries()) {
if (!value) continue;
const keys = key.split('.');
let target = jsonData;
for (let i = 0; i < keys.length - 1; i++) {
target[keys[i]] = target[keys[i]] || {};
target = target[keys[i]];
}
target[keys[keys.length - 1]] = value;
}
try {
const response = await fetch('/Assets/Create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(jsonData)
});
const result = await response.json();
if (result.success) {
const modal = bootstrap.Modal.getInstance(createModalEl);
modal.hide();
createForm.reset();
showToast('✅ Asset created successfully', 'success');
// Optional: reload page or dynamically add new row
// location.reload();
} else {
showToast(`❌ ${result.reason || 'Error creating asset'}`, 'danger');
}
} catch (error) {
console.error(error);
showToast('Error contacting server', 'danger');
}
});
});
</script>
<script>
/* Handle the attributes list for asset creation*/
document.addEventListener('DOMContentLoaded', () => {
const attributesContainer = document.getElementById('attributesContainer');
const addAttributeBtn = document.getElementById('addAttributeBtn');