From 62bcae49753dc9d86d1d2330dd9be28d4824c545 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Mon, 18 Nov 2019 21:58:25 +0530 Subject: [PATCH] app: Avoid showing empty configuration block Several applications whose configuration form only includes an "Enable application" checkbox look empty with an "Update setup" button when JavaScript is enabled. Fixed this. Added license header for LibreJS compliance. Signed-off-by: Joseph Nuthalapati --- static/themes/default/js/app.template.js | 58 +++++++++++++++++++----- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/static/themes/default/js/app.template.js b/static/themes/default/js/app.template.js index baa06a23c..7cfeea4ee 100644 --- a/static/themes/default/js/app.template.js +++ b/static/themes/default/js/app.template.js @@ -1,18 +1,54 @@ -const appForm = document.querySelector('#app-form') -const appToggleContainer = document.querySelector('#app-toggle-container') -const appToggleButton = document.querySelector('#app-toggle-button') -const appToggleInput = document.querySelector('#app-toggle-input') +/** + * @licstart The following is the entire license notice for the JavaScript + * code in this page. + * + * This file is part of FreedomBox. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * @licend The above is the entire license notice for the JavaScript code + * in this page. + */ + +const appForm = document.querySelector('#app-form'); +const appToggleContainer = document.querySelector('#app-toggle-container'); +const appToggleButton = document.querySelector('#app-toggle-button'); +const appToggleInput = document.querySelector('#app-toggle-input'); const onSubmit = (e) => { - e.preventDefault - appToggleInput.checked = !appToggleInput.checked - appForm.submit() -} -appToggleButton.addEventListener('click', onSubmit) + e.preventDefault; + appToggleInput.checked = !appToggleInput.checked; + appForm.submit(); +}; + +appToggleButton.addEventListener('click', onSubmit); /** * if javascript is enabled, this script will run and show the toggle button */ -appToggleInput.parentElement.style.display = 'none' -appToggleContainer.style.display = 'flex'; \ No newline at end of file +appToggleInput.parentElement.style.display = 'none'; +appToggleContainer.style.display = 'flex'; + +/* A basic form has only three elements: + * 1. An input tag with CSRF token + * 2. A div with form elements + * 3. A Submit button + * + * This kind of form can be completely hidden. +*/ +if (appForm.children.length === 3) { + appForm.style.display = 'none'; + appForm.previousElementSibling.style.display = 'none'; +}