-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migrating event,speakers,session in controllers to ES6 (#3721)
* chore: Migrating event,speakers,session in controllers to ES6 * using object destructuring
- Loading branch information
1 parent
9bd3a2e
commit f40338a
Showing
16 changed files
with
598 additions
and
572 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import Controller from '@ember/controller'; | ||
import EventWizardMixin from 'open-event-frontend/mixins/event-wizard'; | ||
import { action } from '@ember/object'; | ||
|
||
export default Controller.extend(EventWizardMixin, { | ||
|
||
actions: { | ||
save() { | ||
this.saveEventDataAndRedirectTo( | ||
'events.view.index', | ||
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization'] | ||
); | ||
}, | ||
move() { | ||
this.saveEventDataAndRedirectTo( | ||
'events.view.edit.attendee', | ||
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization'] | ||
); | ||
} | ||
export default class extends Controller.extend(EventWizardMixin) { | ||
@action | ||
save() { | ||
this.saveEventDataAndRedirectTo( | ||
'events.view.index', | ||
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization'] | ||
); | ||
} | ||
@action | ||
move() { | ||
this.saveEventDataAndRedirectTo( | ||
'events.view.edit.attendee', | ||
['tickets', 'socialLinks', 'copyright', 'tax', 'stripeAuthorization'] | ||
); | ||
} | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,91 @@ | ||
import Controller from '@ember/controller'; | ||
import { isEmpty } from '@ember/utils'; | ||
import { action } from '@ember/object'; | ||
|
||
export default Controller.extend({ | ||
actions: { | ||
openDeleteEventModal() { | ||
this.set('isEventDeleteModalOpen', true); | ||
}, | ||
togglePublishState() { | ||
if (isEmpty(this.get('model.locationName'))) { | ||
this.notify.error(this.l10n.t('Your event must have a location before it can be published.'), | ||
{ | ||
id: 'event_location' | ||
}); | ||
return; | ||
} | ||
this.set('isLoading', true); | ||
const state = this.get('model.state'); | ||
this.set('model.state', state === 'draft' ? 'published' : 'draft'); | ||
this.model.save() | ||
.then(() => { | ||
if (state === 'draft') { | ||
this.notify.success(this.l10n.t('Your event has been published successfully.'), | ||
{ | ||
id: 'event_publish' | ||
}); | ||
} else { | ||
this.notify.success(this.l10n.t('Your event has been unpublished.'), | ||
{ | ||
id: 'event_unpublish' | ||
}); | ||
} | ||
}) | ||
.catch(() => { | ||
this.set('model.state', state); | ||
this.notify.error(this.l10n.t('An unexpected error has occurred.'), | ||
{ | ||
id: 'event_publish_error' | ||
}); | ||
}) | ||
.finally(() => { | ||
this.set('isLoading', false); | ||
}); | ||
}, | ||
deleteEvent() { | ||
this.set('isLoading', true); | ||
this.model.destroyRecord() | ||
.then(() => { | ||
this.transitionToRoute('events'); | ||
this.notify.success(this.l10n.t('Event has been deleted successfully.'), | ||
{ | ||
id: 'event_deleted_succ' | ||
}); | ||
}) | ||
.catch(() => { | ||
this.notify.error(this.l10n.t('An unexpected error has occurred.'), | ||
{ | ||
id: 'event_deleted_error' | ||
}); | ||
}) | ||
.finally(() => { | ||
this.set('isLoading', false); | ||
export default class extends Controller { | ||
@action | ||
openDeleteEventModal() { | ||
this.set('isEventDeleteModalOpen', true); | ||
} | ||
@action | ||
togglePublishState() { | ||
if (isEmpty(this.model.locationName)) { | ||
this.notify.error(this.l10n.t('Your event must have a location before it can be published.'), | ||
{ | ||
id: 'event_location' | ||
}); | ||
this.set('isEventDeleteModalOpen', false); | ||
}, | ||
copyEvent() { | ||
this.set('isCopying', true); | ||
this.loader | ||
.post(`events/${this.get('model.id')}/copy`, {}) | ||
.then(copiedEvent => { | ||
this.transitionToRoute('events.view.edit', copiedEvent.identifier); | ||
this.notify.success(this.l10n.t('Event copied successfully'), | ||
return; | ||
} | ||
this.set('isLoading', true); | ||
const { state } = this.model; | ||
this.set('model.state', state === 'draft' ? 'published' : 'draft'); | ||
this.model.save() | ||
.then(() => { | ||
if (state === 'draft') { | ||
this.notify.success(this.l10n.t('Your event has been published successfully.'), | ||
{ | ||
id: 'event_copy_succ' | ||
id: 'event_publish' | ||
}); | ||
}) | ||
.catch(() => { | ||
this.notify.error(this.l10n.t('Copying of event failed'), | ||
} else { | ||
this.notify.success(this.l10n.t('Your event has been unpublished.'), | ||
{ | ||
id: 'event_copy_fail' | ||
id: 'event_unpublish' | ||
}); | ||
}) | ||
.finally(() => { | ||
this.set('isCopying', false); | ||
}); | ||
} | ||
} | ||
}) | ||
.catch(() => { | ||
this.set('model.state', state); | ||
this.notify.error(this.l10n.t('An unexpected error has occurred.'), | ||
{ | ||
id: 'event_publish_error' | ||
}); | ||
}) | ||
.finally(() => { | ||
this.set('isLoading', false); | ||
}); | ||
} | ||
@action | ||
deleteEvent() { | ||
this.set('isLoading', true); | ||
this.model.destroyRecord() | ||
.then(() => { | ||
this.transitionToRoute('events'); | ||
this.notify.success(this.l10n.t('Event has been deleted successfully.'), | ||
{ | ||
id: 'event_deleted_succ' | ||
}); | ||
}) | ||
.catch(() => { | ||
this.notify.error(this.l10n.t('An unexpected error has occurred.'), | ||
{ | ||
id: 'event_deleted_error' | ||
}); | ||
}) | ||
.finally(() => { | ||
this.set('isLoading', false); | ||
}); | ||
this.set('isEventDeleteModalOpen', false); | ||
} | ||
@action | ||
copyEvent() { | ||
this.set('isCopying', true); | ||
this.loader | ||
.post(`events/${this.model.id}/copy`, {}) | ||
.then(copiedEvent => { | ||
this.transitionToRoute('events.view.edit', copiedEvent.identifier); | ||
this.notify.success(this.l10n.t('Event copied successfully'), | ||
{ | ||
id: 'event_copy_succ' | ||
}); | ||
}) | ||
.catch(() => { | ||
this.notify.error(this.l10n.t('Copying of event failed'), | ||
{ | ||
id: 'event_copy_fail' | ||
}); | ||
}) | ||
.finally(() => { | ||
this.set('isCopying', false); | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
import Controller from '@ember/controller'; | ||
import { action } from '@ember/object'; | ||
import EventWizardMixin from 'open-event-frontend/mixins/event-wizard'; | ||
|
||
export default Controller.extend(EventWizardMixin, { | ||
export default class extends Controller.extend(EventWizardMixin) { | ||
|
||
async saveForms(data) { | ||
for (const customForm of data.customForms ? data.customForms.toArray() : []) { | ||
await customForm.save(); | ||
} | ||
return data; | ||
}, | ||
actions: { | ||
async save(data) { | ||
try { | ||
await this.saveForms(data); | ||
this.saveEventDataAndRedirectTo( | ||
'events.view.index', | ||
['tickets'] | ||
); | ||
} catch (error) { | ||
this.notify.error(this.l10n.t(error.message), | ||
{ | ||
id: 'attendee_error_serv' | ||
}); | ||
} | ||
}, | ||
async move(direction, data) { | ||
try { | ||
await this.saveForms(data); | ||
this.saveEventDataAndRedirectTo( | ||
direction === 'forwards' ? 'events.view.edit.sponsors' : 'events.view.edit.basic-details', | ||
['tickets'] | ||
); | ||
} catch (error) { | ||
this.notify.error(this.l10n.t(error.message), | ||
{ | ||
id: 'attendee_move_error' | ||
}); | ||
} | ||
} | ||
@action | ||
async save(data) { | ||
try { | ||
await this.saveForms(data); | ||
this.saveEventDataAndRedirectTo( | ||
'events.view.index', | ||
['tickets'] | ||
); | ||
} catch (error) { | ||
this.notify.error(this.l10n.t(error.message), | ||
{ | ||
id: 'attendee_error_serv' | ||
}); | ||
} | ||
} | ||
@action | ||
async move(direction, data) { | ||
try { | ||
await this.saveForms(data); | ||
this.saveEventDataAndRedirectTo( | ||
direction === 'forwards' ? 'events.view.edit.sponsors' : 'events.view.edit.basic-details', | ||
['tickets'] | ||
); | ||
} catch (error) { | ||
this.notify.error(this.l10n.t(error.message), | ||
{ | ||
id: 'attendee_move_error' | ||
}); | ||
} | ||
} | ||
}); | ||
} |
Oops, something went wrong.