Skip to content

Commit 4bdc17b

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 removed .get() donation should be greater than min price Add min/max validation Used this.tickets for looping
1 parent 5e9c7b3 commit 4bdc17b

File tree

5 files changed

+92
-36
lines changed

5 files changed

+92
-36
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,26 @@ export default Component.extend(FormMixin, EventWizardMixin, {
114114
this.getForm().form('remove prompt', 'discount_code');
115115
}),
116116

117+
donationTickets: computed.filterBy('tickets', 'type', 'donation'),
118+
117119
didInsertElement() {
118120
if (!this.isCreate && this.get('data.event.copyright') && !this.get('data.event.copyright.content')) {
119121
this.set('data.event.copyright', this.store.createRecord('event-copyright'));
120122
}
121123
},
122124

123125
getValidationRules() {
126+
window.$.fn.form.settings.rules.checkMaxMin = () => {
127+
let returnValue = false;
128+
this.donationTickets.forEach(donationTicket => {
129+
if (donationTicket.minPrice <= donationTicket.maxPrice) {
130+
returnValue = true;
131+
} else {
132+
returnValue = false;
133+
}
134+
});
135+
return returnValue;
136+
};
124137
let validationRules = {
125138
inline : true,
126139
delay : false,
@@ -269,6 +282,40 @@ export default Component.extend(FormMixin, EventWizardMixin, {
269282
}
270283
]
271284
},
285+
ticketMinPrice: {
286+
identifier : 'min_price',
287+
rules : [
288+
{
289+
type : 'empty',
290+
prompt : this.l10n.t('Minimum price for donation tickets required')
291+
},
292+
{
293+
type : 'number',
294+
prompt : this.l10n.t('Invalid number')
295+
},
296+
{
297+
type : 'checkMaxMin',
298+
prompt : this.l10n.t('Ticket min price should be lesser than max price')
299+
}
300+
]
301+
},
302+
ticketMaxPrice: {
303+
identifier : 'max_price',
304+
rules : [
305+
{
306+
type : 'empty',
307+
prompt : this.l10n.t('Maximum price for donation tickets required')
308+
},
309+
{
310+
type : 'number',
311+
prompt : this.l10n.t('Invalid number')
312+
},
313+
{
314+
type : 'checkMaxMin',
315+
prompt : this.l10n.t('Ticket max price should be greater than min price')
316+
}
317+
]
318+
},
272319
paypalEmail: {
273320
identifier : 'paypal_email',
274321
rules : [

app/components/public/ticket-list.js

Lines changed: 31 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,22 @@ export default Component.extend(FormMixin, {
4040
) > 0;
4141
}),
4242

43+
donationTickets: computed.filterBy('data', 'type', 'donation'),
44+
45+
isDonationPriceValid: computed('[email protected]', '[email protected]', function() {
46+
let returnValue = false;
47+
this.donationTickets.forEach(donationTicket => {
48+
if (donationTicket.orderQuantity >= 0) {
49+
if (donationTicket.price >= donationTicket.minPrice) {
50+
returnValue = true;
51+
} else {
52+
returnValue = false;
53+
}
54+
}
55+
});
56+
return returnValue;
57+
}),
58+
4359
total: computed('[email protected]', '[email protected]', function() {
4460
if (this.taxInfo !== null) {
4561
return sumBy(this.tickets.toArray(),
@@ -190,6 +206,19 @@ export default Component.extend(FormMixin, {
190206
prompt : this.l10n.t('Please enter the promotional Code')
191207
}
192208
]
209+
},
210+
price: {
211+
identifier : 'price',
212+
rules : [
213+
{
214+
type : 'number',
215+
prompt : this.l10n.t('Invalid number')
216+
},
217+
{
218+
type : 'integer[1..]',
219+
prompt : this.l10n.t('Donation should be greater than 0')
220+
}
221+
]
193222
}
194223
}
195224
};

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}}<br>
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)