Skip to content

Instantly share code, notes, and snippets.

#Must be defined before you create the application.
DS.RESTAdapter.registerTransform 'array',
deserialize: (value) -> if Ember.isArray value then Em.A(value) else Em.A()
serialize : (value) -> if Ember.isArray value then Em.A(value) else Em.A()
{ [ { id: "32111aae", spot_number: "BAH", commercials: [{ id: "33321eaz", title: "yar"}] } ] }
Binder.Spot = DS.Model.extend({
spot_number: DS.attr('string')
});
Binder.Commercial = DS.Model.extend({
title: DS.attr('string'),
spot: DS.belongsTo(Binder.Spot)
});
@cloke
cloke / gist:4637506
Last active December 11, 2015 17:49
this.set('content.name', 'test');
Content isDirty is set to true and css class is added.
record = App.Model.createRecord();
this.set('content', record);
Content isDirty is set to true and css class is not added.
{{view.content.isDirty}}
<div class="label label-important" {{bindAttr class="view.content.isDirty:unsaved"}}>unsaved changes</div>
#= require_tree .
window.App = App = Ember.Application.create()
App.Models = {}
App.Views = {}
# Models
DS.Adapter.configure 'plurals',
sticky: 'stickies'
@cloke
cloke / gist:4616769
Last active December 11, 2015 14:49 — forked from earnold/gist:4616732
EmberTodo.ItemController = Ember.ObjectController.extend({
completed: function(key, value) {
if (arguments.length > 1){
var item = this.get("content");
console.log("initial value");
console.log(item.get("completed"));
item.set("completed", value);
console.log("after value");
console.log(item.get("completed"));
console.log("is dirty?");
@cloke
cloke / html.html
Last active December 11, 2015 14:28 — forked from mklew/html.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="scripts/vendor/jquery.min.js"></script>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap.js"></script>
<title>Skillshare</title>
#Model
Diets.FoodNutrient = DS.Model.extend
amount: DS.attr 'string'
name: DS.attr 'string'
nutrient_id: DS.attr 'string'
Diets.Food = DS.Model.extend
brand: DS.attr 'string'
food_nutrients: DS.hasMany( Diets.FoodNutrient )
@cloke
cloke / gist:4519996
Last active December 11, 2015 00:58
{ food: {_id: 'bc4', brand: 'test', food_nutrients: [{ _id: 'af1', name: 'sodium'}] }
FoodNutrient = DS.Model.extend({
name: DS.attr( 'string' )
});
Food = DS.Model.extend(
brand: DS.attr( 'string' ),
food_nutrients: DS.hasMany( Diets.FoodNutrient )
});
@cloke
cloke / gist:4495264
Last active December 10, 2015 21:28
MyApp.MyCollectionView = Ember.CollectionView.create({
tagName: 'ul'
contentBinding: 'some array controller',
itemViewClass: Ember.View.extend({
tagName: 'li'
template: Ember.Handlebars.compile("the letter: {{view.content}}")
})
});
/** MUTLIPLE STATE MANAGERS **/
activeStateManagers: null,
getStateManager: function(stateManager) {
return (typeof stateManager === 'string') ?
this.get(stateManager+'StateManager') :
stateManager;
},