2016-09-13 15:14:17 -04:00
|
|
|
export default Ember.Component.extend({
|
|
|
|
classNames: ['invite-list'],
|
|
|
|
users: null,
|
|
|
|
inviteEmail: '',
|
|
|
|
inviteRole: '',
|
|
|
|
invalid: false,
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super();
|
|
|
|
this.set('users', []);
|
|
|
|
|
|
|
|
this.set('roles', [
|
|
|
|
{id: 'moderator', label: I18n.t('wizard.invites.roles.moderator') },
|
|
|
|
{id: 'regular', label: I18n.t('wizard.invites.roles.regular') },
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.updateField();
|
|
|
|
},
|
|
|
|
|
|
|
|
keyPress(e) {
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
this.send('addUser');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updateField() {
|
2016-09-20 12:28:22 -04:00
|
|
|
const users = this.get('users');
|
|
|
|
|
|
|
|
this.set('field.value', JSON.stringify(users));
|
2016-09-21 17:15:57 -04:00
|
|
|
|
2016-09-22 10:01:25 -04:00
|
|
|
const staffCount = this.get('step.fieldsById.staff_count.value') || 1;
|
2016-09-21 17:15:57 -04:00
|
|
|
const showWarning = (staffCount < 3 && users.length === 0);
|
|
|
|
|
|
|
|
this.set('field.warning', showWarning ? 'invites.none_added' : null);
|
2016-09-13 15:14:17 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
addUser() {
|
|
|
|
const user = {
|
|
|
|
email: this.get('inviteEmail') || '',
|
|
|
|
role: this.get('inviteRole')
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!/(.+)@(.+){2,}\.(.+){2,}/.test(user.email)) {
|
|
|
|
return this.set('invalid', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const users = this.get('users');
|
2016-10-26 15:44:36 -04:00
|
|
|
if (users.findBy('email', user.email)) {
|
2016-09-13 15:14:17 -04:00
|
|
|
return this.set('invalid', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('invalid', false);
|
|
|
|
|
|
|
|
users.pushObject(user);
|
|
|
|
this.updateField();
|
|
|
|
|
|
|
|
this.set('inviteEmail', '');
|
|
|
|
Ember.run.scheduleOnce('afterRender', () => this.$('.invite-email').focus());
|
|
|
|
},
|
|
|
|
|
|
|
|
removeUser(user) {
|
|
|
|
this.get('users').removeObject(user);
|
|
|
|
this.updateField();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|