diff --git a/public/assets/js/functions.js b/public/assets/js/functions.js index b8120e2..a82da41 100644 --- a/public/assets/js/functions.js +++ b/public/assets/js/functions.js @@ -30,8 +30,15 @@ function editAddress(id) { .then( response => response.text() ).then( - html => console.log(html) - ); + json => { + let jsonObject = JSON.parse(json) + if (jsonObject.status === 200) { + setInfo('Data successfully saved.') + } else { + setError(jsonObject.message); + } + } + ); document.getElementById('first_' + id).disabled = true document.getElementById('last_' + id).disabled = true @@ -66,8 +73,15 @@ function deleteAddress(id) { .then( response => response.text() ).then( - html => console.log(html) - ); + json => { + let jsonObject = JSON.parse(json) + if (jsonObject.status === 200) { + setInfo('Data successfully saved.') + } else { + setError(jsonObject.message); + } + } + ); let row = document.getElementById('row_' + id) row.parentNode.removeChild(row) } @@ -132,6 +146,43 @@ function sortBy(column) { } } + +function setInfo(info) { + const infoBox = document.getElementById('info_box') + infoBox.innerHTML = info + infoBox.style.display = 'block' + infoBox.classList.add('panel_float') + setTimeout(() => { + infoBox.style.display = 'none' + }, 2500) +} + +function setError(error) { + const errorBox = document.getElementById('error_box') + const errorText = document.getElementById('error_text') + const infoButton = document.getElementById('info_button') + if (errorBox.style.display === 'block') { + errorBox.style.display = 'none' + return + } + if (infoButton != null) { + infoButton.disabled = true + } + errorText.innerHTML = error + errorBox.style.display = 'block' + errorBox.classList.add('panel_float') +} + +function closeError() { + const errorBox = document.getElementById('error_box') + const infoButton = document.getElementById('info_button') + if (infoButton) { + infoButton.disabled = false + } + errorBox.style.display = 'none' + +} + document.addEventListener('DOMContentLoaded', () => { const table = document.getElementById('address_table') || false if (table) {