diff --git a/common/static/common/js/discussion/views/new_post_view.js b/common/static/common/js/discussion/views/new_post_view.js index 2ba9c63db1ebe6d4528ae13dbfd7ec0df6d66469..db9a886de549f6e7e9e8960df1979df0c9d5471d 100644 --- a/common/static/common/js/discussion/views/new_post_view.js +++ b/common/static/common/js/discussion/views/new_post_view.js @@ -135,6 +135,7 @@ }, 'submit .forum-new-post-form': 'createPost', 'change .post-option-input': 'postOptionChange', + 'change .js-group-select': 'groupOptionChange', 'click .cancel': 'cancel', 'click .add-post-cancel': 'cancel', 'reset .forum-new-post-form': 'updateStyles', @@ -146,6 +147,7 @@ NewPostView.prototype.toggleGroupDropdown = function($target) { if ($target.data('divided')) { $('.js-group-select').prop('disabled', false); + $('.js-group-select').val('').prop('selected', true); return $('.group-selector-wrapper').removeClass('disabled'); } else { $('.js-group-select').val('').prop('disabled', true); @@ -257,6 +259,14 @@ return setTimeout(function() { return self.$('.post-option-input').trigger('change'); }, 1); }; + NewPostView.prototype.groupOptionChange = function(event) { + var $target = $(event.target), + data = $target.data(); + this.group_name = this.$('.js-group-select option:selected').text(); + data.divided = true; + this.updateVisibilityMessage($target); + }; + return NewPostView; }(Backbone.View)); } diff --git a/common/static/common/js/spec/discussion/view/new_post_view_spec.js b/common/static/common/js/spec/discussion/view/new_post_view_spec.js index b1b292941e8c1b49e12f156edcf3b1d803b9fd17..b388526befdc357d7125891ab2ad2b659fe54eae 100644 --- a/common/static/common/js/spec/discussion/view/new_post_view_spec.js +++ b/common/static/common/js/spec/discussion/view/new_post_view_spec.js @@ -95,6 +95,25 @@ $('.post-topic').trigger('change'); return checkVisibility(this.view, true, false, false); }); + it('visibility message changes when group is changed', function() { + DiscussionSpecHelper.makeModerator(); + checkVisibility(this.view, true, false, true); + + $('option:contains(Topic)').prop('selected', true); + $('.post-topic').trigger('change'); + expect($('.js-group-select option:selected').text()) + .toEqual('All Groups'); + expect($('.group-visibility').text().trim()) + .toEqual('This post will be visible only to All Groups.'); + + $('.js-group-select option:contains(Cohort1)').prop('selected', true); + $('.js-group-select').trigger('change'); + expect($('.js-group-select option:selected').text()) + .toEqual('Cohort1'); + expect($('.group-visibility').text().trim()) + .toEqual('This post will be visible only to Cohort1.'); + return checkVisibility(this.view, true, false, false); + }); it('allows the user to make a group selection', function() { var expectedGroupId, self = this;