Implementing Session and Speaker Creation From Event Panel In Open Event Frontend
Open-Event Front-end uses Ember data for handling Open Event Orga API which abides by JSON API specs. It allows the user to manage the event using the event panel of that event. This panel lets us create or update sessions & speakers. Each speaker must be associated with a session, therefore we save the session before saving the speaker.
In this blog we will see how to Implement the session & speaker creation via event panel. Lets see how we implemented it?
Passing the session & speaker models to the form
On the session & speaker creation page we need to render the forms using the custom form API and create new speaker and session entity. We create a speaker object here and we pass in the relationships for event and the user to it, likewise we create the session object and pass the event relationship to it.
These objects along with form which contains all the fields of the custom form, tracks which is a list of all the tracks & sessionTypes which is a list of all the session types of the event is passed in the model.
return RSVP.hash({ event : eventDetails, form : eventDetails.query('customForms', { 'page[size]' : 50, sort : 'id' }), session: this.get('store').createRecord('session', { event: eventDetails }), speaker: this.get('store').createRecord('speaker', { event : eventDetails, user : this.get('authManager.currentUser') }), tracks : eventDetails.query('tracks', {}), sessionTypes : eventDetails.query('sessionTypes', {}) });
We bind the speaker & session object to the template which has contains the session-speaker component for form validation. The request is only made if the form gets validated.
Saving the data
In Open Event API each speaker must be associated with a session, i.e we must define a session relationship for the speaker. To accomplish this we first save the session into the server and once it has been successfully saved we pass the session as a relation to the speaker object.
this.get('model.session').save() .then(session => { let speaker = this.get('model.speaker'); speaker.set('session', session); speaker.save() .then(() => { this.get('notify').success(this.l10n.t('Your session has been saved')); this.transitionToRoute('events.view.sessions', this.get('model.event.id')); }); })
We save the objects using the save method. After the speakers and sessions are save successfully we notify the user by showing a success message via the notify service.
Thank you for reading the blog, you can check the source code for the example here.
Resources
- Official Ember Data documentation
- Learn more about how to make requests in ember from this blog by asommer70
You must be logged in to post a comment.