current state

This commit is contained in:
2023-05-15 18:49:02 +02:00
parent b5314cb552
commit 3b9813a680
23 changed files with 937 additions and 107 deletions

View File

@ -0,0 +1,6 @@
.magicalTriangle[aria-expanded=true] {
transform: rotate(180deg);
transition: transform 0.3s ease;
}
/*# sourceMappingURL=dashboard-mod.css.map */

View File

@ -0,0 +1 @@
{"version":3,"sourceRoot":"","sources":["../../src/sass/dashboard-mod.scss"],"names":[],"mappings":"AAAA;EACC;EACA","file":"dashboard-mod.css"}

View File

@ -105,3 +105,31 @@ body {
color: red;
transition: 1s;
}
/*
* Utilities
*/
.loader-overlay {
border-radius: var(--bs-modal-inner-border-radius);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.678);
z-index: 9999;
display: none;
}
.loader {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.loaderActive {
display: block !important;
}

View File

@ -1,12 +1,116 @@
function selectDataForEdit(id) {
const titleForm = document.getElementById('editCategoryModalName');
const descriptionForm = document.getElementById('editCategoryModalDescription');
const idForm = document.getElementById('editCategoryModalId');
const trData = document.getElementById('listEntry-' + id);
const title = trData.children[1].innerText;
const description = trData.children[2].innerText;
const idData = trData.children[0].innerText;
titleForm.value = title;
descriptionForm.value = description;
idForm.value = idData;
}
function getDataForEdit(name) {
$.ajax({
type: 'get',
url: `/api/v1/categories?name=${name}`,
success: function (data) {
const result = JSON.parse(data);
// Get elements inside the editCategoryModal
const modal_categoryName = document.getElementById('editCategoryModalName');
const modal_categoryDescription = document.getElementById('editCategoryModalDescription');
const modal_categoryid = document.getElementById('editCategoryModalId');
modal_categoryName.value = result.name;
modal_categoryDescription.value = result.description;
modal_categoryid.value = result.id;
},
error: function (data) {
console.log('!!!! ERROR !!!!', data);
// Hide overlay with spinner
$('.loader-overlay').removeClass('active');
// Close the modal
$('.modal').modal('hide');
$('#generalToast').removeClass('text-bg-primary');
$('#generalToast').addClass('text-bg-danger');
$('#generalToast').toast('show');
$('#generalToast').children('.d-flex').children('.toast-body').html('<i class="bi bi-exclamation-triangle-fill"></i> Something went wrong. The category does no longer exist.');
setTimeout(() => {
window.location.reload();
}, 3000);
}
});
}
function deleteEntry(id) {
$.ajax({
type: 'delete',
url: `/api/v1/categories`,
data: { id: id },
success: function (data) {
$('#staticBackdrop').modal('hide');
$('#generalToast').removeClass('text-bg-primary');
$('#generalToast').addClass('text-bg-success');
$('#generalToast').toast('show');
$('#generalToast').children('.d-flex').children('.toast-body').html('<i class="bi bi-check2"></i> Category deleted successfully.');
confetti({
spread: 360,
ticks: 100,
gravity: 0.1,
decay: 0.94,
startVelocity: 30,
particleCount: 20,
scalar: 2,
shapes: ['text'],
shapeOptions: {
text: {
value: ['❌', '🗑️', '🚫']
}
}
});
setTimeout(() => {
$('#generalToast').toast('hide');
$('#generalToast').removeClass('text-bg-success');
$('#generalToast').addClass('text-bg-primary');
window.location.reload();
}, 2000);
},
error: function (data) {
// hide the staticBackdrop modal
$('#staticBackdrop').modal('hide');
$('#generalToast').removeClass('text-bg-primary');
$('#generalToast').addClass('text-bg-danger');
$('#generalToast').toast('show');
$('#generalToast').children('.d-flex').children('.toast-body').html('<i class="bi bi-exclamation-triangle-fill"></i> Something went wrong. Please try again later.');
setTimeout(() => {
$('#generalToast').toast('hide');
$('#generalToast').removeClass('text-bg-danger');
$('#generalToast').addClass('text-bg-primary');
}, 3000);
}
});
}
function preFillDeleteModal(name) {
$.ajax({
type: 'get',
url: `/api/v1/categories?name=${name}`,
success: function (data) {
const result = JSON.parse(data);
// Get elements inside the editCategoryModal
const modal_categoryName = document.getElementById('deleteNamePlaceholder');
const modal_deleteButton = document.getElementById('deleteActionBtn');
//const modal_categoryDescription = document.getElementById('editCategoryModalDescription');
//const modal_categoryid = document.getElementById('editCategoryModalId');
modal_categoryName.innerText = result.name;
modal_deleteButton.setAttribute('onclick', `deleteEntry(${result.id})`);
//modal_categoryDescription.value = result.description;
//modal_categoryid.value = result.id;
},
error: function (data) {
console.log('!!!! ERROR !!!!', data);
document.getElementById('deleteNamePlaceholder').innerText = 'Deleted';
$('#staticBackdrop').modal('hide');
$('#generalToast').removeClass('text-bg-primary');
$('#generalToast').addClass('text-bg-danger');
$('#generalToast').toast('show');
$('#generalToast').children('.d-flex').children('.toast-body').html('<i class="bi bi-exclamation-triangle-fill"></i> Something went wrong. The category does no longer exist.');
setTimeout(() => {
window.location.reload();
}, 3000);
}
});
}

57
static/js/formHandler.js Normal file
View File

@ -0,0 +1,57 @@
$('.frontendForm').each(function() {
console.log('frontendForm found');
$(this).on('submit', function(e) {
e.preventDefault();
var form = $(this);
// Show overlay with spinner
$('.loader-overlay').addClass('loaderActive');
formData = form.serializeArray();
console.log(formData, $(this).attr('method'), $(this).attr('data-target'));
console.log('submitting form');
$.ajax({
type: $(this).attr('method'),
url: $(this).attr('data-target'),
data: formData,
dataType: 'json',
success: function(data) {
console.log('success');
// Hide overlay with spinner
$('.loader-overlay').removeClass('loaderActive');
// Close the modal
$('.modal').modal('hide');
// Clear all fields
form.find('input, textarea').val('');
$('#generalToast').removeClass('text-bg-primary');
$('#generalToast').addClass('text-bg-success');
$('#generalToast').toast('show');
$('#generalToast').children('.d-flex').children('.toast-body').html('<i class="bi bi-check2"></i> Changes saved successfully.');
setTimeout(() => {
$('#generalToast').toast('hide');;
$('#generalToast').removeClass('text-bg-success');
$('#generalToast').addClass('text-bg-primary');
window.location.reload();
}, 1500);
},
error: function(data) {
console.log('error');
// Hide overlay with spinner
$('.loader-overlay').removeClass('loaderActive');
$('#generalToast').removeClass('text-bg-primary');
$('#generalToast').addClass('text-bg-danger');
$('#generalToast').toast('show');
$('#generalToast').children('.d-flex').children('.toast-body').html('<i class="bi bi-exclamation-triangle-fill"></i> Something went wrong. Please try again later.');
setTimeout(() => {
$('#generalToast').toast('hide');
$('#generalToast').removeClass('text-bg-danger');
$('#generalToast').addClass('text-bg-primary');
}, 3000);
}
});
})
});