Skip to content

Commit

Permalink
Section: Hands-on, lending articles.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuiles committed Jul 18, 2015
1 parent f9e5d27 commit 262f8c1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ActiveModelAdapter from 'active-model-adapter';

export default ActiveModelAdapter.extend({
namespace: 'api'
namespace: 'api/v2'
});
4 changes: 3 additions & 1 deletion app/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default DS.Model.extend({
createdAt: DS.attr('date'),
description: DS.attr('string'),
notes: DS.attr('string'),
state: DS.attr('string'),
state: DS.attr('string', {
defaultValue: 'borrowed'
}),
friend: DS.belongsTo('friend')
});
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Router.map(function() {
path: ':friend_id'
}, function() {
this.route('articles', {resetNamespace: true}, function() {
this.route('new');
});
});

Expand Down
21 changes: 21 additions & 0 deletions app/routes/articles/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.createRecord('article', {
friend: this.modelFor('friends/show')
});
},
actions: {
save() {
var model = this.modelFor('articles/new');

model.save().then(() => {
this.transitionTo('articles');
});
},
cancel() {
this.transitionTo('articles');
}
}
});
9 changes: 9 additions & 0 deletions app/templates/articles/-form.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<form>
<h2>{{errorMessage}}</h2>
<fieldset>
{{input value=model.description placeholder="Description"}}<br>
{{input value=model.notes placeholder="Notes"}}<br>
<button {{action "save"}} class="primary">Save</button>
<button {{action "cancel"}}>Cancel</button>
</fieldset>
</form>
2 changes: 2 additions & 0 deletions app/templates/articles/new.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2> Lending new articles</h2>
{{partial "articles/form"}}
1 change: 1 addition & 0 deletions app/templates/friends/show.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<p>{{model.lastName}}</p>
<p>{{model.email}}</p>
<p>{{model.twitter}}</p>
<p>{{link-to "Lend article" "articles.new"}}</p>
<p>{{link-to "Edit info" "friends.edit" model}}</p>
<p><a href="#" {{action "delete" model}}>delete</a></p>
</div>
Expand Down

0 comments on commit 262f8c1

Please sign in to comment.