From 167aca64f95e617fd949f85d09628e0695dfdce1 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 8 Jan 2016 17:01:23 +0000 Subject: [PATCH] Transition after setup step 3 submission even if invite takes a long time refs #5779 - adds a timeout of 4 seconds to step 3 submission so that we transition even if we haven't heard back from the server yet. Notification alerts will be displayed asynchronously once all server requests have returned. - adds a message to check e-mail configuration to step 3 invitation failure alert --- core/client/app/controllers/setup/three.js | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/core/client/app/controllers/setup/three.js b/core/client/app/controllers/setup/three.js index 5690cd08fe..a05ee547e1 100644 --- a/core/client/app/controllers/setup/three.js +++ b/core/client/app/controllers/setup/three.js @@ -1,7 +1,7 @@ import Ember from 'ember'; import DS from 'ember-data'; -const {Controller, RSVP, computed, inject} = Ember; +const {Controller, RSVP, computed, inject, run} = Ember; const {Errors} = DS; const {alias} = computed; const emberA = Ember.A; @@ -131,6 +131,13 @@ export default Controller.extend({ }); }), + _transitionAfterSubmission() { + if (!this._hasTransitioned) { + this._hasTransitioned = true; + this.transitionToRoute('posts.index'); + } + }, + actions: { validate() { this.validate(); @@ -139,10 +146,17 @@ export default Controller.extend({ invite() { let users = this.get('usersArray'); let notifications = this.get('notifications'); - let invitationsString; + let invitationsString, submissionTimeout; if (this.validate() && users.length > 0) { - this.toggleProperty('submitting'); + this.set('submitting', true); + this._hasTransitioned = false; + + // wait for 4 seconds, otherwise transition anyway + submissionTimeout = run.later(this, function () { + this._transitionAfterSubmission(); + }, 4000); + this.get('authorRole').then((authorRole) => { RSVP.Promise.all( users.map((user) => { @@ -169,6 +183,8 @@ export default Controller.extend({ let successCount = 0; let message; + run.cancel(submissionTimeout); + invites.forEach((invite) => { if (invite.success) { successCount++; @@ -181,6 +197,9 @@ export default Controller.extend({ invitationsString = erroredEmails.length > 1 ? ' invitations: ' : ' invitation: '; message = `Failed to send ${erroredEmails.length} ${invitationsString}`; message += erroredEmails.join(', '); + message += ". Please check your email configuration, see http://support.ghost.org/mail for instructions"; + + message = Ember.String.htmlSafe(message); notifications.showAlert(message, {type: 'error', delayed: successCount > 0, key: 'signup.send-invitations.failed'}); } @@ -189,9 +208,13 @@ export default Controller.extend({ invitationsString = successCount > 1 ? 'invitations' : 'invitation'; notifications.showAlert(`${successCount} ${invitationsString} sent!`, {type: 'success', delayed: true, key: 'signup.send-invitations.success'}); } - this.send('loadServerNotifications'); - this.toggleProperty('submitting'); - this.transitionToRoute('posts.index'); + + this.set('submitting', false); + + run.schedule('actions', this, function () { + this.send('loadServerNotifications'); + this._transitionAfterSubmission(); + }); }); }); } else if (users.length === 0) {