Ghost/ghost/admin/controllers/modals/invite-new-user.js
Jason Williams faf6832cab Add validation to invite new user form.
Closes #3246
- Add a UserValidator to the validation engine that runs a set
  of validations based on the user status.
- Added validations for invited users and active users.
2014-07-11 19:09:34 +00:00

57 lines
1.3 KiB
JavaScript

var InviteNewUserController = Ember.Controller.extend({
confirm: {
accept: {
text: 'send invitation now'
},
reject: {
buttonClass: 'hidden'
}
},
// @TODO: replace with roles from server - see issue #3196
roles: [
{
id: 3,
name: 'Author'
}
],
actions: {
confirmAccept: function () {
var email = this.get('email'),
role_id = this.get('role'),
self = this,
newUser;
this.notifications.closePassive();
newUser = this.store.createRecord('user', {
email: email,
role: role_id,
status: 'invited'
});
newUser.save().then(function () {
var notificationText = 'Invitation sent! (' + email + ')';
self.notifications.showSuccess(notificationText, false);
}).catch(function (errors) {
newUser.deleteRecord();
self.notifications.closePassive();
self.notifications.showErrors(errors);
});
this.set('email', null);
this.set('role', null);
},
confirmReject: function () {
return false;
}
}
});
export default InviteNewUserController;