Skip to content

Commit

Permalink
Clean up formatting and automatically fill in auto-buy price
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryf0x committed Dec 28, 2023
1 parent 89a405b commit ddd0616
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
1 change: 1 addition & 0 deletions artshow/bid_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def get_bids(piece):
'last_updated': bids_updated,
'location': piece.location,
'locations': piece.artist.assigned_locations(),
'buy_now': piece.buy_now,
})


Expand Down
45 changes: 35 additions & 10 deletions artshow/static/artshow/bid_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,31 @@ document.addEventListener('DOMContentLoaded', () => {
pieceIdField.addEventListener('input', clearFields);
locationSelect.addEventListener('input', setNotSaved);
buyNowCheckbox.addEventListener('input', setNotSaved);
buyNowCheckbox.addEventListener('input', toggleDisableOnNonBuyNowElements);
buyNowCheckbox.addEventListener('input', toggleBuyNowBid);
for (var i = 0; i < bidderFields.length; ++i) {
bidderFields[i].addEventListener('input', setNotSaved);
bidFields[i].addEventListener('input', setNotSaved);
}
});

function toggleDisableOnNonBuyNowElements() {
const maybeDisabled = !!buyNowCheckbox.checked;
const nFields = bidderFields.length;
for (var i = 1; i < nFields; i++) {
/* for every bidder but the first bidder */
bidderFields[i].disabled = maybeDisabled;
bidFields[i].disabled = maybeDisabled;
function toggleBuyNowBid() {
/* for every bidder but the first bidder */
for (var i = 1; i < bidderFields.length; i++) {
bidderFields[i].disabled = buyNowCheckbox.checked;
bidFields[i].disabled = buyNowCheckbox.checked;
if (buyNowCheckbox.checked) {
bidderFields[i].value = '';
bidFields[i].value = '';
}
}
/**
* we still need the first bidder's bidder ID but can automatically populate
* the buy-now price
*/
bidFields[0].disabled = buyNowCheckbox.checked;
if (buyNowCheckbox.checked) {
bidFields[0].value = buyNowPrice;
}
/* we still need the first bidder's bidder ID */
bidFields[0].disabled = maybeDisabled;
}

function updateBids(json, newStatus) {
Expand All @@ -66,9 +74,22 @@ function updateBids(json, newStatus) {
bidderFields[i].value = json.bids[i].bidder;
bidFields[i].value = json.bids[i].bid;
}

if (length >= 1) {
buyNowCheckbox.checked = json.bids[0].buy_now_bid;
}
if (buyNowCheckbox.checked) {
bidFields[0].disabled = true;
for (var i = 1; i < bidderFields.length; ++i) {
bidderFields[i].disabled = true;
bidFields[i].disabled = true;
}
}

buyNowPrice = json.buy_now;
if (buyNowPrice) {
buyNowCheckbox.disabled = false;
}

while (locationSelect.firstChild) {
locationSelect.removeChild(locationSelect.firstChild);
Expand Down Expand Up @@ -113,8 +134,10 @@ function setNotSaved() {

function clearFields() {
for (var i = 0; i < bidderFields.length; ++i) {
bidderFields[i].disabled = false;
bidderFields[i].value = '';
bidFields[i].value = '';
bidFields[i].disabled = false;
}
while (locationSelect.firstChild) {
locationSelect.removeChild(locationSelect.firstChild);
Expand All @@ -124,6 +147,8 @@ function clearFields() {
emptyLocation.textContent = '---';
locationSelect.appendChild(emptyLocation);
buyNowCheckbox.checked = false;
buyNowCheckbox.disabled = true;
buyNowPrice = undefined;
statusText.textContent = '';
}

Expand Down
2 changes: 1 addition & 1 deletion artshow/static/artshow/bid_sheets.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ body {
height: 1in;
display: grid;
grid-template-rows: repeat(4, 1fr);
text-align: center;
}

.bid-info div {
Expand Down Expand Up @@ -93,6 +92,7 @@ body {

.bid-sticker span {
display: table-cell;
padding: 5px;
vertical-align: middle;
}

Expand Down
7 changes: 4 additions & 3 deletions artshow/templates/artshow/bid_sheets.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load static %}
{% load humanize %}
<html>
<head>
<title>Art Show Bid Sheets {% if artist %}({{ artist.name }}){% endif %}</title>
Expand All @@ -12,9 +13,9 @@
<div class="bid-info">
{% if not piece.not_for_sale %}
<div class="label">Minimum Bid</div>
<div>${{ piece.min_bid }}</div>
<div>${{ piece.min_bid|intcomma }}</div>
<div class="label">Auto Buy</div>
<div>{% if piece.buy_now %}1st bid only; please see below{% else %}N/A{% endif %}</div>
<div>{% if piece.buy_now %}1st bid only{% else %}N/A{% endif %}</div>
{% endif %}
</div>
<div class="piece-id">{{ piece.code }}</div>
Expand All @@ -36,7 +37,7 @@
</div>
{% else %}
<div class="bid-stickers">
<div class="bid-sticker"><span>Place 1st bid{% if piece.buy_now %} or auto buy of ${{ piece.buy_now }}{% endif %} here.</span></div>
<div class="bid-sticker"><span>Place 1st bid here{% if piece.buy_now %}, or auto buy for ${{ piece.buy_now|intcomma }}{% endif %}.</span></div>
<div class="bid-sticker"><span>Place 2nd bid here.</span></div>
<div class="bid-sticker"><span>Place 3rd bid here.</span></div>
<div class="bid-sticker"><span>Place 4th bid here.</span></div>
Expand Down
1 change: 1 addition & 0 deletions artshowjockey/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
'tinyreg',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.humanize',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
Expand Down

0 comments on commit ddd0616

Please sign in to comment.