2016-08-01 15:07:46 +02:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2016-07-27 17:26:20 +02:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
const {
|
|
|
|
isEmpty,
|
|
|
|
computed,
|
|
|
|
set,
|
|
|
|
get
|
|
|
|
} = Ember;
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
newUser: { firstname: "", lastname: "", email: "", active: true },
|
2016-07-28 15:17:14 +02:00
|
|
|
firstnameEmpty: computed.empty('newUser.firstname'),
|
|
|
|
lastnameEmpty: computed.empty('newUser.lastname'),
|
|
|
|
emailEmpty: computed.empty('newUser.email'),
|
|
|
|
hasFirstnameEmptyError: computed.and('firstnameEmpty', 'firstnameError'),
|
|
|
|
hasLastnameEmptyError: computed.and('lastnameEmpty', 'lastnameError'),
|
|
|
|
hasEmailEmptyError: computed.and('emailEmpty', 'emailError'),
|
2016-07-27 17:26:20 +02:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
add() {
|
2016-08-01 15:07:46 +02:00
|
|
|
if (isEmpty(this.get('newUser.firstname'))) {
|
2016-07-28 15:17:14 +02:00
|
|
|
set(this, 'firstnameError', true);
|
2016-07-27 17:26:20 +02:00
|
|
|
return $("#newUserFirstname").focus();
|
|
|
|
}
|
2016-08-01 15:07:46 +02:00
|
|
|
if (isEmpty(this.get('newUser.lastname'))) {
|
2016-07-28 15:17:14 +02:00
|
|
|
set(this, 'lastnameError', true);
|
2016-07-27 17:26:20 +02:00
|
|
|
return $("#newUserLastname").focus();
|
|
|
|
}
|
2016-08-01 15:07:46 +02:00
|
|
|
if (isEmpty(this.get('newUser.email')) || is.not.email(this.get('newUser.email'))) {
|
2016-07-28 15:17:14 +02:00
|
|
|
set(this, 'emailError', true);
|
2016-07-27 17:26:20 +02:00
|
|
|
return $("#newUserEmail").focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
let user = get(this, 'newUser');
|
|
|
|
|
|
|
|
get(this, 'add')(user).then(() => {
|
|
|
|
this.set('newUser', { firstname: "", lastname: "", email: "", active: true });
|
2016-07-28 15:17:14 +02:00
|
|
|
set(this, 'firstnameError', false);
|
|
|
|
set(this, 'lastnameError', false);
|
|
|
|
set(this, 'emailError', false);
|
2016-07-27 17:26:20 +02:00
|
|
|
$("#newUserFirstname").focus();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|