1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 05:09:42 +02:00
documize/app/app/components/user-profile.js

73 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-07-25 12:05:46 +02:00
import Ember from 'ember';
const {
computed,
isEmpty,
isEqual,
isPresent
} = Ember;
export default Ember.Component.extend({
password: { password: "", confirmation: "" },
2016-07-28 15:17:14 +02:00
hasFirstnameError: computed.empty('model.firstname'),
hasLastnameError: computed.empty('model.lastname'),
hasEmailError: computed.empty('model.email'),
2016-07-25 12:05:46 +02:00
hasPasswordError: computed('passwordError', 'password.password', {
get() {
if (isPresent(this.get('passwordError'))) {
return `error`;
}
if (isEmpty(this.get('password.password'))) {
return null;
}
}
}),
hasConfirmPasswordError: computed('confirmPasswordError', {
get() {
if (isPresent(this.get("confirmPasswordError"))) {
return `error`;
}
return;
}
}),
actions: {
save() {
let password = this.get('password.password');
let confirmation = this.get('password.confirmation');
if (isEmpty(this.model.get('firstname'))) {
return $("#firstname").focus();
}
if (isEmpty(this.model.get('lastname'))) {
return $("#lastname").focus();
}
if (isEmpty(this.model.get('email'))) {
return $("#email").focus();
}
if (isPresent(password) && isEmpty(confirmation)) {
Ember.set(this, 'confirmPasswordError', 'error');
return $("#confirmPassword").focus();
}
if (isEmpty(password) && isPresent(confirmation)) {
Ember.set(this, 'passwordError', 'error');
return $("#password").focus();
}
if (!isEqual(password, confirmation)) {
Ember.set(this, 'passwordError', 'error');
return $("#password").focus();
}
let passwords = this.get('password');
this.get('save')(passwords).finally(() => {
Ember.set(this, 'password.password', '');
Ember.set(this, 'password.confirmation', '');
});
}
}
});