Files
CPLv4.0/components/modales/settingsModal/handlers/handleSubmit.js
ISA 589c8a0e9e feat: Modularize KueModal component by extracting handler functions
- Moved `handleSave`, `handleChange`, `handleDisplayEinschalten`, `handleSetDateTime`, `handleClearDatabase`, and `handleReboot` to separate handler files for better modularity and code organization.
- Updated imports in `KueModal.jsx` and `SettingsModal.jsx` to use new handler files.
- Improved code readability and maintainability by organizing functions into dedicated handler modules.
2024-11-09 19:29:33 +01:00

71 lines
1.9 KiB
JavaScript

// components/modales/handlers/handleSubmit.js
const handleSubmit = (originalValues, currentValues) => {
const changes = {};
// Überprüfe, welche Werte sich geändert haben
if (name !== originalValues.name) {
changes.SNNA = name;
}
if (ip !== originalValues.ip) {
changes.SEI01 = ip;
}
if (subnet !== originalValues.subnet) {
changes.SEI02 = subnet;
}
if (gateway !== originalValues.gateway) {
changes.SEI03 = gateway;
}
if (ntp1 !== originalValues.ntp1) {
changes.SNIP1 = ntp1;
}
if (ntp2 !== originalValues.ntp2) {
changes.SNIP2 = ntp2;
}
if (ntp3 !== originalValues.ntp3) {
changes.SNIP3 = ntp3;
}
if (ntpTimezone !== originalValues.ntpTimezone) {
changes.SNTZ = ntpTimezone;
}
if (active !== originalValues.active) {
changes.SNAC = active;
}
// Falls Änderungen vorhanden sind, sende die neuen Daten
if (Object.keys(changes).length > 0) {
// Get the current path and ensure it ends with ".html"
let currentPath = window.location.pathname;
if (!currentPath.endsWith(".html")) {
currentPath += ".html";
}
// Full URL with host, current path, and all change parameters
let url = `${window.location.origin}/CPL?${currentPath}`;
Object.keys(changes).forEach((paramKey) => {
url += `&${paramKey}=${encodeURIComponent(changes[paramKey])}`;
});
// Log the full URL to the console for debugging
console.log(url);
// Send the URL with changes to the server
fetch(url, { method: "GET" })
.then((response) => {
if (response.ok) {
alert("Daten erfolgreich gesendet!");
} else {
alert("Fehler beim Senden der Daten!");
}
})
.catch((error) => {
console.error("Fehler:", error);
alert("Fehler beim Senden der Daten!");
});
} else {
alert("Keine Änderungen vorgenommen.");
}
};
export default handleSubmit;