And that is that! Target number support is in.

This commit is contained in:
Yaro Kasear 2025-10-28 08:18:35 -05:00
parent 2845d340da
commit dc3482f887

View file

@ -175,6 +175,42 @@ dtlist.style.height = height;
dtlist.style.maxHeight = height; dtlist.style.maxHeight = height;
dtlist.style.minHeight = height; dtlist.style.minHeight = height;
document.querySelectorAll('.dt-target').forEach((el) => {
el.addEventListener('change', async (ev) => {
const num = ev.target.value;
const id = ev.target.parentElement.dataset.invId;
let res, data;
try {
const res = await fetch(`{{ url_for('crudkit.devicetype.rest_list') }}${id}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
credentials: 'same-origin',
body: JSON.stringify({target: num})
});
const ct = res.headers.get('Content-Type') || '';
if (ct.includes('application/json')) {
data = await res.json();
}
if (res.status !== 200) {
const msg = data?.error || `Create failed (${res.status})`;
toastMessage(msg, 'danger');
return;
}
} catch (err) {
toastMessage('Network error setting target number', 'danger');
return;
}
toastMessage('Updated target number.', 'success');
});
});
document.addEventListener('click', (ev) => { document.addEventListener('click', (ev) => {
const addButton = document.getElementById('add-devicetype'); const addButton = document.getElementById('add-devicetype');
const editButton = document.getElementById('edit-devicetype'); const editButton = document.getElementById('edit-devicetype');