mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Fixed Asset creation not including custom attributes
This commit is contained in:
@@ -263,62 +263,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</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>
|
<script>
|
||||||
/* Handle the attributes list for asset creation*/
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
const attributesContainer = document.getElementById('attributesContainer');
|
const attributesContainer = document.getElementById('attributesContainer');
|
||||||
const addAttributeBtn = document.getElementById('addAttributeBtn');
|
const addAttributeBtn = document.getElementById('addAttributeBtn');
|
||||||
|
|||||||
Reference in New Issue
Block a user