Last active
December 22, 2015 12:18
-
-
Save superlou/6471462 to your computer and use it in GitHub Desktop.
Getting attributes before they're resolved
This file contains 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
attr = Ember.attr | |
hasMany = Ember.hasMany | |
Library.Book = Ember.Model.extend | |
id: attr(Number) | |
code: attr() | |
volume: attr() | |
stock: attr(Number) | |
title: attr() | |
adult: attr() | |
notes: attr() | |
checkouts: hasMany('Library.Checkout',{key: 'checkout_ids'}) | |
available: (-> | |
copies_out = @get('checkouts').filterProperty('status', 'out').get('length') | |
@get('stock') - copies_out | |
).property('stock', 'checkouts.@each.status') | |
full_title: (-> | |
volume = @get('volume') | |
if volume | |
@get('title') + ", vol. " + volume | |
else | |
@get('title') | |
).property('title', 'volume') | |
Library.Book.reopenClass | |
findByCode: (code) -> | |
@find('code:' + code) | |
cloneVolumeFrom: (original_id) -> | |
@fetch(original_id).then (item)-> | |
cloned_book = Library.Book.create | |
title: item.get('title') | |
notes: item.get('notes') | |
return cloned_book | |
Library.Book.url = '/books' | |
Library.Book.adapter = Library.RESTAdapter.create() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment