2023-07-10 17:50:31 +02:00
|
|
|
const FLAG_supports_new_data_loader = true;
|
|
|
|
|
2023-05-15 18:49:02 +02:00
|
|
|
function getDataForEdit(name) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'get',
|
|
|
|
url: `/api/v1/categories?name=${name}`,
|
2023-07-09 18:07:28 +02:00
|
|
|
success: function (result) {
|
2023-05-15 18:49:02 +02:00
|
|
|
// 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');
|
2023-05-17 17:46:51 +02:00
|
|
|
createNewToast('<i class="bi bi-exclamation-triangle-fill"></i> Something went wrong. The category does no longer exist.', "text-bg-danger")
|
2023-05-15 18:49:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-15 22:10:32 +02:00
|
|
|
function primeCreateNew() {
|
|
|
|
const form = document.getElementById('CategoryModalForm');
|
|
|
|
form.setAttribute('method', 'POST');
|
|
|
|
document.getElementById('editCategoryModalLabel').innerText = 'Create a new category';
|
2023-05-16 22:58:08 +02:00
|
|
|
$('.form-control').val('');
|
2023-05-15 22:10:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function primeEdit() {
|
|
|
|
const form = document.getElementById('CategoryModalForm');
|
|
|
|
document.getElementById('editCategoryModalLabel').innerText = 'Edit category';
|
|
|
|
form.setAttribute('method', 'PATCH');
|
|
|
|
return true;
|
|
|
|
}
|
2023-07-10 17:50:31 +02:00
|
|
|
|
|
|
|
const itemList = $('#itemList');
|
|
|
|
// itemList.empty();
|
|
|
|
itemList.bootstrapTable({ url: '/api/v1/categories', search: true, showRefresh: true, responseHandler: dataResponseHandler, sidePagination: 'server', serverSort: true, silentSort: false });
|
|
|
|
setTimeout(() => {
|
|
|
|
activateTooltips();
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
function loadPageData() {
|
|
|
|
itemList.bootstrapTable('refresh')
|
|
|
|
setTimeout(() => {
|
2023-07-10 18:18:38 +02:00
|
|
|
$(".tooltip").tooltip("hide");
|
2023-07-10 17:50:31 +02:00
|
|
|
activateTooltips();
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dataResponseHandler(json) {
|
|
|
|
// console.log(json)
|
|
|
|
totalNotFiltered = json.totalNotFiltered;
|
|
|
|
total = json.total;
|
|
|
|
json = json.items;
|
|
|
|
json.forEach((item) => {
|
|
|
|
item.actions = `
|
|
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#editCategoryModal" onclick="primeEdit(); getDataForEdit('${item.name}')">
|
|
|
|
<i class="bi bi-pencil"></i>
|
|
|
|
</button>
|
|
|
|
<button class="btn btn-danger" onclick="preFillDeleteModalNxt('${item.name}','categories','Category','name')" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
|
|
|
|
<i class="bi bi-trash"></i>
|
|
|
|
</button>`
|
|
|
|
});
|
|
|
|
///// --------------------------------- /////
|
|
|
|
setTimeout(() => {
|
|
|
|
activateTooltips();
|
|
|
|
}, 200);
|
|
|
|
return {"rows": json, total: total, totalNotFiltered: totalNotFiltered, totalRows: total};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
loadPageData()
|