0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Adds rudimentary validation to user invite

refs #5652

- with these changes, validation appears, but doesn't properly prevent closing the modal
- this needs revisiting at some point
This commit is contained in:
Hannah Wolfe 2015-09-02 22:10:51 +01:00
parent 5b4a8c66be
commit 73080dc064
3 changed files with 25 additions and 9 deletions

View file

@ -1,8 +1,11 @@
import Ember from 'ember'; 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(), notifications: Ember.inject.service(),
validationType: 'signup',
role: null, role: null,
authorRole: null, authorRole: null,
@ -42,13 +45,13 @@ export default Ember.Controller.extend({
confirmAccept: function () { confirmAccept: function () {
var email = this.get('email'), var email = this.get('email'),
role = this.get('role'), role = this.get('role'),
validationErrors = this.get('errors.messages'),
self = this, self = this,
newUser; newUser;
// reset the form and close the modal // reset the form and close the modal
self.set('email', ''); this.set('email', '');
self.set('role', self.get('authorRole')); this.set('role', self.get('authorRole'));
self.send('closeModal');
this.store.find('user').then(function (result) { this.store.find('user').then(function (result) {
var invitedUser = result.findBy('email', email); var invitedUser = result.findBy('email', email);
@ -82,7 +85,13 @@ export default Ember.Controller.extend({
// save is overridden in order to validate, we probably // save is overridden in order to validate, we probably
// want to use inline-validations here and only show an // want to use inline-validations here and only show an
// alert if we have an actual error // 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();
}); });
} }
}); });

View file

@ -46,10 +46,16 @@ var TeamUserRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
model.rollback(); model.rollback();
} }
model.get('errors').clear();
this._super(); this._super();
}, },
actions: { actions: {
didTransition: function () {
this.modelFor('team.user').get('errors').clear();
},
save: function () { save: function () {
this.get('controller').send('save'); this.get('controller').send('save');
} }

View file

@ -2,11 +2,12 @@
title="Invite a New User" confirm=confirm class="invite-new-user"}} title="Invite a New User" confirm=confirm class="invite-new-user"}}
<fieldset> <fieldset>
<div class="form-group"> {{#gh-form-group errors=errors hasValidated=hasValidated property="email"}}
<label for="new-user-email">Email Address</label> <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" {{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}} autocapitalize="off" autocorrect="off" value=email focusOut=(action "validate" "email")}}
</div> {{gh-error-message errors=errors property="email"}}
{{/gh-form-group}}
<div class="form-group for-select"> <div class="form-group for-select">
<label for="new-user-role">Role</label> <label for="new-user-role">Role</label>