Skip to content

Commit 9698259

Browse files
committed
Added quantity support for donations & fixed bugs
Prevent zero donations Added computed function Add mut helper Added watched properties and fixed totalling error Fixed logic and naming error
1 parent 539cc20 commit 9698259

File tree

5 files changed

+81
-36
lines changed

5 files changed

+81
-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: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default Component.extend(FormMixin, {
1515
&& !this.get('authManager.currentUser.isVerified');
1616
}),
1717

18-
shouldDisableOrderButton: computed('isUnverified', 'hasTicketsInOrder', function() {
19-
return !this.hasTicketsInOrder;
18+
shouldDisableOrderButton: computed('hasTicketsInOrder', 'isDonationPriceValid', function() {
19+
return !(this.hasTicketsInOrder && this.isDonationPriceValid);
2020
}),
2121

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

43+
donationTickets: computed('data', function() {
44+
return this.data.filterBy('type', 'donation');
45+
}),
46+
47+
isDonationPriceValid: computed('donationTickets', '[email protected]', '[email protected]', function() {
48+
let returnValue = false;
49+
this.donationTickets.forEach(donationTicket => {
50+
if (donationTicket.get('orderQuantity') >= 0) {
51+
if (donationTicket.get('price') > 0) {
52+
returnValue = true;
53+
} else {
54+
returnValue = false;
55+
}
56+
}
57+
});
58+
return returnValue;
59+
}),
60+
4361
total: computed('[email protected]', '[email protected]', function() {
4462
if (this.taxInfo !== null) {
4563
return sumBy(this.tickets.toArray(),
@@ -190,6 +208,19 @@ export default Component.extend(FormMixin, {
190208
prompt : this.l10n.t('Please enter the promotional Code')
191209
}
192210
]
211+
},
212+
price: {
213+
identifier : 'price',
214+
rules : [
215+
{
216+
type : 'number',
217+
prompt : this.l10n.t('Invalid number')
218+
},
219+
{
220+
type : 'integer[1..]',
221+
prompt : this.l10n.t('Donation should be greater than 0')
222+
}
223+
]
193224
}
194225
}
195226
};

app/models/ticket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ 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'),
24+
minPrice : attr('number', { defaultValue: 1 }),
2525
maxPrice : attr('number'),
2626
isFeeAbsorbed : attr('boolean', { defaultValue: true }),
2727
position : attr('number'),

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@
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+
<div class="field">
52+
{{input type='number' name="price" placeholder=(t 'Enter Donation') min=ticket.minPrice max=ticket.maxPrice value=ticket.price}}
53+
</div>
54+
{{else}}
55+
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
56+
{{/if}}
5157
{{#if (and taxInfo (not-eq ticket.type 'free'))}}
5258
{{#if showTaxIncludedMessage}}
5359
<small class="ui gray-text small">
@@ -63,24 +69,6 @@
6369
</div>
6470
{{/if}}
6571
</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}}
8472
{{/if}}
8573
<td>
8674
<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)