Skip to content

Instantly share code, notes, and snippets.

@abobwhite
Created September 12, 2013 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abobwhite/6544752 to your computer and use it in GitHub Desktop.
Save abobwhite/6544752 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.0.0/ember.js"></script>
<script src="http://builds.emberjs.com/tags/v1.0.0-beta.2/ember-data.js"></script>
<title>Ember JS Bin</title>
</head>
<body>
<script type="text/x-handlebars" data-template-name="application">
<h1>Ember JS Bin</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Test Content</h2>
<button {{action 'goToDashboard'}}>Go to Dashboard</button>
{{#if attempted}}
Try again
{{/if}}
</script>
<script type="text/x-handlebars" data-template-name="dashboard">
<h1>Dashboard</h1>
{{#link-to 'index'}}back{{/link-to}}
<div id="success"></div>
</script>
</body>
</html>
App = Ember.Application.create({});
App.TestAdapter = DS.RESTAdapter.extend({
counter: 0,
find: function(type, id){
if(counter < 1){
counter++;
return Ember.RSVP.reject();
}
return Ember.RSVP.resolve(DS.PromiseObject.create({promise: Ember.RSVP.resolve}));
}
});
App.ApplicationAdapter = App.TestAdapter;
App.CurrentUser = Ember.Object.create({
id: 7
});
App.Router.map(function (){
this.route('dashboard');
});
App.Membership = DS.Model.extend({
membershipLevel : DS.attr('number'),
status : DS.attr('string')/*, ... */
});
App.IndexController = Ember.Controller.extend({
attempted: false,
actions: {
goToDashboard: function(){
this.set('attempted', true);
console.log('Attempted to access Dashboard');
this.transitionToRoute('dashboard');
}
}
});
App.DashboardRoute = Ember.Route.extend({
model: function(){
console.log('Entering: model');
return this.store.find('membership', App.CurrentUser.get('id'));
},
setupController: function(controller, model){
console.log('Entering: setupController');
controller.set('model', model);
// Force a refresh of the model from Store (not applicable for demo)
/* model.reload().then(function(data){
controller.set('model', data);
}); */
},
actions: {
error: function(reason, transition){
console.log('Entering: error');
console.log(reason);
console.log(transition);
}
}
});
App.DashboardView = Ember.View.extend({
templateName: 'dashboard',
didInsertElement: function(){
$("#success").html('SUCCESSFULLY ROUTED');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment