Ember Latest

The latest build of Ember.

HTML

<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<script type="text/x-handlebars" data-template-name="application">
    <h1>ember-latest jsfiddle</h1>
    {{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="foos">
  {{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="foos/index">
  <ul>
  {{#each itemController='pollItem'}}
      <li>
          {{#link-to 'foos.show' id}}
              {{firstName}} {{lastName}}
          {{/link-to}}
          {{x-vote votes=votes}}
      </li>
  {{/each}}
   </ul>
</script>
<script type="text/x-handlebars" data-template-name="foos/show">
  {{link-to 'Show All' 'foos'}}
  <div>First name: {{firstName}}</div>
  <div>Last name: {{lastName}}</div>
  <div>Votes: {{votes}}</div>
</script>

<script type="text/x-handlebars" data-template-name="x-vote">
    Vote: {{votes}} <button {{action 'vote-up'}}>up</button> <button {{action 'vote-down'}}>down</button>
</script>

CSS

h1 { font-size: 1.6em; padding-bottom: 10px; }
h2 { font-size: 1.4em; }
ul { padding: 15px; font-size: 1.4em; color: green; }

JavaScript

App = Ember.Application.create({});

App.Router.map(function() {
    this.resource('foos', { path: '/' }, function() {
        this.route('show', { path: '/:id' });
    });
});

var FIXTURE = [
    {id: 1, firstName: 'Kris', lastName: 'Selden', votes: 1},
    {id: 2, firstName: 'Luke', lastName: 'Melia', votes: 5},
    {id: 3, firstName: 'Formerly Alex', lastName: 'Matchneer', votes: 10}
];

App.ApplicationController = Ember.Controller.extend({
    needs: ['tracker'],
    logUrl: function() {
        this.get('controllers.tracker').pathChanged(this.get('currentPath'));
    }.observes('currentPath')
});

App.FoosRoute = Ember.Route.extend({});

App.FoosIndexRoute = Ember.Route.extend({
    model: function() {
      return FIXTURE;
    }
});

App.FoosShowRoute = Ember.Route.extend({
    model: function(params) {
      return FIXTURE.findBy('id', parseInt(params.id, 10));
    }
});

App.TrackerController = Ember.Controller.extend({
    pathChanged: function(currentPath) {
        // log your path change
        alert('logging ' + currentPath);
    },
    trackVote: function(name, votes) {
        // log your votes
        alert(name + ' has ' + votes + ' votes');
    }
});

App.PollItemController = Ember.ObjectController.extend({
    needs: ['tracker'],
    
    fullName: function() {
        return this.get('firstName') + ' ' + this.get('lastName');
    }.property('firstName', 'lastName'),
    
    logOnVoted: function() {
        this.get('controllers.tracker').trackVote(this.get('fullName'), this.get('votes'));
    }.observes('votes')
});

App.XVoteComponent = Ember.Component.extend({
    templateName: 'x-vote',
    votes: 0,
    actions: {
        'vote-up': function() {
            this.incrementProperty('votes');
        },
        'vote-down': function() {
            if(this.get('votes') > 0) {
                this.decrementProperty('votes');
            }
        }
    }
});