master
1class csx.Models.Cake extends Backbone.Model
2 paramRoot: 'cake'
3
4 defaults:
5 id: null
6 name: null
7 story: null
8 created_at: null
9 updated_at: null
10 category_id: null
11
12 validate: (attributes, options) ->
13 return "Name can't be blank" unless attributes.name && attributes.name.trim()
14 return "Category can't be blank" unless attributes.category_id
15
16 photos: ->
17 cake_id = @id
18 new Backbone.Collection(csx.Collections.Photo.filter((photo) => photo.get("cake_id") == cake_id))
19
20 public_url: ->
21 "#{window.location.origin}/creations/#{@get('slug')}"
22
23 category_id: ->
24 @get('category_id') || @get('category').id
25
26class csx.Collections.CakesCollection extends Backbone.Collection
27 model: csx.Models.Cake
28 url: '/api/v1/cakes'
29
30csx.Models.Creation = csx.Models.Cake