Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import Ember from 'ember'
  2.  
  3. export default Ember.Component.extend({
  4. store: Ember.inject.service(),
  5. title: undefined,
  6. location: undefined,
  7. rating: undefined,
  8.  
  9. inputRatings: [{
  10. label: 'Not rated',
  11. value: 0
  12. },{
  13. label: 'Bad',
  14. value: 1
  15. },{
  16. label: 'Average',
  17. value: 2
  18. },{
  19. label: 'Good',
  20. value: 3
  21. }],
  22.  
  23. init () {
  24. this._super(...arguments)
  25.  
  26. this.set('title', this.get('title'))
  27. this.set('location', this.get('location'))
  28. this.set('rating', this.get('rating'))
  29. },
  30.  
  31. actions: {
  32. submit () {
  33. let newTitle = this.get('title')
  34. let newLocation = this.get('location')
  35. let newRating = this.get('rating')
  36. let ids = this.get('store').peekAll('item').mapBy('id')
  37. let newId = Math.max(...ids) + 1
  38.  
  39. if (!newTitle || !newLocation || !newRating) {
  40. return
  41. }
  42.  
  43. var newItem = this.get('store').pushPayload({
  44. data: {
  45. type: 'item',
  46. id: newId,
  47. attributes: {
  48. title: newTitle,
  49. location: newLocation,
  50. created: new Date().getTime(),
  51. rating: newRating
  52. }
  53. }
  54. })
  55. this.set('title', undefined)
  56. this.set('location', undefined)
  57. this.set('rating', undefined)
  58. }
  59. }
  60. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement