Skip to content

Commit

Permalink
#111 add client side handling for optional_max_amount_per_ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed May 22, 2017
1 parent d9f50ec commit a7300ae
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public boolean getLimitedAmount() {
getSupplementPolicy() == AdditionalService.SupplementPolicy.OPTIONAL_MAX_AMOUNT_PER_TICKET;
}

public boolean getMaxAmountPerTicket() {
return getSupplementPolicy() == AdditionalService.SupplementPolicy.OPTIONAL_MAX_AMOUNT_PER_TICKET;
}

public BigDecimal getVatPercentage() {
AdditionalService.VatType vatType = getVatType();
if(vatType == AdditionalService.VatType.INHERITED) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/webapp/WEB-INF/templates/event/additional-service.ms
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@
<input type="number" min="0" step="1" aria-labelledby="{{id}}-label" name="additionalService[{{index}}].quantity" class="form-control" placeholder="0" autocomplete="off">
{{/unlimitedAmount}}
{{#limitedAmount}}
<select aria-labelledby="{{id}}-label" name="additionalService[{{index}}].quantity" class="form-control text-align-center" placeholder="0" autocomplete="off">
{{#amountOfTickets}}<option value="{{this}}">{{this}}</option>{{/amountOfTickets}}
<select {{#maxAmountPerTicket}}data-max-amount-per-ticket="{{maxQtyPerOrder}}"{{/maxAmountPerTicket}} aria-labelledby="{{id}}-label" name="additionalService[{{index}}].quantity" class="form-control text-align-center" placeholder="0" autocomplete="off">
{{#maxAmountPerTicket}}
<option value="0">0</option>
{{/maxAmountPerTicket}}
{{^maxAmountPerTicket}}
{{#amountOfTickets}}<option value="{{this}}">{{this}}</option>{{/amountOfTickets}}
{{/maxAmountPerTicket}}
</select>
{{/limitedAmount}}
{{/fixPrice}}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/templates/event/ticket-category.ms
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<div class="col-sm-2 text-align-center">
{{#saleable}}
<input name="reservation[{{-index}}].ticketCategoryId" value="{{id}}" type="hidden">
<select aria-labelledby="{{id}}-label" name="reservation[{{-index}}].amount" class="form-control text-align-center" placeholder="0" autocomplete="off">
<select aria-labelledby="{{id}}-label" name="reservation[{{-index}}].amount" class="form-control text-align-center" placeholder="0" autocomplete="off" data-ticket-selector>
{{#accessRestricted}}
<option value="0">0</option>
<option value="1">1</option>
Expand Down
30 changes: 30 additions & 0 deletions src/main/webapp/resources/js/event/show-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@
$('#collapseOne').on('shown.bs.collapse', function () {
$('#promo-code').focus();
})

function countTotalTicketSelected() {
var selected = $("[data-ticket-selector]").map(function() {
return parseInt(this.value);
});
var tot = 0;
for(var i = 0; i < selected.length; i++) {
tot+=selected[i];
}
return tot;
}

function updateSelect(select, totalSelected) {
var maxAmount = parseInt($(select).attr('data-max-amount-per-ticket')) * totalSelected;
var options = [];
for(var i = 0; i <= maxAmount; i++) {
options.push($("<option value='"+i+"'>"+i+"</option>"));
}
var value = select.value;
$(select).empty();
$(select).append(options);
select.value = Math.min(value, maxAmount);
}

$("[data-ticket-selector]").change(function() {
var totalSelected = countTotalTicketSelected();
$("[data-max-amount-per-ticket]").each(function() {
updateSelect(this, totalSelected);
});
});
});

})();

0 comments on commit a7300ae

Please sign in to comment.