Last active
April 4, 2016 06:47
-
-
Save kepek/1d299a9455c7b8ad71a9482344b8419b to your computer and use it in GitHub Desktop.
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
import Ember from 'ember'; | |
import DS from 'ember-data'; | |
import { | |
validator, buildValidations | |
} | |
from 'ember-cp-validations'; | |
const attr = DS.attr; | |
const Validations = buildValidations({ | |
firstName: validator('presence', true), | |
lastName: validator('presence', true) | |
}, { | |
debounce: 500 | |
}); | |
export default DS.Model.extend(Validations, { | |
"firstName": attr('string'), | |
"lastName": attr('string') | |
}); |
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
import Ember from 'ember'; | |
import DS from 'ember-data'; | |
import { validator, buildValidations } from 'ember-cp-validations'; | |
const attr = DS.attr; | |
const Validations = buildValidations({ | |
username: { | |
description: 'Username', | |
validators: [ | |
validator('presence', true), | |
validator('length', { | |
max: 15 | |
}) | |
] | |
}, | |
password: { | |
description: 'Password', | |
validators: [ | |
validator('presence', true), | |
validator('length', { | |
min: 4, | |
max: 8 | |
}), | |
validator('format', { | |
regex: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$/, | |
message: '{description} must include at least one upper case letter, one lower case letter, and a number' | |
}) | |
] | |
}, | |
email: { | |
validators: [ | |
validator('presence', true), | |
validator('format', { | |
type: 'email' | |
}) | |
] | |
} | |
details: validator('belongs-to') | |
}, { | |
debounce: 500 | |
}); | |
export default DS.Model.extend(Validations, { | |
'username': attr('string'), | |
'password': attr('string'), | |
'email': attr('string'), | |
'details': DS.belongsTo('user/detail') | |
}); |
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
import Ember from 'ember' | |
export default Ember.Route.extend(AdapterHashRouteMixin, { | |
model(params) { | |
return Ember.RSVP.hash({ | |
user: this.store.createRecord('user', { | |
details: this.store.createRecord('user/detail') | |
}) | |
}) | |
}, | |
setupController(controller, models) { | |
this._super(...arguments) | |
controller.setProperties(models) | |
}, | |
actions: { | |
createNewUser(model) { | |
model.save().then(() => { | |
Ember.Logger.warn( 'user/then', arguments ) | |
}) | |
.catch(() => { | |
Ember.Logger.warn( 'user/catch', arguments ) | |
}) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment