Skip to content

Commit e0fcf78

Browse files
committed
Added quantity support for donations & fixed bugs
Prevent zero donations Added validation
1 parent 539cc20 commit e0fcf78

File tree

5 files changed

+76
-36
lines changed

5 files changed

+76
-36
lines changed

app/components/forms/wizard/basic-details-step.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,40 @@ export default Component.extend(FormMixin, EventWizardMixin, {
269269
}
270270
]
271271
},
272+
ticketMinPrice: {
273+
identifier : 'min_price',
274+
rules : [
275+
{
276+
type : 'empty',
277+
prompt : this.l10n.t('Minimum price for donation tickets required')
278+
},
279+
{
280+
type : 'number',
281+
prompt : this.l10n.t('Invalid number')
282+
},
283+
{
284+
type : 'integer[1..]',
285+
prompt : this.l10n.t('Ticket price should be greater than 0')
286+
}
287+
]
288+
},
289+
ticketMaxPrice: {
290+
identifier : 'max_price',
291+
rules : [
292+
{
293+
type : 'empty',
294+
prompt : this.l10n.t('Maximum price for donation tickets required')
295+
},
296+
{
297+
type : 'number',
298+
prompt : this.l10n.t('Invalid number')
299+
},
300+
{
301+
type : 'integer[1..]',
302+
prompt : this.l10n.t('Ticket price should be greater than 0')
303+
}
304+
]
305+
},
272306
paypalEmail: {
273307
identifier : 'paypal_email',
274308
rules : [

app/components/public/ticket-list.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default Component.extend(FormMixin, {
1616
}),
1717

1818
shouldDisableOrderButton: computed('isUnverified', 'hasTicketsInOrder', function() {
19-
return !this.hasTicketsInOrder;
19+
return !this.hasTicketsInOrder || !this.donationPriceValid;
2020
}),
2121

2222
showTaxIncludedMessage: computed('taxInfo.isTaxIncludedInPrice', function() {
@@ -40,6 +40,21 @@ export default Component.extend(FormMixin, {
4040
) > 0;
4141
}),
4242

43+
donationTickets: computed(function() {
44+
return this.data.filterBy('type', 'donation');
45+
}),
46+
47+
donationPriceValid: computed('[email protected]', '[email protected]', function() {
48+
if (this.donationTickets) {
49+
return sumBy(this.donationTickets.toArray(),
50+
donationTicket => (donationTicket.price)
51+
) > 0;
52+
} else {
53+
return true;
54+
}
55+
56+
}),
57+
4358
total: computed('[email protected]', '[email protected]', function() {
4459
if (this.taxInfo !== null) {
4560
return sumBy(this.tickets.toArray(),
@@ -190,6 +205,19 @@ export default Component.extend(FormMixin, {
190205
prompt : this.l10n.t('Please enter the promotional Code')
191206
}
192207
]
208+
},
209+
price: {
210+
identifier : 'price',
211+
rules : [
212+
{
213+
type : 'number',
214+
prompt : this.l10n.t('Invalid number')
215+
},
216+
{
217+
type : 'integer[1..]',
218+
prompt : this.l10n.t('Ticket price should be greater than 0')
219+
}
220+
]
193221
}
194222
}
195223
};

app/models/ticket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export default ModelBase.extend({
2121
salesEndsAt : attr('moment', { defaultValue: () => moment().add(10, 'days').startOf('day') }),
2222
minOrder : attr('number', { defaultValue: 1 }),
2323
maxOrder : attr('number', { defaultValue: 10 }),
24-
minPrice : attr('number'),
25-
maxPrice : attr('number'),
24+
minPrice : attr('number', { defaultValue: 1 }),
25+
maxPrice : attr('number', { defaultValue: 10 }),
2626
isFeeAbsorbed : attr('boolean', { defaultValue: true }),
2727
position : attr('number'),
2828

app/templates/components/public/ticket-list.hbs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@
4747
</td>
4848
{{else}}
4949
<td id="{{ticket.id}}_price">
50-
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
50+
{{#if (eq ticket.type 'donation') }}
51+
{{input type='number' name='price' placeholder=(t 'Enter Donation') value=ticket.price min=ticket.minPrice max=ticket.maxPrice }}
52+
{{else}}
53+
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
54+
{{/if}}
5155
{{#if (and taxInfo (not-eq ticket.type 'free'))}}
5256
{{#if showTaxIncludedMessage}}
5357
<small class="ui gray-text small">
@@ -63,24 +67,6 @@
6367
</div>
6468
{{/if}}
6569
</td>
66-
{{#if (eq ticket.type 'donation') }}
67-
<div class="three wide column">
68-
<td id="{{ticket.id}}_price">{{input type='number' value=ticket.price}}</td>
69-
</div>
70-
{{else}}
71-
{{#if ticket.discount}}
72-
<td>
73-
<div id="{{ticket.id}}_price" class="strike text">
74-
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
75-
</div>
76-
<div id="{{ticket.id}}_discount">
77-
{{currency-symbol eventCurrency}} {{format-number (sub ticket.price ticket.discount)}}
78-
</div>
79-
</td>
80-
{{else}}
81-
<td id="{{ticket.id}}_price">{{currency-symbol eventCurrency}} {{format-number ticket.price}}</td>
82-
{{/if}}
83-
{{/if}}
8470
{{/if}}
8571
<td>
8672
<div class="field">

app/templates/components/widgets/forms/ticket-input.hbs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
{{else if (eq ticket.type 'donation')}}
1313
<div class="two fields">
1414
<div class="field">
15-
{{input type='number' name='min_price' placeholder=(t 'Min') value=ticket.minOrder}}
15+
{{input type='number' name='min_price' placeholder=(t 'Min') value=ticket.minPrice min=1}}
1616
</div>
1717
<div class="field">
18-
{{input type='number' name='max_price' placeholder=(t 'Max') value=ticket.maxOrder}}
18+
{{input type='number' name='max_price' placeholder=(t 'Max') value=ticket.maxPrice min=1}}
1919
</div>
2020
</div>
2121
{{else if (eq ticket.type 'free')}}
@@ -26,19 +26,11 @@
2626
</div>
2727
{{/if}}
2828
</div>
29-
{{#if (eq ticket.type 'donation')}}
30-
<div class="four wide column">
31-
<span class="text muted ticket-input">
32-
{{t 'This is a Donation Ticket'}}
33-
</span>
34-
</div>
35-
{{else}}
36-
<div class="four wide column">
37-
<div class="field">
38-
{{input type='number' name='ticket_quantity' placeholder=(t 'Quantity') value=ticket.maxOrder min=1}}
39-
</div>
29+
<div class="four wide column">
30+
<div class="field">
31+
{{input type='number' name='ticket_quantity' placeholder=(t 'Quantity') value=ticket.quantity min=1}}
4032
</div>
41-
{{/if}}
33+
</div>
4234
<div class="column {{unless device.isLargeMonitor 'less right padding'}}">
4335
<div class="field">
4436
<div class="ui icon buttons">

0 commit comments

Comments
 (0)