Commit b654d06

mo khan <mo@mokhan.ca>
2014-11-21 19:48:03
display a different photo when clicked.
1 parent 266bff4
Changed files (4)
app
controllers
models
templates
tests
unit
controllers
app/controllers/cake.js
@@ -0,0 +1,9 @@
+import Ember from 'ember';
+
+export default Ember.ObjectController.extend({
+  actions: {
+    selectPhoto: function(photo) {
+      this.model.choosePhoto(photo);
+    }
+  }
+});
app/models/cake.js
@@ -8,5 +8,10 @@ export default DS.Model.extend({
   createdAt: DS.attr('date'),
   updatedAt: DS.attr('date'),
 
-  primaryPhoto: Ember.computed.alias('photos.firstObject')
+  primaryPhoto: function(){
+    return this.get('selectedPhoto') || this.get('photos.firstObject');
+  }.property('selectedPhoto', 'photos.firstObject'),
+  choosePhoto: function(photo) {
+    this.set('selectedPhoto', photo);
+  },
 });
app/templates/cake.hbs
@@ -11,13 +11,15 @@
     <p>Updated at: {{formatted-date updatedAt 'MMM Do, YYYY [at] h:mm'}}</p>
   </div>
 </div>
+{{#if 'photos.length === 1'}}
 <div class="row">
   {{#each photos}}
   <div class="col-sm-2 col-md-2">
-    <a href="#" class="thumbnail">
-      <img {{bind-attr src=thumbUrl}} {{bind-attr alt=name}}>
+    <a class="thumbnail">
+      <img {{bind-attr src=thumbUrl}} {{bind-attr alt=name}} {{action 'selectPhoto' this}}>
     </a>
   </div>
   {{/each}}
 </div>
+{{/if}}
 {{outlet}}
tests/unit/controllers/cake-test.js
@@ -0,0 +1,15 @@
+import {
+  moduleFor,
+  test
+} from 'ember-qunit';
+
+moduleFor('controller:cake', 'CakeController', {
+  // Specify the other units that are required for this test.
+  // needs: ['controller:foo']
+});
+
+// Replace this with your real tests.
+test('it exists', function() {
+  var controller = this.subject();
+  ok(controller);
+});