Skip to content

Commit daa6a85

Browse files
mrsaicharan1kushthedude
authored andcommitted
Added quantity support for donations & fixed bugs (#3209)
Added watched properties and fixed totalling error Added semantic validation Added dynamic popup for ticket buyers Added action to check for max/min price Added quantitiy, min-max and bug fixes for donations removed repeated code Add error class validation Fixed paid & free tickets bug ESLint Used for-of & removed redundant merge Optimized donationsValidation property
1 parent b7f6f7c commit daa6a85

File tree

6 files changed

+91
-42
lines changed

6 files changed

+91
-42
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,32 @@ export default Component.extend(FormMixin, EventWizardMixin, {
269269
}
270270
]
271271
},
272+
minPrice: {
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 : 'integer[1..]',
281+
prompt : this.l10n.t('Minimum price needs to be greater than zero')
282+
}
283+
]
284+
},
285+
maxPrice: {
286+
identifier : 'max_price',
287+
rules : [
288+
{
289+
type : 'empty',
290+
prompt : this.l10n.t('Maximum price for donation tickets required')
291+
},
292+
{
293+
type : 'integer[1..]',
294+
prompt : this.l10n.t('Maximum price needs to be greater than zero')
295+
}
296+
]
297+
},
272298
paypalEmail: {
273299
identifier : 'paypal_email',
274300
rules : [

app/components/public/ticket-list.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import FormMixin from 'open-event-frontend/mixins/form';
44
import { inject as service } from '@ember/service';
55
import { sumBy } from 'lodash-es';
66
import { A } from '@ember/array';
7+
import { merge } from 'lodash-es';
78

89
export default Component.extend(FormMixin, {
910
store: service(),
@@ -15,8 +16,14 @@ export default Component.extend(FormMixin, {
1516
&& !this.get('authManager.currentUser.isVerified');
1617
}),
1718

18-
shouldDisableOrderButton: computed('isUnverified', 'hasTicketsInOrder', function() {
19-
return !this.hasTicketsInOrder;
19+
shouldDisableOrderButton: computed('hasTicketsInOrder', 'isDonationPriceValid', function() {
20+
let quantityDonation = sumBy(this.donationTickets.toArray(),
21+
donationTicket => (donationTicket.orderQuantity || 0));
22+
if (quantityDonation > 0) {
23+
return !(this.hasTicketsInOrder && this.isDonationPriceValid);
24+
} else {
25+
return !this.hasTicketsInOrder;
26+
}
2027
}),
2128

2229
showTaxIncludedMessage: computed('taxInfo.isTaxIncludedInPrice', function() {
@@ -39,8 +46,20 @@ export default Component.extend(FormMixin, {
3946
ticket => (ticket.orderQuantity || 0)
4047
) > 0;
4148
}),
49+
donationTickets: computed.filterBy('data', 'type', 'donation'),
50+
51+
isDonationPriceValid: computed('[email protected]', '[email protected]', function() {
52+
for (const donationTicket of this.donationTickets) {
53+
if (donationTicket.orderQuantity > 0) {
54+
if (donationTicket.price < donationTicket.minPrice || donationTicket.price > donationTicket.maxPrice) {
55+
return false;
56+
}
57+
}
58+
}
59+
return true;
60+
}),
4261

43-
total: computed('[email protected]', '[email protected]', function() {
62+
total: computed('tickets.@each.price', 'tickets.@each.orderQuantity', '[email protected]', function() {
4463
if (this.taxInfo !== null) {
4564
return sumBy(this.tickets.toArray(),
4665
ticket => (ticket.ticketPriceWithTax || 0) * (ticket.orderQuantity || 0)
@@ -176,14 +195,30 @@ export default Component.extend(FormMixin, {
176195
this.send('togglePromotionalCode', this.code);
177196
}
178197
},
198+
donationTicketsValidation: computed('[email protected]', '[email protected]', '[email protected]', function() {
199+
const validationRules = {};
200+
for (let donationTicket of this.donationTickets) {
201+
validationRules[donationTicket.id] = {
202+
identifier : donationTicket.id,
203+
optional : true,
204+
rules : [
205+
{
206+
type : `integer[${donationTicket.minPrice}..${donationTicket.maxPrice}]`,
207+
prompt : this.l10n.t(`Please enter a donation amount between ${donationTicket.minPrice} and ${donationTicket.maxPrice}`)
208+
}
209+
]
210+
};
211+
}
212+
return validationRules;
213+
}),
179214
getValidationRules() {
180-
return {
215+
const validationRules = {
181216
inline : true,
182217
delay : false,
183218
on : 'blur',
184219
fields : {
185220
promotionalCode: {
186-
identifier : 'promotional_code',
221+
identifier : 'promotionalCode',
187222
rules : [
188223
{
189224
type : 'empty',
@@ -193,5 +228,7 @@ export default Component.extend(FormMixin, {
193228
}
194229
}
195230
};
231+
validationRules.fields = merge(validationRules.fields, this.donationTicketsValidation);
232+
return validationRules;
196233
}
197234
});

app/components/widgets/forms/ticket-input.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import Component from '@ember/component';
2+
import { gte } from '@ember/object/computed';
23

34
export default Component.extend({
4-
classNames: ['ui', 'celled', 'stackable', 'grid', 'ticket-row'],
5-
6-
actions: {
5+
classNames : ['ui', 'celled', 'stackable', 'grid', 'ticket-row'],
6+
minMaxValid : gte('ticket.maxPrice', 'ticket.minPrice'),
7+
actions : {
78
toggleSettings() {
89
this.toggleProperty('isExpanded');
910
}

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: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<td>
1717
<div class="ui small">
1818
{{ticket.name}}
19+
{{#if (eq ticket.type 'donation')}}
20+
{{ui-popup tagName="i" class="info icon" content=(concat "Donation value should be between " ticket.minPrice " " eventCurrency " and " ticket.maxPrice " " eventCurrency)}}
21+
{{/if}}
1922
</div>
2023
{{#if ticket.isDescriptionVisible}}
2124
<small class="ui gray-text tiny">{{ticket.description}}</small>
@@ -47,7 +50,13 @@
4750
</td>
4851
{{else}}
4952
<td id="{{ticket.id}}_price">
50-
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
53+
{{#if (eq ticket.type 'donation') }}
54+
<div class="field">
55+
{{input type='number' name=ticket.id placeholder=(t 'Enter Donation') min=ticket.minPrice max=ticket.maxPrice value=ticket.price}}<br>
56+
</div>
57+
{{else}}
58+
{{currency-symbol eventCurrency}} {{format-number ticket.price}}
59+
{{/if}}
5160
{{#if (and taxInfo (not-eq ticket.type 'free'))}}
5261
{{#if showTaxIncludedMessage}}
5362
<small class="ui gray-text small">
@@ -63,22 +72,6 @@
6372
</div>
6473
{{/if}}
6574
</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-
{{/if}}
81-
{{/if}}
8275
{{/if}}
8376
<td>
8477
<div class="field">

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
</div>
1212
{{else if (eq ticket.type 'donation')}}
1313
<div class="two fields">
14-
<div class="field">
15-
{{input type='number' name='min_price' placeholder=(t 'Min') value=ticket.minOrder}}
14+
<div class="field {{unless minMaxValid 'error'}}" >
15+
{{input type='number' name='min_price' placeholder=(t 'Min') value=ticket.minPrice min=1}}
1616
</div>
17-
<div class="field">
18-
{{input type='number' name='max_price' placeholder=(t 'Max') value=ticket.maxOrder}}
17+
<div class="field {{unless minMaxValid 'error'}}" >
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)