Setup handleSubmit, handleSetDateTime, and handleReboot modularization with SettingsModal updates
This commit is contained in:
80
components/modales/setttingsModal/handlers/handleSubmit.js
Normal file
80
components/modales/setttingsModal/handlers/handleSubmit.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// handleSubmit.js
|
||||
const handleSubmit = ({
|
||||
name,
|
||||
originalValues,
|
||||
ip,
|
||||
subnet,
|
||||
gateway,
|
||||
ntp1,
|
||||
ntp2,
|
||||
ntp3,
|
||||
ntpTimezone,
|
||||
active,
|
||||
handleReboot,
|
||||
}) => {
|
||||
const changes = {};
|
||||
let networkChanges = false;
|
||||
|
||||
// Überprüfe, welche Werte sich geändert haben
|
||||
if (name !== originalValues.name) {
|
||||
changes.SNNA = name;
|
||||
networkChanges = true;
|
||||
}
|
||||
if (ip !== originalValues.ip) {
|
||||
changes.SEI01 = ip;
|
||||
networkChanges = true;
|
||||
}
|
||||
if (subnet !== originalValues.subnet) {
|
||||
changes.SEI02 = subnet;
|
||||
networkChanges = true;
|
||||
}
|
||||
if (gateway !== originalValues.gateway) {
|
||||
changes.SEI03 = gateway;
|
||||
networkChanges = true;
|
||||
}
|
||||
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) {
|
||||
let currentPath = window.location.pathname;
|
||||
if (!currentPath.endsWith(".html")) {
|
||||
currentPath += ".html";
|
||||
}
|
||||
|
||||
let url = `${window.location.origin}/CPL?${currentPath}`;
|
||||
Object.keys(changes).forEach((paramKey) => {
|
||||
url += `&${paramKey}=${encodeURIComponent(changes[paramKey])}`;
|
||||
});
|
||||
|
||||
fetch(url, { method: "GET" }).catch((error) => {
|
||||
console.error("Fehler beim Senden der Daten:", error);
|
||||
});
|
||||
|
||||
alert("Daten erfolgreich gesendet!");
|
||||
|
||||
if (networkChanges) {
|
||||
alert(
|
||||
"Hinweis: Die Änderungen in CPL-Name und den Netzwerkeinstellungen werden erst nach einem Neustart des CPL wirksam."
|
||||
);
|
||||
handleReboot();
|
||||
}
|
||||
} else {
|
||||
alert("Keine Änderungen vorgenommen.");
|
||||
}
|
||||
};
|
||||
|
||||
export default handleSubmit;
|
||||
Reference in New Issue
Block a user