From e7e823129e9e172a5ca5600beaa6f7b49975d20f Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 22 Jul 2014 21:30:51 +0530 Subject: [PATCH 1/2] FEATURE: group name is required for private topic invite --- .../discourse/controllers/invite.js.es6 | 26 ++++++++++++++++++- .../templates/modal/invite.js.handlebars | 2 +- config/locales/client.en.yml | 3 ++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/invite.js.es6 b/app/assets/javascripts/discourse/controllers/invite.js.es6 index b6b45b29039..63314163255 100644 --- a/app/assets/javascripts/discourse/controllers/invite.js.es6 +++ b/app/assets/javascripts/discourse/controllers/invite.js.es6 @@ -23,8 +23,9 @@ export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, { if (this.get('saving')) return true; if (this.blank('email')) return true; if (!Discourse.Utilities.emailValid(this.get('email'))) return true; + if (this.get('isPrivateTopic') && this.blank('groupNames')) return true; return false; - }.property('email', 'saving'), + }.property('email', 'isPrivateTopic', 'groupNames', 'saving'), /** The current text for the invite button @@ -46,6 +47,15 @@ export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, { return this.get('model') !== Discourse.User.current(); }.property('model'), + /** + Is Private Topic? (i.e. visible only to specific group members) + + @property isPrivateTopic + **/ + isPrivateTopic: function() { + return this.get('invitingToTopic') && this.get('model.category.read_restricted'); + }.property('model'), + /** Instructional text for the modal. @@ -59,6 +69,19 @@ export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, { } }.property('invitingToTopic'), + /** + Instructional text for the group selection. + + @property groupInstructions + **/ + groupInstructions: function() { + if (this.get('isPrivateTopic')) { + return I18n.t('topic.automatically_add_to_groups_required'); + } else { + return I18n.t('topic.automatically_add_to_groups_optional'); + } + }.property('isPrivateTopic'), + /** The "success" text for when the invite was created. @@ -76,6 +99,7 @@ export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, { reset: function() { this.setProperties({ email: null, + groupNames: null, error: false, saving: false, finished: false diff --git a/app/assets/javascripts/discourse/templates/modal/invite.js.handlebars b/app/assets/javascripts/discourse/templates/modal/invite.js.handlebars index 772f21d9da9..8d9bfed67ac 100644 --- a/app/assets/javascripts/discourse/templates/modal/invite.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/invite.js.handlebars @@ -14,7 +14,7 @@ {{text-field value=email placeholderKey="topic.invite_reply.email_placeholder"}} {{#if isAdmin}} - + {{group-selector includeAuto=false groupNames=groupNames placeholderKey="topic.invite_private.group_name"}} {{/if}} {{/if}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 32a42406334..d14a90f644b 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -902,7 +902,8 @@ en: success_message: 'You successfully flagged this topic.' inviting: "Inviting..." - automatically_add_to_groups: "This invite also includes access to these groups: (optional, admin only)" + automatically_add_to_groups_optional: "This invite also includes access to these groups: (optional, admin only)" + automatically_add_to_groups_required: "This invite also includes access to these groups: (Required, admin only)" invite_private: title: 'Invite to Private Message' From d0024f738bfc29e00821bbf363a249a5ad7e4a5c Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 23 Jul 2014 00:08:18 +0530 Subject: [PATCH 2/2] further optimize computed property --- app/assets/javascripts/discourse/controllers/invite.js.es6 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/invite.js.es6 b/app/assets/javascripts/discourse/controllers/invite.js.es6 index 63314163255..f7dd557a188 100644 --- a/app/assets/javascripts/discourse/controllers/invite.js.es6 +++ b/app/assets/javascripts/discourse/controllers/invite.js.es6 @@ -52,9 +52,7 @@ export default Discourse.ObjectController.extend(Discourse.ModalFunctionality, { @property isPrivateTopic **/ - isPrivateTopic: function() { - return this.get('invitingToTopic') && this.get('model.category.read_restricted'); - }.property('model'), + isPrivateTopic: Em.computed.and('invitingToTopic', 'model.category.read_restricted'), /** Instructional text for the modal.