mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
apps: Fix regression in enabling install button
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
parent
acd2f515d7
commit
bdf24d93cd
@ -27,7 +27,7 @@
|
|||||||
* create different rules when Javascript is available and when it is not. This
|
* create different rules when Javascript is available and when it is not. This
|
||||||
* functionality was provided by the Modernizr library earlier.
|
* functionality was provided by the Modernizr library earlier.
|
||||||
*/
|
*/
|
||||||
document.addEventListener('DOMContentLoaded', function(event) {
|
document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
const html = document.querySelector('html');
|
const html = document.querySelector('html');
|
||||||
html.classList.remove('no-js');
|
html.classList.remove('no-js');
|
||||||
html.classList.add('js');
|
html.classList.add('js');
|
||||||
@ -36,7 +36,7 @@ document.addEventListener('DOMContentLoaded', function(event) {
|
|||||||
/*
|
/*
|
||||||
* Refresh page if marked for refresh.
|
* Refresh page if marked for refresh.
|
||||||
*/
|
*/
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
const body = document.querySelector('body');
|
const body = document.querySelector('body');
|
||||||
if (body.hasAttribute('data-refresh-page-sec')) {
|
if (body.hasAttribute('data-refresh-page-sec')) {
|
||||||
let seconds = body.getAttribute('data-refresh-page-sec');
|
let seconds = body.getAttribute('data-refresh-page-sec');
|
||||||
@ -54,7 +54,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
/*
|
/*
|
||||||
* Return all submit buttons on the page
|
* Return all submit buttons on the page
|
||||||
*/
|
*/
|
||||||
function getSubmitButtons(){
|
function getSubmitButtons() {
|
||||||
return document.querySelectorAll(
|
return document.querySelectorAll(
|
||||||
"form input[type='submit'], form button[type='submit'].toggle-button");
|
"form input[type='submit'], form button[type='submit'].toggle-button");
|
||||||
}
|
}
|
||||||
@ -81,12 +81,12 @@ function onSubmitAddProgress(event) {
|
|||||||
// for the next event loop run which will happen after current event is
|
// for the next event loop run which will happen after current event is
|
||||||
// processed.
|
// processed.
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
if (button.tagName == "INPUT"){
|
if (button.tagName == "INPUT") {
|
||||||
// For push buttons
|
// For push buttons
|
||||||
const beforeElement = document.createElement('div');
|
const beforeElement = document.createElement('div');
|
||||||
beforeElement.classList.add('running-status-button-before');
|
beforeElement.classList.add('running-status-button-before');
|
||||||
button.parentNode.insertBefore(beforeElement, button);
|
button.parentNode.insertBefore(beforeElement, button);
|
||||||
} else if (button.tagName == "BUTTON"){
|
} else if (button.tagName == "BUTTON") {
|
||||||
// For toggle buttons
|
// For toggle buttons
|
||||||
button.classList.toggle('toggle-button--toggled');
|
button.classList.toggle('toggle-button--toggled');
|
||||||
}
|
}
|
||||||
@ -96,8 +96,8 @@ function onSubmitAddProgress(event) {
|
|||||||
// Disable all form submit buttons on the page
|
// Disable all form submit buttons on the page
|
||||||
for (const formbutton of getSubmitButtons()) {
|
for (const formbutton of getSubmitButtons()) {
|
||||||
if (!(formbutton.classList.contains('btn-link') ||
|
if (!(formbutton.classList.contains('btn-link') ||
|
||||||
formbutton.classList.contains('no-running-status') ||
|
formbutton.classList.contains('no-running-status') ||
|
||||||
formbutton.hasAttribute('disabled'))) {
|
formbutton.hasAttribute('disabled'))) {
|
||||||
formbutton.classList.add('temporarily-disabled');
|
formbutton.classList.add('temporarily-disabled');
|
||||||
formbutton.setAttribute('disabled', 'disabled');
|
formbutton.setAttribute('disabled', 'disabled');
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ function onSubmitAddProgress(event) {
|
|||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function(event) {
|
document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
for (const button of getSubmitButtons()) {
|
for (const button of getSubmitButtons()) {
|
||||||
// Don't listen for 'click' event on buttons as they are triggered
|
// Don't listen for 'click' event on buttons as they are triggered
|
||||||
// even when the form is invalid.
|
// even when the form is invalid.
|
||||||
@ -141,7 +141,7 @@ window.addEventListener('pageshow', clearButtonDisabling);
|
|||||||
/*
|
/*
|
||||||
* Select all option for multiple checkboxes.
|
* Select all option for multiple checkboxes.
|
||||||
*/
|
*/
|
||||||
document.addEventListener('DOMContentLoaded', function(event) {
|
document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
// Django < 4.0 generates <ul> and <li> where as Django >= 4.0 generates <div>s
|
// Django < 4.0 generates <ul> and <li> where as Django >= 4.0 generates <div>s
|
||||||
let parents = document.querySelectorAll('ul.has-select-all,div.has-select-all');
|
let parents = document.querySelectorAll('ul.has-select-all,div.has-select-all');
|
||||||
for (const parent of parents) {
|
for (const parent of parents) {
|
||||||
@ -225,12 +225,10 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
|
|
||||||
function setInstallButtonState(enable) {
|
function setInstallButtonState(enable) {
|
||||||
const installButton = document.querySelector('.install-button');
|
const installButton = document.querySelector('.install-button');
|
||||||
installButton?.setAttribute('disabled', !enable);
|
if (enable)
|
||||||
}
|
installButton?.removeAttribute('disabled')
|
||||||
|
else
|
||||||
function unavailable() {
|
installButton?.setAttribute('disabled', 'disabled');
|
||||||
document.querySelector('.app-unavailable').classList.remove('d-none');
|
|
||||||
setInstallButtonState(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
@ -253,7 +251,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
if (data.is_available === true) {
|
if (data.is_available === true) {
|
||||||
setInstallButtonState(true);
|
setInstallButtonState(true);
|
||||||
} else if (data.is_available === false) {
|
} else if (data.is_available === false) {
|
||||||
unavailable();
|
document.querySelector('.app-unavailable').classList.remove('d-none');
|
||||||
|
setInstallButtonState(false);
|
||||||
} else {
|
} else {
|
||||||
error();
|
error();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user