Trying to reload dirty records

For http://stackoverflow.com/questions/15804405/how-can-i-ignore-dirty-records-when-refreshing-a-list-from-the-server

by ekidd

HTML

<script src="https://s3.amazonaws.com/kiddsoftware-jsfiddle/handlebars-1.0.0-rc.3.js"></script>
<script src="https://s3.amazonaws.com/kiddsoftware-jsfiddle/ember-1.0.0-rc.2.js"></script>
<script src="https://s3.amazonaws.com/kiddsoftware-jsfiddle/ember-data-a29070da.js"></script>
<script type="text/x-handlebars">
    <h1>Trying to reload dirty records</h1>
    {{outlet}}
</script>

<script type="text/x-handlebars" data-template-name="contacts">
    <ul>
       {{#each contact in controller}}
           <li>{{#linkTo 'contact' contact}}{{contact.name}}{{/linkTo}}</li>
       {{/each}}
    </ul>
</script>

<script type="text/x-handlebars" data-template-name="contact">
    <p>Name: {{view Ember.TextField valueBinding="name"}}</p>
    <p>{{#linkTo 'contacts'}}All contacts{{/linkTo}}</p>
</script>

JavaScript

window.App = Ember.Application.create();

App.Store = DS.Store.extend({
    revision: 12,
    adapter: DS.FixtureAdapter.create()
});

App.Contact = DS.Model.extend({
    name: DS.attr("string") 
});

App.Contact.reopenClass({
    cache: null,
    
    findAllWithRefresh: function () {
        if (this.cache === null) {
            this.cache = this.find();
        } else {
            this.cache.forEach(function (c) {
                if (c.get("isLoaded") && !c.get("isSaving") &&  !c.get("isError") && !c.get("isDeleted") && !c.get("isDirty") && !c.get("isReloading")) {
                    console.log("Refreshing", c);
                    c.reload();
                } else {
                    console.log("Can't refresh", c);
                }
            });        
        }
        return this.cache;
    }
});

App.Contact.FIXTURES = [{
    id: 1,
    name: "Jane Q. Public"
}, {
    id: 2,
    name: "John Q. Public"
}];

App.Router.map(function () {
    this.route("contacts", { path: "/" });
    this.route("contact", { path: "/contact/:contact_id" });
});

App.ContactsRoute = Ember.Route.extend({
    model: function (params) {
        return App.Contact.findAllWithRefresh();  
    }
});

App.ContactRoute = Ember.Route.extend({
    model: function (params) {
        return App.Contact.find(params.contact_id);  
    }
});