66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
// renderer.js
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
console.log('DOM fully loaded. renderer.js is now running.');
|
|
|
|
// --- Real-time Filename Generation ---
|
|
const browseNameInput = document.getElementById('BrowseName');
|
|
const filenameDisplay = document.getElementById('output-filename-display');
|
|
|
|
const updateFilename = () => {
|
|
const browseName = browseNameInput.value;
|
|
if (browseName) {
|
|
// Sanitize the name for the file system
|
|
const safeBrowseName = browseName.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
filenameDisplay.textContent = `${safeBrowseName}.yml`;
|
|
} else {
|
|
filenameDisplay.textContent = ''; // Clear if BrowseName is empty
|
|
}
|
|
};
|
|
|
|
if (browseNameInput && filenameDisplay) {
|
|
// Listen for any input in the BrowseName field and update the display
|
|
browseNameInput.addEventListener('input', updateFilename);
|
|
// Initial call to set the name if the field is pre-filled
|
|
updateFilename();
|
|
}
|
|
|
|
const publicationDateInput = document.getElementById('publicationDate');
|
|
if (publicationDateInput) {
|
|
publicationDateInput.value = new Date().toISOString().split('T')[0];
|
|
}
|
|
|
|
const form = document.getElementById('machine-form');
|
|
if (form) {
|
|
form.addEventListener('submit', async (event) => {
|
|
event.preventDefault();
|
|
|
|
const formData = new FormData(form);
|
|
|
|
// The FormData API handles checkboxes and dropdowns with the same name identically.
|
|
// We just need to make sure the data object is built correctly.
|
|
const data = {};
|
|
for (const [key, value] of formData.entries()) {
|
|
// This check prevents multi-value fields from overwriting themselves
|
|
if (!data[key]) {
|
|
data[key] = value;
|
|
}
|
|
}
|
|
// Use .getAll('addins') to get an array of all CHECKED addins
|
|
data.addins = formData.getAll('addins');
|
|
|
|
console.log('Collected form data:', data);
|
|
|
|
try {
|
|
const result = await window.electronAPI.submitForm(data);
|
|
if (result.success) {
|
|
form.reset();
|
|
// ... (reset logic remains the same)
|
|
}
|
|
} catch (error) {
|
|
console.error('Error during form submission process:', error);
|
|
}
|
|
});
|
|
}
|
|
}); |