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'); const modal_userinfo = document.getElementById('itemModifyModalContact'); 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.categoryId) { 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.statusId) { 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.storageLocationId) { modal_itemStorageLocationOptions[i].selected = true; } } modal_userinfo.selectedIndex = 0; // Select the correct option in the dropdown const modal_userInfoOptions = modal_userinfo.options; for (let i = 0; i < modal_userInfoOptions.length; i++) { if (modal_userInfoOptions[i].value == result.contactInfoId) { modal_userInfoOptions[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(' Something went wrong. The category does no longer exist.', "text-bg-danger") } }); }