master
 1#= require views/my/cakes/thumbnail_view
 2
 3class csx.Views.My.Cakes.ShowView extends Marionette.CompositeView
 4  template: JST["templates/my/cakes/show"]
 5  childView: csx.Views.My.Cakes.ThumbnailView
 6  childViewContainer: '.card-columns'
 7
 8  events:
 9    "click .add-photo": "launchAddPhoto"
10    "click #remove-cake-button": "removeCake"
11
12  templateHelpers:
13    hasImage: ->
14      typeof(@photos) != 'undefined' && _.any(@photos)
15
16    randomPhoto: ->
17      if @primary_photo_id
18        _.find @photos, (photo) =>
19          photo.id.toString() == @primary_photo_id
20      else
21        @photos[Math.floor(Math.random()*@photos.length)]
22
23  constructor: (options) ->
24    super(options)
25    @collection = @model.photos()
26    @model.set('primary_photo_id', options.photo_id) if options.photo_id
27
28  launchAddPhoto: ->
29    @displayModal(new csx.Views.Photos.NewModalView(cake: @model))
30
31  removeCake: ->
32    @displayModal(new csx.Views.Cakes.DeleteCakeModalView(model: @model))
33
34  displayModal: (view) ->
35    $("#modal").html(view.render().el)
36    $("#modal").modal()