Commit 52095699

mo khan <mo@mokhan.ca>
2014-09-02 16:36:01
display the selected photo on the cake page.
1 parent a9490cc
Changed files (5)
app
assets
app/assets/javascripts/backbone/controllers/cakes_controller.js.coffee
@@ -10,11 +10,11 @@ class CakeSide.Controllers.CakesController extends Marionette.Controller
     @comment_view.hide()
     @content_region.show(new @views.IndexView(collection: @cakes))
 
-  show: (id) ->
+  show: (id, photo_id) ->
     @selectTab()
     cake = @cakes.get(id)
     @comment_view.hide()
-    @content_region.show(new @views.ShowView(model: cake))
+    @content_region.show(new @views.ShowView(model: cake, photo_id: photo_id))
     #@comment_view.render
       #identifier: "c-#{cake.id}"
       #title: cake.get('name')
app/assets/javascripts/backbone/routers/cakes_router.js.coffee
@@ -3,4 +3,5 @@ class CakeSide.Routers.CakesRouter extends Marionette.AppRouter
     "cakes/new": "newCake"
     "cakes/:id/edit": "edit"
     "cakes/:id": "show"
+    "cakes/:id/:photo_id": "show"
     "cakes": "index"
app/assets/javascripts/backbone/templates/cakes/show.jst.ejs
@@ -19,9 +19,9 @@
 <div class="row-fluid">
   <div class="span6">
     <% if (hasImage()) { %>
-    <% random_photo = randomPhoto()%>
-    <a href="#cakes/<%= id %>/photos/<%= random_photo.id %>">
-      <img class="thumbnail" src="<%= random_photo.large_url %>" alt="<%= name %>" />
+    <% photo = randomPhoto()%>
+    <a href="#cakes/<%= id %>/photos/<%= photo.id %>">
+      <img class="thumbnail" src="<%= photo.large_url %>" alt="<%= name %>" />
     </a>
     <% } %>
   </div>
@@ -45,12 +45,6 @@
     <p><%= story %></p>
   </div>
 </div>
-<div class="row-fluid">
-  <div class="span12">
-    <a class="btn add-photo">Add Photo</a>
-    <a href="#cakes/<%= id %>/edit">(edit)</a>
-  </div>
-</div>
 <div class="row-fluid">
   <ul class="thumbnails"></ul>
 </div>
app/assets/javascripts/backbone/templates/cakes/thumbnail.jst.ejs
@@ -4,7 +4,8 @@
       <div class="bar" style="width: <%= percentComplete %>%;"></div>
     </div>
   <% } else { %>
-    <a href="#cakes/<%= cake_id %>/photos/<%= id %>">
+    <!-- <a href="#cakes/<%= cake_id %>/photos/<%= id %>"> -->
+    <a href="#cakes/<%= cake_id %>/<%= id %>">
       <img src="<%= thumb_url %>" />
     </a>
   <% } %>
app/assets/javascripts/backbone/views/cakes/show_view.js.coffee
@@ -15,11 +15,16 @@ class CakeSide.Views.Cakes.ShowView extends Marionette.CompositeView
       typeof(@photos) != 'undefined' && _.any(@photos)
 
     randomPhoto: ->
-      @photos[Math.floor(Math.random()*@photos.length)]
+      if @primary_photo_id
+        _.find @photos, (photo) =>
+          photo.id.toString() == @primary_photo_id
+      else
+        @photos[Math.floor(Math.random()*@photos.length)]
 
   constructor: (options) ->
     super(options)
     @collection = @model.photos()
+    @model.set('primary_photo_id', options.photo_id) if options.photo_id
 
   launchAddPhoto: ->
     @displayModal(new CakeSide.Views.Photos.NewModalView(cake: @model))