Created
November 15, 2016 21:57
-
-
Save gauthierm/cfe0f899671ea1288604b548ebfad206 to your computer and use it in GitHub Desktop.
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
import DS from 'ember-data'; | |
import Ember from 'ember'; | |
export default DS.Model.extend({ | |
createdAt: DS.attr('date'), | |
updatedAt: DS.attr('date'), | |
firstName: DS.attr('string'), | |
lastName: DS.attr('string'), | |
suffix: DS.attr('string'), | |
company: DS.attr('string'), | |
phone: DS.attr('string'), | |
line1: DS.attr('string'), | |
line2: DS.attr('string'), | |
city: DS.attr('string'), | |
postalCode: DS.attr('string'), | |
provStateOther: DS.attr('string'), | |
// Relationships | |
country: DS.belongsTo('country'), | |
provState: DS.belongsTo('prov-state'), | |
// Computed | |
fullName: Ember.computed('firstName', 'lastName', 'suffix', function () { | |
if (this.get('suffix')) { | |
return `${this.get('firstName')} ${this.get('lastName')}, ${this.get('suffix')}`; | |
} | |
return `${this.get('firstName')} ${this.get('lastName')}`; | |
}), | |
copyFrom(address) { | |
const keys = [ | |
'firstName', | |
'lastName', | |
'suffix', | |
'company', | |
'phone', | |
'line1', | |
'line2', | |
'city', | |
'postalCode', | |
'provStateOther', | |
'country', | |
'provState', | |
]; | |
const values = keys.map(key => address.get(key)); | |
const properties = keys.reduce((map, key, index) => { | |
const newMap = map; | |
newMap[key] = values[index]; | |
return newMap; | |
}, {}); | |
this.setProperties(properties); | |
return this; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment