Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Ember from 'ember'
- export default Ember.Component.extend({
- store: Ember.inject.service(),
- title: undefined,
- location: undefined,
- rating: undefined,
- inputRatings: [{
- label: 'Not rated',
- value: 0
- },{
- label: 'Bad',
- value: 1
- },{
- label: 'Average',
- value: 2
- },{
- label: 'Good',
- value: 3
- }],
- init () {
- this._super(...arguments)
- this.set('title', this.get('title'))
- this.set('location', this.get('location'))
- this.set('rating', this.get('rating'))
- },
- actions: {
- submit () {
- let newTitle = this.get('title')
- let newLocation = this.get('location')
- let newRating = this.get('rating')
- let ids = this.get('store').peekAll('item').mapBy('id')
- let newId = Math.max(...ids) + 1
- if (!newTitle || !newLocation || !newRating) {
- return
- }
- var newItem = this.get('store').pushPayload({
- data: {
- type: 'item',
- id: newId,
- attributes: {
- title: newTitle,
- location: newLocation,
- created: new Date().getTime(),
- rating: newRating
- }
- }
- })
- this.set('title', undefined)
- this.set('location', undefined)
- this.set('rating', undefined)
- }
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement