mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-11 16:21:24 -05:00
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
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() {
|
|
this.set('field.value', JSON.stringify(this.get('users')));
|
|
},
|
|
|
|
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');
|
|
if (users.findProperty('email', user.email)) {
|
|
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();
|
|
}
|
|
}
|
|
});
|