Last active
August 29, 2015 14:05
-
-
Save szabcsee/caf172a792fa0dbf8c2c to your computer and use it in GitHub Desktop.
Ember data questions
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 = Ember.Application.create({ | |
LOG_TRANSITIONS_INTERNAL: true, | |
LOG_ACTIVE_GENERATION: true, | |
LOG_VIEW_LOOKUPS: true, | |
LOG_RESOLVER: true | |
}); | |
Ember.run.backburner.DEBUG = true; | |
Ember.ENV.RAISE_ON_DEPRECATION = true; | |
Ember.LOG_STACKTRACE_ON_DEPRECATION = true; | |
Ember.LOG_BINDINGS = true; | |
Ember.RSVP.on('error', function(error) { | |
Ember.Logger.assert(false, error); | |
}); | |
App.ApplicationSerializer = DS.RESTSerializer.extend({ | |
primaryKey: 'key' | |
}); | |
App.Artwork = DS.Model.extend({ | |
"created-at": DS.attr('date', { defaultValue: new Date() }), | |
"updated-at": DS.attr('date', { defaultValue: new Date() }), | |
title: DS.attr('string'), | |
genre: DS.attr('string'), | |
"word-count": DS.attr('string'), | |
"doc-key": DS.attr('string'), | |
critiques: DS.hasMany('critique') | |
}); | |
App.Doc = DS.Model.extend({ | |
"created-at": DS.attr('date', { defaultValue: new Date() }), | |
"updated-at": DS.attr('date', { defaultValue: new Date() }), | |
body: DS.attr('string') | |
}); | |
App.Critique = DS.Model.extend({ | |
"created-at": DS.attr('date', { defaultValue: new Date() }), | |
"updated-at": DS.attr('date'), | |
text: DS.attr('string'), | |
artwork: DS.belongsTo('artwork', { inverse: 'critiques' }) | |
}); | |
App.Router.map(function(){ | |
this.resource('artworks', { path: '/artworks' }, function() { | |
this.resource('artwork', { path: '/:artwork_id'}, function() { | |
this.route('edit'); | |
this.resource('critiques', { path: '/critiques'}, function() { | |
this.route('create', { path: '/create' }); | |
this.resource('critique', { path: '/:critique_id'}); | |
this.route('edit'); | |
}); | |
}); | |
}); | |
}); | |
App.ArtworksRoute = Ember.Route.extend({ | |
model: function() { | |
return this.store.find('artwork'); | |
} | |
}); | |
App.ArtworkController = Ember.ArrayController.extend({ | |
}); | |
App.DocsRoute = Ember.Route.extend({ | |
model: function() { | |
return this.store.find('doc'); | |
} | |
}); | |
App.DocRoute = Ember.Route.extend({ | |
model: function(params) { | |
return this.store.find('doc', params.doc-key); | |
} | |
}); | |
App.ArtworkRoute = Ember.Route.extend({ | |
model: function(params) { | |
return this.store.find('artwork', params.artwork_id); | |
} | |
}); | |
App.CritiquesRoute = Ember.Route.extend({ | |
model: function() { | |
return this.store.find('critique'); | |
} | |
}); | |
App.ArtworksIndexController = Ember.ArrayController.extend({ | |
newTitle: '', | |
disabled: function() { | |
return Ember.isEmpty(this.get('newTitle')); | |
}.property('newTitle'), | |
actions: { | |
save: function () { | |
var docu = this.store.createRecord('doc', {body: this.get('newBody')}); | |
var wordCount = this.get('newBody').length.toString(); | |
var art = this.store.createRecord('artwork', {title: this.get('newTitle'), genre: this.get('newGenre'), 'word-count': wordCount}); | |
docu.save().then(function(record){ | |
art.set('doc-key', record.id).save(); | |
}); | |
this.set('newTitle', ''); | |
this.set('newGenre', ''); | |
this.set('newBody', ''); | |
return false; | |
} | |
} | |
}); |
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> | |
<script src="//code.jquery.com/jquery-2.1.0.min.js"></script> | |
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
<meta charset="utf-8"/> | |
<title>Vonalasfüzet.hu - Portál Íróknak</title> | |
<link rel="stylesheet" href="css/normalize.css"> | |
<link rel="stylesheet" href="css/bootstrap-theme.min.css" media="screen"/> | |
<link rel="stylesheet" href="css/style.css"> | |
</head> | |
<body> | |
<script type="text/x-handlebars" data-template-name="application"> | |
<div class="navbar navbar-default"> | |
{{#link-to 'application' class="navbar-brand"}}HOME{{/link-to}} | |
<ul class="nav navbar-nav"> | |
<li>{{#link-to 'artworks.index'}}Artworks{{/link-to}}</li> | |
</ul> | |
</div> | |
<div class="container"> | |
{{outlet}} | |
</div> | |
</script> | |
<script type="text/x-handlebars" data-template-name="index"> | |
<h1>Welcome Home</h1> | |
</script> | |
<script type="text/x-handlebars" data-template-name="artwork"> | |
<h2>{{title}}</h2> | |
</script> | |
<script type="text/x-handlebars" data-template-name="artworks/index"> | |
<div class="col-md-4"> | |
<ul class="list-group"> | |
<li class="list-group-item"> | |
{{input type="text" class="new-artwork" placeholder="New Title" value=newTitle}} | |
{{input type="text" class="new-artwork" placeholder="New Genre" value=newGenre}} | |
{{input type="text" class="new-document" placeholder="Write your stories here" value=newBody}} | |
<button {{action 'save'}} class="btn btn-primary btn-sm new-doc-button" {{bind-attr disabled=disabled}}>Add</button> | |
</li> | |
{{#each}} | |
<li class="list-group-item">{{title}}</li> | |
{{/each}} | |
</ul> | |
</div> | |
</script> | |
<script type="text/x-handlebars" data-template-name="artworks/critiques"> | |
{{#each critiques}} | |
<div class="list-group-item"> | |
{{doc-key}} | |
{{artwork-key}} | |
{{usefulness}} | |
{{rating}} | |
{{key}} | |
</div> | |
{{/each}} | |
</script> | |
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script> | |
<script src="http://builds.emberjs.com/tags/v1.6.1/ember.js"></script> | |
<script src="http://builds.emberjs.com/tags/v1.0.0-beta.8/ember-data.js"></script> | |
<script src="js/app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment