-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show a loader for running migrations (#84)
- Loading branch information
1 parent
0203e2f
commit ac634fa
Showing
7 changed files
with
85 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
document.addEventListener('DOMContentLoaded', function () { | ||
const migrationActions = document.querySelectorAll('.migration-action'); | ||
|
||
migrationActions.forEach(button => { | ||
button.addEventListener('click', function (event) { | ||
const originalText = button.value; | ||
button.value = 'Loading...'; | ||
disableButtons(); | ||
|
||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); | ||
|
||
fetch(event.target.form.action, { | ||
method: 'POST', | ||
headers: { | ||
'X-Requested-With': 'XMLHttpRequest', | ||
'X-CSRF-Token': csrfToken | ||
} | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
window.location.reload(); | ||
} else { | ||
throw new Error('Network response was not ok.'); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('There has been a problem with your fetch operation:', error); | ||
enableButtons(); | ||
button.value = originalText; | ||
}); | ||
|
||
event.preventDefault(); | ||
}); | ||
}); | ||
|
||
function disableButtons() { | ||
migrationActions.forEach(button => { | ||
button.disabled = true; | ||
}); | ||
} | ||
|
||
function enableButtons() { | ||
migrationActions.forEach(button => { | ||
button.disabled = false; | ||
}); | ||
} | ||
}); |
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
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
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
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
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
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