Fix condition text and quantity text

Closes #3
Closes #4
This commit is contained in:
2026-01-25 06:11:37 -06:00
parent 6ab872e8f1
commit 11402d9964
4 changed files with 50 additions and 25 deletions

View File

@@ -146,7 +146,11 @@
<span style="color: #64748b;">Out of Stock</span>
{% endif %}
{% endwith %}
<span id="stock-{{ card.uuid }}" class="stock-counter" data-card-id="{{ card.uuid }}" style="font-size: 0.75rem; color: #94a3b8; margin-left: auto;">...</span>
{% if card.total_quantity > 0 %}
<span style="font-size: 0.75rem; color: #10b981; margin-left: auto;">{{ card.total_quantity }} in stock</span>
{% else %}
<span style="font-size: 0.75rem; color: #ef4444; margin-left: auto;">Out of Stock</span>
{% endif %}
</div>
</div>
</a>
@@ -178,26 +182,5 @@
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const stockCounters = document.querySelectorAll('.stock-counter');
stockCounters.forEach(counter => {
const cardId = counter.getAttribute('data-card-id');
fetch(`/store/api/stock/${cardId}/`)
.then(response => response.json())
.then(data => {
if (data.total_stock > 0) {
counter.textContent = `${data.total_stock} in stock`;
counter.style.color = '#10b981'; // green
} else {
counter.textContent = 'Out of Stock';
counter.style.color = '#ef4444'; // red
}
})
.catch(err => {
counter.textContent = 'Stock unknown';
});
});
});
</script>
{% endblock %}