Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve menu form #527

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 51 additions & 45 deletions stregsystem/templates/stregsystem/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@
padding-top: .8em;
padding-bottom: 1em;
}
#productlist {
#product-buy-form {
padding-bottom: 1em;

& button {
background: none;
border: none;
cursor: pointer;
font: inherit;
text-decoration: underline;
color: LinkText;

&:active{
color: ActiveText;
}
}
}
</style>
{% endblock %}
Expand Down Expand Up @@ -76,58 +89,51 @@ <h4>Du
{% endblock %}
</div>

<div id="productlist" class="horizontal-table">
{% block products %}
{% autoescape off %}
{% if product_list %}
<table class="default">
<tr>
<th>Produkt</th>
<th>Pris</th>
</tr>
{% for product in product_list|partition:"2"|first %}
<tr>
<td>
<form method="post" action="/{{ room.id }}/sale/{{ member.id }}/">
{% csrf_token %}
<a href="" onclick="this.closest('form').submit();return false;">{{product.name}}</a>
<input type="hidden" value="{{ product.id }}" name="product_id">
<input type="hidden" value="{{ room.id }}" name="room_id">
<input type="hidden" value="{{ member.id }}" name="member_id">
</form>
</td>
<td class="price">{{product.price|money}} kr</td>
</tr>
{% endfor %}
</table>
{% if product_list|partition:"2"|last %}
{% block products %}
{% autoescape off %}
{% if product_list %}
<form method="post" action="/{{ room.id }}/sale/{{ member.id }}/" id="product-buy-form" name="product-buy-form">
{% csrf_token %}
<input type="hidden" value="{{ room.id }}" name="room_id">
<input type="hidden" value="{{ member.id }}" name="member_id">
<div class="horizontal-table">
<table class="default">
<tr>
<th>Produkt</th>
<th>Pris</th>
</tr>
{% for product in product_list|partition:"2"|last %}
<tr>
<td>
<form method="post" action="/{{ room.id }}/sale/{{ member.id }}/">
{% csrf_token %}
<a href="" onclick="this.closest('form').submit();return false;">{{product.name}}</a>
<input type="hidden" value="{{ product.id }}" name="product_id">
<input type="hidden" value="{{ room.id }}" name="room_id">
<input type="hidden" value="{{ member.id }}" name="member_id">
</form>
</td>
<td class="price">{{product.price|money}} kr</td>
</tr>
{% for product in product_list|partition:"2"|first %}
<tr>
<td>
<button value="{{ product.id }}" name="product_id">{{product.name}}</button>
</td>
<td class="price">{{product.price|money}} kr</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% else %}
<p>Ingen produkter.</p>
{% if product_list|partition:"2"|last %}
<table class="default">
<tr>
<th>Produkt</th>
<th>Pris</th>
</tr>
{% for product in product_list|partition:"2"|last %}
<tr>
<td>
<button value="{{ product.id }}" name="product_id">{{product.name}}</button>
</td>
<td class="price">{{product.price|money}} kr</td>
</tr>
{% endfor %}
</table>
</div>
</form>
{% endif %}
{% endautoescape %}
{% endblock %}
</div>
{% else %}
<p>Ingen produkter.</p>
{% endif %}
{% endautoescape %}
{% endblock %}
<br />
{% include "stregsystem/purchase_heatmap.html" %}
</main>
Expand Down
4 changes: 2 additions & 2 deletions stregsystem/templates/stregsystem/purchase_heatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ <h2 class="heatmap-header-title">Forbrugsoversigt (Antal)</h2>
}

function updateAllProductNumbers(hide=false){
document.querySelectorAll("input[name='product_id']")
document.querySelectorAll("button[name='product_id']")
.forEach(p => changeProductCountElement(p.parentElement, 0, hide))
}

Expand Down Expand Up @@ -184,7 +184,7 @@ <h2 class="heatmap-header-title">Forbrugsoversigt (Antal)</h2>
}

for (const [product_id, count] of Object.entries(product_counts)){
const productCountElement = document.querySelector(`input[name='product_id'][value='${product_id}']`)?.parentElement;
const productCountElement = document.querySelector(`button[name='product_id'][value='${product_id}']`)?.parentElement;

if (productCountElement === undefined){
console.warn(`Product doesn't exist in tabel: ${product_id}`);
Expand Down
Loading