mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Warn the user if they haven't invited anyone
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
//= require select2.js
|
||||
//= require jquery.ui.widget.js
|
||||
//= require jquery.fileupload.js
|
||||
//= require sweetalert.min.js
|
||||
|
||||
@@ -26,7 +26,10 @@ export default Ember.Component.extend({
|
||||
},
|
||||
|
||||
updateField() {
|
||||
this.set('field.value', JSON.stringify(this.get('users')));
|
||||
const users = this.get('users');
|
||||
|
||||
this.set('field.value', JSON.stringify(users));
|
||||
this.set('field.warning', users.length ? null : 'invites.none_added');
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
||||
@@ -11,6 +11,8 @@ jQuery.fn.wiggle = function (times, duration) {
|
||||
return this;
|
||||
};
|
||||
|
||||
const alreadyWarned = {};
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNames: ['wizard-step'],
|
||||
saving: null,
|
||||
@@ -66,6 +68,14 @@ export default Ember.Component.extend({
|
||||
Ember.run.scheduleOnce('afterRender', () => $('.invalid input[type=text]').wiggle(2, 100));
|
||||
},
|
||||
|
||||
advance() {
|
||||
this.set('saving', true);
|
||||
this.get('step').save()
|
||||
.then(response => this.sendAction('goNext', response))
|
||||
.catch(() => this.animateInvalidFields())
|
||||
.finally(() => this.set('saving', false));
|
||||
},
|
||||
|
||||
actions: {
|
||||
quit() {
|
||||
document.location = "/";
|
||||
@@ -80,14 +90,29 @@ export default Ember.Component.extend({
|
||||
if (this.get('saving')) { return; }
|
||||
|
||||
const step = this.get('step');
|
||||
step.checkFields();
|
||||
const result = step.validate();
|
||||
|
||||
if (result.warnings.length) {
|
||||
const unwarned = result.warnings.filter(w => !alreadyWarned[w]);
|
||||
if (unwarned.length) {
|
||||
unwarned.forEach(w => alreadyWarned[w] = true);
|
||||
return window.swal({
|
||||
customClass: 'wizard-warning',
|
||||
title: "",
|
||||
text: unwarned.map(w => I18n.t(`wizard.${w}`)).join("\n"),
|
||||
type: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: "#6699ff"
|
||||
}, confirmed => {
|
||||
if (confirmed) {
|
||||
this.advance();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (step.get('valid')) {
|
||||
this.set('saving', true);
|
||||
step.save()
|
||||
.then(response => this.sendAction('goNext', response))
|
||||
.catch(() => this.animateInvalidFields())
|
||||
.finally(() => this.set('saving', false));
|
||||
this.advance();
|
||||
} else {
|
||||
this.animateInvalidFields();
|
||||
this.autoFocus();
|
||||
|
||||
@@ -15,14 +15,21 @@ export default Ember.Object.extend(ValidState, {
|
||||
return lookup;
|
||||
},
|
||||
|
||||
checkFields() {
|
||||
validate() {
|
||||
let allValid = true;
|
||||
const result = { warnings: [] };
|
||||
|
||||
this.get('fields').forEach(field => {
|
||||
field.check();
|
||||
allValid = allValid && field.get('valid');
|
||||
allValid = allValid && field.check();
|
||||
const warning = field.get('warning');
|
||||
if (warning) {
|
||||
result.warnings.push(warning);
|
||||
}
|
||||
});
|
||||
|
||||
this.setValid(allValid);
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
fieldError(id, description) {
|
||||
|
||||
@@ -5,13 +5,19 @@ export default Ember.Object.extend(ValidState, {
|
||||
type: null,
|
||||
value: null,
|
||||
required: null,
|
||||
warning: null,
|
||||
|
||||
check() {
|
||||
if (!this.get('required')) {
|
||||
return this.setValid(true);
|
||||
this.setValid(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
const val = this.get('value');
|
||||
this.setValid(val && val.length > 0);
|
||||
const valid = val && val.length > 0;
|
||||
|
||||
this.setValid(valid);
|
||||
return valid;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -16,6 +16,8 @@ componentTest('can add users', {
|
||||
const firstVal = JSON.parse(this.get('field.value'));
|
||||
assert.equal(firstVal.length, 0, 'empty JSON at first');
|
||||
|
||||
assert.ok(this.get('field.warning'), 'it has a warning since no users were added');
|
||||
|
||||
click('.add-user');
|
||||
andThen(() => {
|
||||
assert.ok(this.$('.users-list .invite-list-user').length === 0, "doesn't add a blank user");
|
||||
@@ -33,6 +35,7 @@ componentTest('can add users', {
|
||||
assert.equal(val.length, 1);
|
||||
assert.equal(val[0].email, 'eviltrout@example.com', 'adds the email to the JSON');
|
||||
assert.ok(val[0].role.length, 'adds the role to the JSON');
|
||||
assert.ok(!this.get('field.warning'), 'no warning once the user is added');
|
||||
});
|
||||
|
||||
fillIn('.invite-email', 'eviltrout@example.com');
|
||||
|
||||
@@ -26,9 +26,9 @@ test('text - required - validation', assert => {
|
||||
});
|
||||
|
||||
test('text - optional - validation', assert => {
|
||||
const w = WizardField.create({ type: 'text' });
|
||||
assert.ok(w.get('unchecked'));
|
||||
const f = WizardField.create({ type: 'text' });
|
||||
assert.ok(f.get('unchecked'));
|
||||
|
||||
w.check();
|
||||
assert.ok(w.get('valid'));
|
||||
f.check();
|
||||
assert.ok(f.get('valid'));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user