|
1 | 1 | import Controller from '@ember/controller';
|
2 |
| -import { computed } from '@ember/object'; |
3 |
| -export default Controller.extend({ |
4 |
| - hasRestorePrivileges: computed('authManager.currentUser.isAdmin', function() { |
5 |
| - return this.get('authManager.currentUser.isSuperAdmin') || this.get('authManager.currentUser.isAdmin'); |
6 |
| - }), |
7 |
| - columns: [ |
8 |
| - { |
9 |
| - propertyName : 'name', |
10 |
| - template : 'components/ui-table/cell/cell-event', |
11 |
| - title : 'Name' |
12 |
| - }, |
13 |
| - { |
14 |
| - propertyName : 'startsAt', |
15 |
| - template : 'components/ui-table/cell/cell-simple-date', |
16 |
| - dateFormat : 'MMMM DD, YYYY - hh:mm A', |
17 |
| - title : 'Starts At' |
18 |
| - }, |
19 |
| - { |
20 |
| - propertyName : 'endsAt', |
21 |
| - template : 'components/ui-table/cell/cell-simple-date', |
22 |
| - dateFormat : 'MMMM DD, YYYY - hh:mm A', |
23 |
| - title : 'Ends At' |
24 |
| - }, |
25 |
| - { |
26 |
| - propertyName : 'state', |
27 |
| - template : 'components/ui-table/cell/cell-event-state', |
28 |
| - title : 'State' |
29 |
| - }, |
30 |
| - { |
31 |
| - propertyName : 'roles', |
32 |
| - template : 'components/ui-table/cell/cell-roles', |
33 |
| - title : 'Roles', |
34 |
| - disableSorting : true |
35 |
| - }, |
36 |
| - { |
37 |
| - propertyName : 'eventStatisticsGeneral.sessions', |
38 |
| - template : 'components/ui-table/cell/cell-sessions', |
39 |
| - title : 'Sessions', |
40 |
| - disableSorting : true |
41 |
| - }, |
42 |
| - { |
43 |
| - propertyName : 'eventStatisticsGeneral.speakers', |
44 |
| - template : 'components/ui-table/cell/cell-speakers-dashboard', |
45 |
| - title : 'Speakers', |
46 |
| - disableSorting : true |
47 |
| - }, |
48 |
| - { |
49 |
| - propertyName : 'tickets', |
50 |
| - template : 'components/ui-table/cell/cell-tickets', |
51 |
| - title : 'Tickets', |
52 |
| - disableSorting : true |
53 |
| - }, |
54 |
| - { |
55 |
| - propertyName : 'url', |
56 |
| - template : 'components/ui-table/cell/cell-link', |
57 |
| - title : 'Public URL', |
58 |
| - disableSorting : true |
59 |
| - }, |
60 |
| - { |
61 |
| - propertyName : 'is-featured', |
62 |
| - template : 'components/ui-table/cell/admin/event-is-featured', |
63 |
| - title : 'Featured Event', |
64 |
| - disableSorting : false |
65 |
| - }, |
66 |
| - { |
67 |
| - propertyName : 'deletedAt', |
68 |
| - template : 'components/ui-table/cell/cell-buttons', |
69 |
| - title : 'Actions', |
70 |
| - disableSorting : true |
| 2 | +import { computed, action } from '@ember/object'; |
| 3 | +import { or } from '@ember/object/computed'; |
| 4 | +import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller'; |
| 5 | + |
| 6 | + |
| 7 | +export default class extends Controller.extend(EmberTableControllerMixin) { |
| 8 | + |
| 9 | + @or('authManager.currentUser.isSuperAdmin', 'authManager.currentUser.isAdmin') hasRestorePrivileges; |
| 10 | + |
| 11 | + @computed() |
| 12 | + get columns() { |
| 13 | + return [ |
| 14 | + { |
| 15 | + name : 'Name', |
| 16 | + valuePath : 'id', |
| 17 | + extraValuePaths : ['logoUrl', 'identifier', 'deletedAt', 'name'], |
| 18 | + isSortable : true, |
| 19 | + headerComponent : 'tables/headers/sort', |
| 20 | + cellComponent : 'ui-table/cell/cell-event', |
| 21 | + options : { |
| 22 | + hasRestorePrivileges: this.hasRestorePrivileges |
| 23 | + }, |
| 24 | + actions: { |
| 25 | + moveToDetails : this.moveToDetails.bind(this), |
| 26 | + editEvent : this.editEvent.bind(this), |
| 27 | + openDeleteEventModal : this.openDeleteEventModal.bind(this), |
| 28 | + deleteEvent : this.deleteEvent.bind(this), |
| 29 | + restoreEvent : this.restoreEvent.bind(this) |
| 30 | + } |
| 31 | + }, |
| 32 | + { |
| 33 | + name : 'Starts At', |
| 34 | + valuePath : 'startsAt', |
| 35 | + isSortable : true, |
| 36 | + headerComponent : 'tables/headers/sort', |
| 37 | + cellComponent : 'ui-table/cell/cell-simple-date', |
| 38 | + width : 40, |
| 39 | + options : { |
| 40 | + dateFormat: 'MMMM DD, YYYY - hh:mm A' |
| 41 | + } |
| 42 | + }, |
| 43 | + { |
| 44 | + name : 'Ends At', |
| 45 | + valuePath : 'endsAt', |
| 46 | + isSortable : true, |
| 47 | + headerComponent : 'tables/headers/sort', |
| 48 | + cellComponent : 'ui-table/cell/cell-simple-date', |
| 49 | + width : 40, |
| 50 | + options : { |
| 51 | + dateFormat: 'MMMM DD, YYYY - hh:mm A' |
| 52 | + } |
| 53 | + }, |
| 54 | + { |
| 55 | + name : 'State', |
| 56 | + valuePath : 'state', |
| 57 | + isSortable : true, |
| 58 | + headerComponent : 'tables/headers/sort', |
| 59 | + width : 50 |
| 60 | + }, |
| 61 | + { |
| 62 | + name : 'Roles', |
| 63 | + valuePath : 'owner', |
| 64 | + extraValuePaths : ['organizers', 'coorganizers', 'trackOrganizers', 'registrars', 'moderators'], |
| 65 | + cellComponent : 'ui-table/cell/cell-roles' |
| 66 | + }, |
| 67 | + { |
| 68 | + name : 'Sessions', |
| 69 | + valuePath : 'eventStatisticsGeneral', |
| 70 | + cellComponent : 'ui-table/cell/cell-sessions', |
| 71 | + width : 60 |
| 72 | + |
| 73 | + }, |
| 74 | + { |
| 75 | + name : 'Speakers', |
| 76 | + valuePath : 'eventStatisticsGeneral', |
| 77 | + cellComponent : 'ui-table/cell/cell-speakers-dashboard', |
| 78 | + width : 60 |
| 79 | + }, |
| 80 | + { |
| 81 | + name : 'Tickets', |
| 82 | + valuePath : 'tickets', |
| 83 | + cellComponent : 'ui-table/cell/cell-tickets' |
| 84 | + }, |
| 85 | + { |
| 86 | + name : 'Public URL', |
| 87 | + valuePath : 'url', |
| 88 | + cellComponent : 'ui-table/cell/cell-link' |
| 89 | + }, |
| 90 | + { |
| 91 | + name : 'Featured Event', |
| 92 | + valuePath : 'id', |
| 93 | + extraValuePaths : ['isFeatured'], |
| 94 | + cellComponent : 'ui-table/cell/admin/event-is-featured', |
| 95 | + width : 40, |
| 96 | + actions : { |
| 97 | + toggleFeatured: this.toggleFeatured.bind(this) |
| 98 | + } |
| 99 | + } |
| 100 | + ]; |
| 101 | + } |
| 102 | + |
| 103 | + @action |
| 104 | + moveToDetails(id) { |
| 105 | + this.transitionToRoute('events.view', id); |
| 106 | + } |
| 107 | + |
| 108 | + @action |
| 109 | + editEvent(id) { |
| 110 | + this.transitionToRoute('events.view.edit.basic-details', id); |
| 111 | + } |
| 112 | + |
| 113 | + @action |
| 114 | + openDeleteEventModal(id, name) { |
| 115 | + this.setProperties({ |
| 116 | + isEventDeleteModalOpen : true, |
| 117 | + confirmName : '', |
| 118 | + eventName : name, |
| 119 | + eventId : id |
| 120 | + }); |
| 121 | + } |
| 122 | + |
| 123 | + @action |
| 124 | + async deleteEvent() { |
| 125 | + this.set('isLoading', true); |
| 126 | + try { |
| 127 | + let event = this.store.peekRecord('event', this.eventId, { backgroundReload: false }); |
| 128 | + await event.destroyRecord(); |
| 129 | + this.notify.success(this.l10n.t('Event has been deleted successfully.')); |
| 130 | + } catch (e) { |
| 131 | + console.warn(e); |
| 132 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
71 | 133 | }
|
72 |
| - ], |
73 |
| - actions: { |
74 |
| - moveToDetails(id) { |
75 |
| - this.transitionToRoute('events.view', id); |
76 |
| - }, |
77 |
| - editEvent(id) { |
78 |
| - this.transitionToRoute('events.view.edit.basic-details', id); |
79 |
| - }, |
80 |
| - openDeleteEventModal(id, name) { |
81 |
| - this.set('isEventDeleteModalOpen', true); |
82 |
| - this.set('confirmName', ''); |
83 |
| - this.set('eventName', name); |
84 |
| - this.set('eventId', id); |
85 |
| - }, |
86 |
| - deleteEvent() { |
87 |
| - this.set('isLoading', true); |
88 |
| - this.store.findRecord('event', this.eventId, { backgroundReload: false }).then(function(event) { |
89 |
| - event.destroyRecord(); |
90 |
| - }) |
91 |
| - .then(() => { |
92 |
| - this.set('isLoading', false); |
93 |
| - this.notify.success(this.l10n.t('Event has been deleted successfully.')); |
94 |
| - this.send('refreshRoute'); |
95 |
| - }) |
96 |
| - .catch(() => { |
97 |
| - this.set('isLoading', false); |
98 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
99 |
| - }); |
100 |
| - this.set('isEventDeleteModalOpen', false); |
101 |
| - }, |
102 |
| - restoreEvent(event) { |
103 |
| - this.set('isLoading', true); |
| 134 | + this.setProperties({ |
| 135 | + isLoading : false, |
| 136 | + isEventDeleteModalOpen : false |
| 137 | + }); |
| 138 | + } |
| 139 | + @action |
| 140 | + async restoreEvent(event_id) { |
| 141 | + this.set('isLoading', true); |
| 142 | + try { |
| 143 | + let event = this.store.peekRecord('event', event_id, { backgroundReload: false }); |
104 | 144 | event.set('deletedAt', null);
|
105 |
| - event.save({ adapterOptions: { getTrashed: true } }) |
106 |
| - .then(() => { |
107 |
| - this.notify.success(this.l10n.t('Event has been restored successfully.')); |
108 |
| - this.send('refreshRoute'); |
109 |
| - }) |
110 |
| - .catch(e => { |
111 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
112 |
| - console.warn(e); |
113 |
| - }) |
114 |
| - .finally(() => { |
115 |
| - this.set('isLoading', false); |
116 |
| - }); |
117 |
| - }, |
118 |
| - toggleFeatured(event) { |
| 145 | + await event.save({ adapterOptions: { getTrashed: true } }); |
| 146 | + this.notify.success(this.l10n.t('Event has been restored successfully.')); |
| 147 | + } catch (e) { |
| 148 | + console.warn(e); |
| 149 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
| 150 | + } |
| 151 | + this.set('isLoading', false); |
| 152 | + } |
| 153 | + |
| 154 | + @action |
| 155 | + async toggleFeatured(event_id) { |
| 156 | + this.set('isLoading', true); |
| 157 | + try { |
| 158 | + let event = this.store.peekRecord('event', event_id, { backgroundReload: false }); |
119 | 159 | event.toggleProperty('isFeatured');
|
120 |
| - event.save() |
121 |
| - .then(() => { |
122 |
| - this.notify.success(this.l10n.t('Event details modified successfully')); |
123 |
| - }) |
124 |
| - .catch(() => { |
125 |
| - this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
126 |
| - }); |
| 160 | + await event.save(); |
| 161 | + this.notify.success(this.l10n.t('Event details modified successfully')); |
| 162 | + |
| 163 | + } catch (e) { |
| 164 | + console.warn(e); |
| 165 | + this.notify.error(this.l10n.t('An unexpected error has occurred.')); |
127 | 166 | }
|
| 167 | + this.set('isLoading', false); |
128 | 168 | }
|
129 |
| -}); |
| 169 | +} |
0 commit comments