Skip to content

Commit

Permalink
Adds rudimentary validation to user invite
Browse files Browse the repository at this point in the history
refs TryGhost#5652

- with these changes, validation appears, but doesn't properly prevent closing the modal
- this needs revisiting at some point
  • Loading branch information
ErisDS committed Sep 2, 2015
1 parent 5b4a8c6 commit 73080dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
19 changes: 14 additions & 5 deletions core/client/app/controllers/modals/invite-new-user.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Ember from 'ember';
import ValidationEngine from 'ghost/mixins/validation-engine';

export default Ember.Controller.extend({
export default Ember.Controller.extend(ValidationEngine, {
notifications: Ember.inject.service(),

validationType: 'signup',

role: null,
authorRole: null,

Expand Down Expand Up @@ -42,13 +45,13 @@ export default Ember.Controller.extend({
confirmAccept: function () {
var email = this.get('email'),
role = this.get('role'),
validationErrors = this.get('errors.messages'),
self = this,
newUser;

// reset the form and close the modal
self.set('email', '');
self.set('role', self.get('authorRole'));
self.send('closeModal');
this.set('email', '');
this.set('role', self.get('authorRole'));

this.store.find('user').then(function (result) {
var invitedUser = result.findBy('email', email);
Expand Down Expand Up @@ -82,7 +85,13 @@ export default Ember.Controller.extend({
// save is overridden in order to validate, we probably
// want to use inline-validations here and only show an
// alert if we have an actual error
self.get('notifications').showErrors(errors);
if (errors) {
self.get('notifications').showErrors(errors);
} else if (validationErrors) {
self.get('notifications').showAlert(validationErrors.toString(), {type: 'error'});
}
}).finally(function () {
self.get('errors').clear();
});
}
});
Expand Down
6 changes: 6 additions & 0 deletions core/client/app/routes/team/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ var TeamUserRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
model.rollback();
}

model.get('errors').clear();

this._super();
},

actions: {
didTransition: function () {
this.modelFor('team.user').get('errors').clear();
},

save: function () {
this.get('controller').send('save');
}
Expand Down
9 changes: 5 additions & 4 deletions core/client/app/templates/modals/invite-new-user.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
title="Invite a New User" confirm=confirm class="invite-new-user"}}

<fieldset>
<div class="form-group">
{{#gh-form-group errors=errors hasValidated=hasValidated property="email"}}
<label for="new-user-email">Email Address</label>
{{input enter="confirmAccept" class="gh-input email" id="new-user-email" type="email" placeholder="Email Address" name="email" autofocus="autofocus"
autocapitalize="off" autocorrect="off" value=email}}
</div>
{{gh-input enter="confirmAccept" class="email" id="new-user-email" type="email" placeholder="Email Address" name="email" autofocus="autofocus"
autocapitalize="off" autocorrect="off" value=email focusOut=(action "validate" "email")}}
{{gh-error-message errors=errors property="email"}}
{{/gh-form-group}}

<div class="form-group for-select">
<label for="new-user-role">Role</label>
Expand Down

0 comments on commit 73080dc

Please sign in to comment.