Frontend update
This commit is contained in:
77
static/js/editItems.js
Normal file
77
static/js/editItems.js
Normal file
@ -0,0 +1,77 @@
|
||||
|
||||
function primeCreateNew() {
|
||||
// Clear the form
|
||||
$('.form-control').val('');
|
||||
const form = document.getElementById('ItemModalForm');
|
||||
document.getElementById('itemModifyModalLabel').innerText= "Create a new item";
|
||||
form.setAttribute('method', 'POST');
|
||||
return true;
|
||||
}
|
||||
|
||||
function primeEdit() {
|
||||
const form = document.getElementById('ItemModalForm');
|
||||
document.getElementById('itemModifyModalLabel').innerText = 'Edit an item';
|
||||
form.setAttribute('method', 'PATCH');
|
||||
return true;
|
||||
}
|
||||
|
||||
function getDataForEdit(id) {
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: `/api/v1/items?id=${id}`,
|
||||
success: function (data) {
|
||||
const result = JSON.parse(data);
|
||||
|
||||
// Get elements inside the editCategoryModal
|
||||
const modal_itemName = document.getElementById('itemModifyModalName');
|
||||
const modal_itemComment = document.getElementById('itemModifyModalComment');
|
||||
const modal_itemAmount = document.getElementById('itemModifyModalAmount');
|
||||
const modal_itemSKU = document.getElementById('itemModifyModalSKU');
|
||||
const modal_itemStorageLocation = document.getElementById('itemModifyModalStorageLocation');
|
||||
const modal_itemManufacturer = document.getElementById('itemModifyModalManuf');
|
||||
const modal_itemCategory = document.getElementById('itemModifyModalCategory');
|
||||
const modal_itemStatus = document.getElementById('itemModifyModalStatus');
|
||||
const modal_itemid = document.getElementById('itemModifyModalId');
|
||||
|
||||
modal_itemName.value = result.name;
|
||||
modal_itemComment.value = result.comment;
|
||||
modal_itemAmount.value = result.amount;
|
||||
modal_itemSKU.value = result.SKU;
|
||||
modal_itemManufacturer.value = result.manufacturer;
|
||||
|
||||
// Select the correct option in the dropdown
|
||||
const modal_itemCategoryOptions = modal_itemCategory.options;
|
||||
for (let i = 0; i < modal_itemCategoryOptions.length; i++) {
|
||||
if (modal_itemCategoryOptions[i].value == result.category.id) {
|
||||
modal_itemCategoryOptions[i].selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Select the correct option in the dropdown
|
||||
const modal_itemStatusOptions = modal_itemStatus.options;
|
||||
for (let i = 0; i < modal_itemStatusOptions.length; i++) {
|
||||
if (modal_itemStatusOptions[i].value == result.status.id) {
|
||||
modal_itemStatusOptions[i].selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Select the correct option in the dropdown
|
||||
const modal_itemStorageLocationOptions = modal_itemStorageLocation.options;
|
||||
for (let i = 0; i < modal_itemStorageLocationOptions.length; i++) {
|
||||
if (modal_itemStorageLocationOptions[i].value == result.storageLocation.id) {
|
||||
modal_itemStorageLocationOptions[i].selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
modal_itemid.value = result.id;
|
||||
},
|
||||
error: function (data) {
|
||||
console.log('!!!! ERROR !!!!', data);
|
||||
// Hide overlay with spinner
|
||||
$('.loader-overlay').removeClass('active');
|
||||
// Close the modal
|
||||
$('.modal').modal('hide');
|
||||
createNewToast('<i class="bi bi-exclamation-triangle-fill"></i> Something went wrong. The category does no longer exist.', "text-bg-danger")
|
||||
}
|
||||
});
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
var amountOfForms = $('.frontendForm').length;
|
||||
$('.frontendForm').each(function () {
|
||||
// TODO Handle empty strings as null or undefined, not as ''
|
||||
$(this).on('submit', function (e) {
|
||||
e.preventDefault(); // Prevent the form from submitting via the browser
|
||||
|
||||
@ -108,7 +109,7 @@ function preFillDeleteModalNxt(id, route, name, requestIdent='id') {
|
||||
document.getElementById('deleteNamePlaceholder').innerText = 'Deleted';
|
||||
|
||||
$('#staticBackdrop').modal('hide');
|
||||
createNewToast(`<i class="bi bi-exclamation-triangle-fill"></i> Something went wrong. The ${name} does no longer exist.', "text-bg-danger`)
|
||||
createNewToast(`<i class="bi bi-exclamation-triangle-fill"></i> Something went wrong. The ${name} does no longer exist.`, `text-bg-danger`)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ const autocompleteBox = document.getElementById("autocomplete-items");
|
||||
autocompleteBox.style.display = "none";
|
||||
function handleSearchChange(e) {
|
||||
console.log(e.target.value);
|
||||
|
||||
// document.getElementById("SearchBox").setAttribute("data-bs-content", "Search results will show up here soon")
|
||||
|
||||
|
||||
return; // No you won't. I'm not done yet.
|
||||
// Check if known prefix is used (either > or #)
|
||||
if(e.target.value != "" ) {
|
||||
|
Reference in New Issue
Block a user