mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
dd50cca97a
Closes #3511, Closes #3512, Closes #3526 - show* methods now close existing passive notifications by default. They also now take an optional options object where existing parameters such as "delayed" and "defaultErrorText" can be passed in as well as the new "doNotClosePassive" flag. - Removed all explicit calls to notifications.closePassive except for the few places where it makes sense to call it separately.
63 lines
2 KiB
JavaScript
63 lines
2 KiB
JavaScript
var InviteNewUserController = Ember.Controller.extend({
|
|
//Used to set the initial value for the dropdown
|
|
authorRole: Ember.computed(function () {
|
|
var self = this;
|
|
return this.store.find('role').then(function (roles) {
|
|
var authorRole = roles.findBy('name', 'Author');
|
|
//Initialize role as well.
|
|
self.set('role', authorRole);
|
|
return authorRole;
|
|
});
|
|
}),
|
|
|
|
confirm: {
|
|
accept: {
|
|
text: 'send invitation now'
|
|
},
|
|
reject: {
|
|
buttonClass: 'hidden'
|
|
}
|
|
},
|
|
|
|
actions: {
|
|
setRole: function (role) {
|
|
this.set('role', role);
|
|
},
|
|
confirmAccept: function () {
|
|
var email = this.get('email'),
|
|
role = this.get('role'),
|
|
self = this,
|
|
newUser;
|
|
|
|
newUser = self.store.createRecord('user', {
|
|
email: email,
|
|
status: 'invited',
|
|
role: role
|
|
});
|
|
|
|
newUser.save().then(function () {
|
|
var notificationText = 'Invitation sent! (' + email + ')';
|
|
|
|
// If sending the invitation email fails, the API will still return a status of 201
|
|
// but the user's status in the response object will be 'invited-pending'.
|
|
if (newUser.get('status') === 'invited-pending') {
|
|
self.notifications.showWarn('Invitation email was not sent. Please try resending.');
|
|
} else {
|
|
self.notifications.showSuccess(notificationText, false);
|
|
}
|
|
}).catch(function (errors) {
|
|
newUser.deleteRecord();
|
|
self.notifications.showErrors(errors);
|
|
});
|
|
|
|
self.set('email', null);
|
|
self.set('role', null);
|
|
},
|
|
|
|
confirmReject: function () {
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
|
|
export default InviteNewUserController;
|