diff --git a/app/assets/javascripts/discourse/controllers/invite.js.es6 b/app/assets/javascripts/discourse/controllers/invite.js.es6 index 7ee5d076325..788cf4758af 100644 --- a/app/assets/javascripts/discourse/controllers/invite.js.es6 +++ b/app/assets/javascripts/discourse/controllers/invite.js.es6 @@ -6,6 +6,8 @@ export default Ember.Controller.extend(ModalFunctionality, { // If this isn't defined, it will proxy to the user model on the preferences // page which is wrong. emailOrUsername: null, + hasCustomMessage: false, + customMessage: null, inviteIcon: "envelope", isAdmin: function(){ @@ -27,6 +29,7 @@ export default Ember.Controller.extend(ModalFunctionality, { }.property('isAdmin', 'emailOrUsername', 'invitingToTopic', 'isPrivateTopic', 'model.groupNames', 'model.saving'), disabledCopyLink: function() { + if (this.get('hasCustomMessage')) return true; if (this.get('model.saving')) return true; if (Ember.isEmpty(this.get('emailOrUsername'))) return true; const emailOrUsername = this.get('emailOrUsername').trim(); @@ -37,7 +40,7 @@ export default Ember.Controller.extend(ModalFunctionality, { // when inviting to private topic via email, group name must be specified if (this.get('isPrivateTopic') && Ember.isEmpty(this.get('model.groupNames')) && Discourse.Utilities.emailValid(emailOrUsername)) return true; return false; - }.property('emailOrUsername', 'model.saving', 'isPrivateTopic', 'model.groupNames'), + }.property('emailOrUsername', 'model.saving', 'isPrivateTopic', 'model.groupNames', 'hasCustomMessage'), buttonTitle: function() { return this.get('model.saving') ? 'topic.inviting' : 'topic.invite_reply.action'; @@ -71,6 +74,11 @@ export default Ember.Controller.extend(ModalFunctionality, { return this.get('isAdmin') && (Discourse.Utilities.emailValid(this.get('emailOrUsername')) || this.get('isPrivateTopic') || !this.get('invitingToTopic')) && !Discourse.SiteSettings.enable_sso && Discourse.SiteSettings.enable_local_logins && !this.get('isMessage'); }.property('isAdmin', 'emailOrUsername', 'isPrivateTopic', 'isMessage', 'invitingToTopic'), + // Show Custom Message textarea? (only shown when inviting new user to forum) + showCustomMessage: function() { + return this.get('model') === this.currentUser; + }.property('model'), + // Instructional text for the modal. inviteInstructions: function() { if (Discourse.SiteSettings.enable_sso || !Discourse.SiteSettings.enable_local_logins) { @@ -136,9 +144,15 @@ export default Ember.Controller.extend(ModalFunctionality, { 'topic.invite_private.email_or_username_placeholder'; }.property(), + customMessagePlaceholder: function() { + return I18n.t('invite.custom_message_placeholder'); + }.property(), + // Reset the modal to allow a new user to be invited. reset() { this.set('emailOrUsername', null); + this.set('hasCustomMessage', false); + this.set('customMessage', null); this.get('model').setProperties({ groupNames: null, error: false, @@ -147,7 +161,6 @@ export default Ember.Controller.extend(ModalFunctionality, { inviteLink: null }); }, - actions: { createInvite() { @@ -162,7 +175,7 @@ export default Ember.Controller.extend(ModalFunctionality, { model.setProperties({ saving: true, error: false }); - return this.get('model').createInvite(this.get('emailOrUsername').trim(), groupNames).then(result => { + return this.get('model').createInvite(this.get('emailOrUsername').trim(), groupNames, this.get('customMessage')).then(result => { model.setProperties({ saving: false, finished: true }); if (!this.get('invitingToTopic')) { Invite.findInvitedBy(this.currentUser, userInvitedController.get('filter')).then(invite_model => { @@ -213,6 +226,15 @@ export default Ember.Controller.extend(ModalFunctionality, { } model.setProperties({ saving: false, error: true }); }); + }, + + showCustomMessageBox() { + this.toggleProperty('hasCustomMessage'); + if (this.get('hasCustomMessage')) { + this.set('customMessage', I18n.t('invite.custom_message_template')); + } else { + this.set('customMessage', null); + } } } diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index 1526638f7fe..9797cec04f5 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -321,10 +321,10 @@ const User = RestModel.extend({ Discourse.SiteSettings['newuser_max_' + type + 's'] > 0; }, - createInvite(email, group_names) { + createInvite(email, group_names, custom_message) { return Discourse.ajax('/invites', { type: 'POST', - data: { email, group_names } + data: { email, group_names, custom_message } }); }, diff --git a/app/assets/javascripts/discourse/templates/modal/invite.hbs b/app/assets/javascripts/discourse/templates/modal/invite.hbs index 0a016002d65..d28afdb0167 100644 --- a/app/assets/javascripts/discourse/templates/modal/invite.hbs +++ b/app/assets/javascripts/discourse/templates/modal/invite.hbs @@ -22,6 +22,12 @@ {{group-selector groupFinder=groupFinder groupNames=model.groupNames placeholderKey="topic.invite_private.group_name"}} {{/if}} + + {{#if showCustomMessage}} +
+ {{#if hasCustomMessage}}{{textarea value=customMessage placeholder=customMessagePlaceholder}}{{/if}} + {{/if}} + {{/if}}