-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5576 from nextcloud/ernolf/submit-button-fix
feat: toggle submit button based on unsaved changes
- Loading branch information
Showing
3 changed files
with
233 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,60 @@ | ||
function makeOptionsFormSubmitVisible() { | ||
let optionsFormSubmit = document.getElementById("options-form-submit"); | ||
optionsFormSubmit.style.display = 'block'; | ||
} | ||
|
||
function handleTalkVisibility() { | ||
let talk = document.getElementById("talk"); | ||
let talkRecording = document.getElementById("talk-recording") | ||
if (talk.checked) { | ||
talkRecording.disabled = false | ||
} else { | ||
talkRecording.checked = false | ||
talkRecording.disabled = true | ||
} | ||
} | ||
|
||
function handleDockerSocketProxyWarning() { | ||
let dockerSocketProxy = document.getElementById("docker-socket-proxy"); | ||
if (dockerSocketProxy.checked) { | ||
alert('⚠️ Warning! Enabling this container comes with possible Security problems since you are exposing the docker socket and all its privileges to the Nextcloud container. Enable this only if you are sure what you are doing!') | ||
} | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function(event) { | ||
// handle submit button for options form | ||
let optionsFormSubmit = document.getElementById("options-form-submit"); | ||
document.addEventListener("DOMContentLoaded", function () { | ||
// Hide submit button initially | ||
const optionsFormSubmit = document.getElementById("options-form-submit"); | ||
optionsFormSubmit.style.display = 'none'; | ||
|
||
// Clamav | ||
let clamav = document.getElementById("clamav"); | ||
clamav.addEventListener('change', makeOptionsFormSubmitVisible); | ||
|
||
// OnlyOffice | ||
let onlyoffice = document.getElementById("onlyoffice"); | ||
if (onlyoffice) { | ||
onlyoffice.addEventListener('change', makeOptionsFormSubmitVisible); | ||
// Store initial states for all checkboxes | ||
const initialState = {}; | ||
const checkboxes = document.querySelectorAll("#options-form input[type='checkbox']"); | ||
|
||
checkboxes.forEach(checkbox => { | ||
initialState[checkbox.id] = checkbox.checked; // Use checked property to capture actual initial state | ||
}); | ||
|
||
// Function to compare current states to initial states | ||
function checkForChanges() { | ||
let hasChanges = false; | ||
|
||
checkboxes.forEach(checkbox => { | ||
if (checkbox.checked !== initialState[checkbox.id]) { | ||
hasChanges = true; | ||
} | ||
}); | ||
|
||
// Show or hide submit button based on changes | ||
optionsFormSubmit.style.display = hasChanges ? 'block' : 'none'; | ||
} | ||
|
||
// Collabora | ||
let collabora = document.getElementById("collabora"); | ||
collabora.addEventListener('change', makeOptionsFormSubmitVisible); | ||
|
||
// Talk | ||
let talk = document.getElementById("talk"); | ||
talk.addEventListener('change', makeOptionsFormSubmitVisible); | ||
talk.addEventListener('change', handleTalkVisibility); | ||
|
||
// Talk-recording | ||
let talkRecording = document.getElementById("talk-recording"); | ||
talkRecording.addEventListener('change', makeOptionsFormSubmitVisible); | ||
if (!talk.checked) { | ||
talkRecording.disabled = true | ||
// Event listener to trigger visibility check on each change | ||
checkboxes.forEach(checkbox => { | ||
checkbox.addEventListener("change", checkForChanges); | ||
}); | ||
|
||
// Custom behaviors for specific options | ||
function handleTalkVisibility() { | ||
const talkRecording = document.getElementById("talk-recording"); | ||
if (document.getElementById("talk").checked) { | ||
talkRecording.disabled = false; | ||
} else { | ||
talkRecording.checked = false; | ||
talkRecording.disabled = true; | ||
} | ||
checkForChanges(); // Check changes after toggling Talk Recording | ||
} | ||
|
||
// Imaginary | ||
let imaginary = document.getElementById("imaginary"); | ||
imaginary.addEventListener('change', makeOptionsFormSubmitVisible); | ||
function handleDockerSocketProxyWarning() { | ||
if (document.getElementById("docker-socket-proxy").checked) { | ||
alert('⚠️ Warning! Enabling this container comes with possible Security problems since you are exposing the docker socket and all its privileges to the Nextcloud container. Enable this only if you are sure what you are doing!'); | ||
} | ||
} | ||
|
||
// Fulltextsearch | ||
let fulltextsearch = document.getElementById("fulltextsearch"); | ||
fulltextsearch.addEventListener('change', makeOptionsFormSubmitVisible); | ||
// Initialize event listeners for specific behaviors | ||
document.getElementById("talk").addEventListener('change', handleTalkVisibility); | ||
document.getElementById("docker-socket-proxy").addEventListener('change', handleDockerSocketProxyWarning); | ||
|
||
// Docker socket proxy | ||
let dockerSocketProxy = document.getElementById("docker-socket-proxy"); | ||
if (dockerSocketProxy) { | ||
dockerSocketProxy.addEventListener('change', makeOptionsFormSubmitVisible); | ||
// dockerSocketProxy.addEventListener('change', handleDockerSocketProxyWarning); | ||
} | ||
// Initialize talk-recording visibility on page load | ||
handleTalkVisibility(); // Ensure talk-recording is correctly initialized | ||
|
||
// Whiteboard | ||
let whiteboard = document.getElementById("whiteboard"); | ||
whiteboard.addEventListener('change', makeOptionsFormSubmitVisible); | ||
// Initial call to check for changes | ||
checkForChanges(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.