console
This commit is contained in:
56
modules/pi_control/assets/hosts.js
Normal file
56
modules/pi_control/assets/hosts.js
Normal file
@@ -0,0 +1,56 @@
|
||||
(() => {
|
||||
const form = document.querySelector('[data-host-form]');
|
||||
if (!form) return;
|
||||
|
||||
const idInput = form.querySelector('input[name="id"]');
|
||||
const nameInput = form.querySelector('input[name="name"]');
|
||||
const hostInput = form.querySelector('input[name="host"]');
|
||||
const portInput = form.querySelector('input[name="port"]');
|
||||
const userInput = form.querySelector('input[name="username"]');
|
||||
const authSelect = form.querySelector('select[name="auth_type"]');
|
||||
const keyInput = form.querySelector('input[name="key_path"]');
|
||||
const passInput = form.querySelector('input[name="password"]');
|
||||
const imageInput = form.querySelector('input[name="image_url"]');
|
||||
const submitBtn = form.querySelector('[data-host-submit]');
|
||||
const cancelBtn = form.querySelector('[data-host-cancel]');
|
||||
|
||||
const resetForm = () => {
|
||||
if (idInput) idInput.value = '';
|
||||
if (nameInput) nameInput.value = '';
|
||||
if (hostInput) hostInput.value = '';
|
||||
if (portInput) portInput.value = '22';
|
||||
if (userInput) userInput.value = '';
|
||||
if (authSelect) authSelect.value = 'key';
|
||||
if (keyInput) keyInput.value = '';
|
||||
if (passInput) passInput.value = '';
|
||||
if (imageInput) imageInput.value = '';
|
||||
if (submitBtn) submitBtn.textContent = 'Speichern';
|
||||
};
|
||||
|
||||
document.querySelectorAll('[data-host-edit]').forEach((btn) => {
|
||||
btn.addEventListener('click', () => {
|
||||
const card = btn.closest('.host-card');
|
||||
if (!card) return;
|
||||
if (idInput) idInput.value = card.dataset.hostId || '';
|
||||
if (nameInput) nameInput.value = card.dataset.name || '';
|
||||
if (hostInput) hostInput.value = card.dataset.host || '';
|
||||
if (portInput) portInput.value = card.dataset.port || '22';
|
||||
if (userInput) userInput.value = card.dataset.username || '';
|
||||
if (authSelect) authSelect.value = card.dataset.auth || 'key';
|
||||
if (keyInput) keyInput.value = card.dataset.keyPath || '';
|
||||
if (passInput) passInput.value = '';
|
||||
if (imageInput) imageInput.value = card.dataset.imageUrl || '';
|
||||
if (submitBtn) submitBtn.textContent = 'Aktualisieren';
|
||||
const details = btn.closest('details');
|
||||
if (details) details.removeAttribute('open');
|
||||
form.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
});
|
||||
});
|
||||
|
||||
if (cancelBtn) {
|
||||
cancelBtn.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
resetForm();
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user