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