Created
March 18, 2014 07:34
-
-
Save selvagsz/9615207 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Put your CSS here */ | |
html, body { | |
margin: 20px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Ember Starter Kit</title> | |
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.2.1.js"></script> | |
<script src="http://builds.emberjs.com/tags/v1.4.0/ember.js"></script> | |
<script src="http://builds.emberjs.com/tags/v1.0.0-beta.7/ember-data.js"></script> | |
</head> | |
<body> | |
<script type="text/x-handlebars" data-template-name='application'> | |
<h2>App template</h2> | |
{{link-to 'groups' 'groups'}} | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name='groups'> | |
<h2>Group template</h2> | |
{{view Em.Select content=content optionValuePath='content.id' optionLabelPath='content.title' value=group_id prompt="Select a guy"}} | |
{{group_id}} | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name='products'> | |
<h2>Product template</h2> | |
{{#each}} | |
<div> | |
{{link-to title 'logs' group_id id}} | |
</div> | |
{{/each}} | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name='logs'> | |
<h2>Log template</h2> | |
{{#each}} {{description}} {{/each}} | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var App = window.App = Em.Application.create({ | |
LOG_TRANSITIONS: true | |
}); | |
App.ApplicationAdapter = DS.FixtureAdapter.extend({ | |
queryFixtures: function(fixtures, query, type) { | |
var key = Em.keys(query)[0]; | |
return fixtures.filterBy(key, query[key]); | |
} | |
}); | |
App.Group = DS.Model.extend({ | |
title: DS.attr('string') | |
}); | |
App.Product = DS.Model.extend({ | |
title: DS.attr('string'), | |
group_id: DS.attr('string') | |
}); | |
App.Log = DS.Model.extend({ | |
description: DS.attr('string'), | |
product_id: DS.attr('string') | |
}); | |
App.Router.map(function() { | |
this.resource('groups', function(){ | |
this.resource('products', {path: ':id/products'}, function() { | |
this.resource('logs', {path:':id/logs'}); | |
}); | |
}); | |
}); | |
App.GroupsRoute = Em.Route.extend({ | |
model: function() { | |
return this.store.find('group'); | |
}, | |
actions: { | |
goToProducts: function(group_id){ | |
this.transitionTo('products', group_id); | |
} | |
} | |
}); | |
App.GroupsController = Em.ObjectController.extend({ | |
groupDidChange: function() { | |
this.transitionToRoute('products', this.get('group_id')); | |
}.observes('group_id') | |
}); | |
App.ProductsRoute = Em.Route.extend({ | |
model: function(params) { | |
return this.store.find("product", {group_id: Em.get(params, 'id')}); | |
}, | |
serialize: function(model) { | |
return { | |
id: Em.get(model, 'group_id') | |
}; | |
} | |
}); | |
App.LogsRoute = Em.Route.extend({ | |
model: function(params){ | |
return this.store.find("log", {product_id: Em.get(params, 'id')}); | |
} | |
}); | |
//Fixtures | |
App.Group.FIXTURES = [ | |
{ | |
id: 1, | |
title: 'Group Tom' | |
}, | |
{ | |
id: 2, | |
title: 'Group Yehuda' | |
}, | |
{ | |
id: 3, | |
title: 'Group Machty' | |
} | |
]; | |
App.Product.FIXTURES = [ | |
{ | |
id: 1, | |
title: 'Product Tom', | |
group_id: '1' | |
}, | |
{ | |
id: 2, | |
title: 'Product Yehuda', | |
group_id: '1' | |
}, | |
{ | |
id: 3, | |
title: 'Product Machty', | |
group_id: '2' | |
} | |
]; | |
App.Log.FIXTURES = [ | |
{ | |
id: 1, | |
description: "Ember.js - A JavaScript framework for creating ambitious web applications", | |
product_id: "1" | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment