|
1 | 1 | import Controller from '@ember/controller';
|
| 2 | +import { computed, action } from '@ember/object'; |
| 3 | +import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller'; |
2 | 4 |
|
3 |
| -export default Controller.extend({ |
4 |
| - columns: [ |
5 |
| - { |
6 |
| - propertyName : 'user', |
7 |
| - template : 'components/ui-table/cell/events/view/tickets/orders/cell-order', |
8 |
| - title : 'Order', |
9 |
| - disableSorting : true |
10 |
| - }, |
11 |
| - { |
12 |
| - propertyName : 'completedAt', |
13 |
| - template : 'components/ui-table/cell/events/view/tickets/orders/cell-date', |
14 |
| - dateFormat : 'MMMM DD, YYYY - HH:mm A', |
15 |
| - title : 'Date And Time' |
16 |
| - }, |
17 |
| - { |
18 |
| - propertyName : 'amount', |
19 |
| - template : 'components/ui-table/cell/events/view/tickets/orders/cell-amount', |
20 |
| - title : 'Total Amount' |
21 |
| - }, |
22 |
| - { |
23 |
| - propertyName : 'attendees.length', |
24 |
| - title : 'Quantity' |
25 |
| - }, |
26 |
| - { |
27 |
| - propertyName : 'user.email', |
28 |
| - title : 'Buyer/Registration Contact', |
29 |
| - disableSorting : true |
30 |
| - } |
31 |
| - ], |
32 | 5 |
|
33 |
| - actions: { |
34 |
| - completeOrder(order) { |
35 |
| - this.set('isLoading', true); |
36 |
| - order.set('status', 'completed'); |
37 |
| - order.save() |
38 |
| - .then(() => { |
39 |
| - this.send('refreshRoute'); |
40 |
| - this.notify.success(this.l10n.t('Order has been marked completed successfully.')); |
41 |
| - }) |
42 |
| - .catch(() => { |
43 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
44 |
| - }) |
45 |
| - .finally(() => { |
46 |
| - this.set('isLoading', false); |
47 |
| - }); |
48 |
| - }, |
49 |
| - deleteOrder(order) { |
50 |
| - this.set('isLoading', true); |
51 |
| - order.destroyRecord() |
52 |
| - .then(() => { |
53 |
| - this.send('refreshRoute'); |
54 |
| - this.notify.success(this.l10n.t('Order has been deleted successfully.')); |
55 |
| - }) |
56 |
| - .catch(() => { |
57 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
58 |
| - }) |
59 |
| - .finally(() => { |
60 |
| - this.set('isLoading', false); |
61 |
| - }); |
62 |
| - }, |
63 |
| - cancelOrder(order) { |
64 |
| - this.set('isLoading', true); |
65 |
| - order.set('status', 'cancelled'); |
66 |
| - order.save() |
67 |
| - .then(() => { |
68 |
| - this.send('refreshRoute'); |
69 |
| - this.notify.success(this.l10n.t('Order has been cancelled successfully.')); |
70 |
| - }) |
71 |
| - .catch(() => { |
72 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
73 |
| - }) |
74 |
| - .finally(() => { |
75 |
| - this.set('isLoading', false); |
76 |
| - }); |
77 |
| - }, |
78 |
| - async resendConfirmation(order) { |
79 |
| - try { |
80 |
| - const payload = { |
81 |
| - 'data': { |
82 |
| - 'order' : order.identifier, |
83 |
| - 'user' : this.authManager.currentUser.email |
84 |
| - } |
85 |
| - }; |
86 |
| - await this.loader.post('orders/resend-email', payload); |
87 |
| - this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully')); |
88 |
| - } catch (error) { |
89 |
| - if (error.status && error.status === 429) { |
90 |
| - this.notify.error(this.l10n.t('Only 5 resend actions are allowed in a minute')); |
91 |
| - } else if (error.status && error.status === 422) { |
92 |
| - this.notify.error(this.l10n.tVar(error.response.errors[0].detail)); |
93 |
| - } else { |
94 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
| 6 | +export default class extends Controller.extend(EmberTableControllerMixin) { |
| 7 | + @computed() |
| 8 | + get columns() { |
| 9 | + return [ |
| 10 | + { |
| 11 | + name : 'Order', |
| 12 | + valuePath : 'identifier', |
| 13 | + extraValuePaths : ['user', 'status', 'paidVia', 'completedAt', 'createdAt'], |
| 14 | + cellComponent : 'ui-table/cell/events/view/tickets/orders/cell-order', |
| 15 | + width : 200, |
| 16 | + actions : { |
| 17 | + completeOrder : this.completeOrder.bind(this), |
| 18 | + deleteOrder : this.deleteOrder.bind(this), |
| 19 | + cancelOrder : this.cancelOrder.bind(this), |
| 20 | + resendConfirmation : this.resendConfirmation.bind(this) |
| 21 | + } |
| 22 | + }, |
| 23 | + { |
| 24 | + name : 'Date And Time', |
| 25 | + valuePath : 'completedAt', |
| 26 | + extraValuePaths : ['createdAt'], |
| 27 | + cellComponent : 'ui-table/cell/events/view/tickets/orders/cell-date', |
| 28 | + headerComponent : 'tables/headers/sort', |
| 29 | + width : 100, |
| 30 | + dateFormat : 'MMMM DD, YYYY - HH:mm A', |
| 31 | + isSortable : true |
| 32 | + }, |
| 33 | + { |
| 34 | + name : 'Total Amount', |
| 35 | + valuePath : 'amount', |
| 36 | + extraValuePaths : ['discountCode', 'event'], |
| 37 | + cellComponent : 'ui-table/cell/events/view/tickets/orders/cell-amount', |
| 38 | + headerComponent : 'tables/headers/sort', |
| 39 | + width : 100, |
| 40 | + isSortable : true |
| 41 | + }, |
| 42 | + { |
| 43 | + name : 'Quantity', |
| 44 | + valuePath : 'attendees.length', |
| 45 | + width : 50 |
| 46 | + }, |
| 47 | + { |
| 48 | + name : 'Buyer/Registration Contact', |
| 49 | + valuePath : 'user.email', |
| 50 | + width : 140 |
| 51 | + |
| 52 | + } |
| 53 | + ]; |
| 54 | + } |
| 55 | + |
| 56 | + @computed('model.data.@each') |
| 57 | + get rows() { |
| 58 | + return this.model.data; |
| 59 | + } |
| 60 | + |
| 61 | + @action |
| 62 | + completeOrder(order_id) { |
| 63 | + this.set('isLoading', true); |
| 64 | + const order = this.store.peekRecord('order', order_id, { backgroundReload: false }); |
| 65 | + order.set('status', 'completed'); |
| 66 | + order.save() |
| 67 | + .then(() => { |
| 68 | + this.notify.success(this.l10n.t('Order has been marked completed successfully.')); |
| 69 | + this.refreshModel.bind(this)(); |
| 70 | + }) |
| 71 | + .catch(() => { |
| 72 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
| 73 | + }) |
| 74 | + .finally(() => { |
| 75 | + this.set('isLoading', false); |
| 76 | + }); |
| 77 | + } |
| 78 | + @action |
| 79 | + deleteOrder(order_id) { |
| 80 | + this.set('isLoading', true); |
| 81 | + const order = this.store.peekRecord('order', order_id, { backgroundReload: false }); |
| 82 | + order.destroyRecord() |
| 83 | + .then(() => { |
| 84 | + this.notify.success(this.l10n.t('Order has been deleted successfully.')); |
| 85 | + this.refreshModel.bind(this)(); |
| 86 | + }) |
| 87 | + .catch(e => { |
| 88 | + console.warn(e); |
| 89 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
| 90 | + }) |
| 91 | + .finally(() => { |
| 92 | + this.set('isLoading', false); |
| 93 | + }); |
| 94 | + } |
| 95 | + |
| 96 | + @action |
| 97 | + cancelOrder(order_id) { |
| 98 | + this.set('isLoading', true); |
| 99 | + const order = this.store.peekRecord('order', order_id, { backgroundReload: false }); |
| 100 | + order.set('status', 'cancelled'); |
| 101 | + order.save() |
| 102 | + .then(() => { |
| 103 | + this.notify.success(this.l10n.t('Order has been cancelled successfully.')); |
| 104 | + this.refreshModel.bind(this)(); |
| 105 | + }) |
| 106 | + .catch(() => { |
| 107 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
| 108 | + }) |
| 109 | + .finally(() => { |
| 110 | + this.set('isLoading', false); |
| 111 | + }); |
| 112 | + } |
| 113 | + |
| 114 | + @action |
| 115 | + async resendConfirmation(order_id) { |
| 116 | + try { |
| 117 | + const order = this.store.peekRecord('order', order_id, { backgroundReload: false }); |
| 118 | + const payload = { |
| 119 | + 'data': { |
| 120 | + 'order' : order.identifier, |
| 121 | + 'user' : this.authManager.currentUser.email |
95 | 122 | }
|
| 123 | + }; |
| 124 | + await this.loader.post('orders/resend-email', payload); |
| 125 | + this.notify.success(this.l10n.t('Email confirmation has been sent to attendees successfully')); |
| 126 | + } catch (error) { |
| 127 | + if (error.status && error.status === 429) { |
| 128 | + this.notify.error(this.l10n.t('Only 5 resend actions are allowed in a minute')); |
| 129 | + } else if (error.status && error.status === 422) { |
| 130 | + this.notify.error(this.l10n.tVar(error.response.errors[0].detail)); |
| 131 | + } else { |
| 132 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
96 | 133 | }
|
97 | 134 | }
|
98 | 135 | }
|
99 |
| -}); |
| 136 | +} |
0 commit comments