add to inventroy
This commit is contained in:
@@ -69,8 +69,7 @@
|
||||
{% endif %}
|
||||
|
||||
<button class="btn btn-success btn-sm"
|
||||
onclick="addToInventory({{ loop.index0 }})"
|
||||
data-item="{{ item | tojson | e }}">
|
||||
onclick="addToInventory({{ loop.index0 }})">
|
||||
📦 Add to Inventory
|
||||
</button>
|
||||
</div>
|
||||
@@ -143,6 +142,7 @@
|
||||
<script>
|
||||
let currentMediaItem = null;
|
||||
let storageLocations = [];
|
||||
let searchResults = {{ results | tojson | safe }};
|
||||
|
||||
// Load storage locations when page loads
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
@@ -185,11 +185,18 @@ function updateLocationDropdown() {
|
||||
}
|
||||
|
||||
function addToInventory(itemIndex) {
|
||||
// Get the item data from the button's data attribute
|
||||
const buttons = document.querySelectorAll('[data-item]');
|
||||
const button = buttons[itemIndex];
|
||||
const itemData = JSON.parse(button.getAttribute('data-item'));
|
||||
console.log('addToInventory called with index:', itemIndex);
|
||||
console.log('searchResults:', searchResults);
|
||||
|
||||
// Get the item data from the global search results array
|
||||
if (!searchResults || itemIndex >= searchResults.length) {
|
||||
console.error('Invalid item index or no search results');
|
||||
showError('Invalid item selected');
|
||||
return;
|
||||
}
|
||||
|
||||
const itemData = searchResults[itemIndex];
|
||||
console.log('Selected item:', itemData);
|
||||
currentMediaItem = itemData;
|
||||
|
||||
// Populate item details
|
||||
@@ -217,8 +224,21 @@ function addToInventory(itemIndex) {
|
||||
document.getElementById('quantity').value = '1';
|
||||
|
||||
// Show modal
|
||||
const modal = new bootstrap.Modal(document.getElementById('addToInventoryModal'));
|
||||
modal.show();
|
||||
try {
|
||||
const modalElement = document.getElementById('addToInventoryModal');
|
||||
if (!modalElement) {
|
||||
console.error('Modal element not found');
|
||||
showError('Modal not found');
|
||||
return;
|
||||
}
|
||||
|
||||
const modal = new bootstrap.Modal(modalElement);
|
||||
modal.show();
|
||||
console.log('Modal shown successfully');
|
||||
} catch (error) {
|
||||
console.error('Error showing modal:', error);
|
||||
showError('Error opening inventory modal');
|
||||
}
|
||||
}
|
||||
|
||||
async function submitToInventory() {
|
||||
@@ -276,9 +296,17 @@ async function submitToInventory() {
|
||||
|
||||
function showError(message) {
|
||||
const errorDiv = document.getElementById('inventoryError');
|
||||
errorDiv.textContent = message;
|
||||
errorDiv.classList.remove('d-none');
|
||||
document.getElementById('inventorySuccess').classList.add('d-none');
|
||||
if (errorDiv) {
|
||||
errorDiv.textContent = message;
|
||||
errorDiv.classList.remove('d-none');
|
||||
const successDiv = document.getElementById('inventorySuccess');
|
||||
if (successDiv) {
|
||||
successDiv.classList.add('d-none');
|
||||
}
|
||||
} else {
|
||||
// Fallback to alert if modal error div not found
|
||||
alert('Error: ' + message);
|
||||
}
|
||||
}
|
||||
|
||||
function showSuccess(message) {
|
||||
|
Reference in New Issue
Block a user