From 94bea7a707affe8f9b4fd6d6faebd44aff1ec3a6 Mon Sep 17 00:00:00 2001 From: Douglas Cerna Date: Thu, 6 Jul 2017 01:44:03 -0600 Subject: [PATCH] Cherry picked Adolfo's commits and addressed Braden's observations --- .../views/discussion_inline_view.js | 3 +- .../views/discussion_topic_menu_view.js | 1 + .../js/discussion/views/new_post_view.js | 44 ++++++++++++++++++- .../discussion/new-post-visibility.underscore | 11 +++++ .../templates/discussion/new-post.underscore | 7 +++ lms/djangoapps/discussion/views.py | 2 + .../discussion/_underscore_templates.html | 27 ++++++++++-- 7 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 common/static/common/templates/discussion/new-post-visibility.underscore diff --git a/common/static/common/js/discussion/views/discussion_inline_view.js b/common/static/common/js/discussion/views/discussion_inline_view.js index fe9fdc3529..870a9fcda6 100644 --- a/common/static/common/js/discussion/views/discussion_inline_view.js +++ b/common/static/common/js/discussion/views/discussion_inline_view.js @@ -126,7 +126,8 @@ course_settings: this.courseSettings, topicId: discussionId, startHeader: this.startHeader, - is_commentable_divided: response.is_commentable_divided + is_commentable_divided: response.is_commentable_divided, + user_group_id: response.user_group_id, }); this.newPostView.render(); diff --git a/common/static/common/js/discussion/views/discussion_topic_menu_view.js b/common/static/common/js/discussion/views/discussion_topic_menu_view.js index e92d66e0db..b5b26a36f5 100644 --- a/common/static/common/js/discussion/views/discussion_topic_menu_view.js +++ b/common/static/common/js/discussion/views/discussion_topic_menu_view.js @@ -15,6 +15,7 @@ initialize: function(options) { this.course_settings = options.course_settings; this.currentTopicId = options.topicId; + this.group_name = options.group_name; _.bindAll(this, 'handleTopicEvent' ); 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 3ebcafec7f..bb1ba7b155 100644 --- a/common/static/common/js/discussion/views/new_post_view.js +++ b/common/static/common/js/discussion/views/new_post_view.js @@ -42,6 +42,7 @@ } this.course_settings = options.course_settings; this.is_commentable_divided = options.is_commentable_divided; + this.user_group_id = options.user_group_id; this.topicId = options.topicId; this.discussionBoardView = options.discussionBoardView; }; @@ -53,6 +54,7 @@ _.extend(context, { group_options: this.getGroupOptions(), is_commentable_divided: this.is_commentable_divided, + is_discussion_division_enabled: this.course_settings.get('is_discussion_division_enabled'), mode: this.mode, startHeader: this.startHeader, form_id: this.mode + (this.topicId ? '-' + this.topicId : '') @@ -68,10 +70,17 @@ if (this.isTabMode()) { this.topicView = new DiscussionTopicMenuView({ topicId: this.topicId, - course_settings: this.course_settings + course_settings: this.course_settings, + group_name: this.getGroupName() }); - this.topicView.on('thread:topic_change', this.toggleGroupDropdown); + this.topicView.on('thread:topic_change', this.toggleGroupDropDown); + if (this.course_settings.get('is_discussion_division_enabled')) { + this.topicView.on('thread:topic_change', this.updateVisibilityMessage); + } this.addField(this.topicView.render()); + } else { + this.group_name = this.getGroupName(); + this.updateVisibilityMessage(null, this.is_commentable_divided); } return DiscussionUtil.makeWmdEditor(this.$el, $.proxy(this.$, this), 'js-post-body'); }; @@ -100,6 +109,26 @@ } }; + NewPostView.prototype.getGroupName = function() { + var userGroupId; + var group; + var group_name = null; + if (this.course_settings.get('is_discussion_division_enabled')) { + userGroupId = $('#discussion-container').data('user-group-id'); + if (!userGroupId) { + userGroupId = this.user_group_id; + } + group = this.course_settings.get('groups').find(function(group) { + return group.id == userGroupId; + }); + if (group) { + group_name = group.name; + } + } + + return group_name; + }; + NewPostView.prototype.events = { 'keypress .forum-new-post-form input:not(.wmd-input)': function(event) { return DiscussionUtil.ignoreEnterKey(event); @@ -121,6 +150,17 @@ } }; + NewPostView.prototype.updateVisibilityMessage = function($target, force_divided) { + var visEl = $('.group-visibility .field-label-text'); + var visTemplate = edx.HtmlUtils.template($('#new-post-visibility-template').html()); + var group_name = null; + if (($target && $target.data('divided')) || force_divided) { + group_name = this.group_name; + } + + edx.HtmlUtils.setHtml(visEl, visTemplate({group_name: group_name})); + }; + NewPostView.prototype.postOptionChange = function(event) { var $optionElem, $target; $target = $(event.target); diff --git a/common/static/common/templates/discussion/new-post-visibility.underscore b/common/static/common/templates/discussion/new-post-visibility.underscore new file mode 100644 index 0000000000..34492a0f97 --- /dev/null +++ b/common/static/common/templates/discussion/new-post-visibility.underscore @@ -0,0 +1,11 @@ +<% if (group_name) { %> + <%- + interpolate( + gettext('This post will be visible only to %(group_name)s.'), + {group_name: group_name}, + true + ) + %> +<% } else { %> + <%- gettext('This post will be visible to everyone.') %> +<% } %> diff --git a/common/static/common/templates/discussion/new-post.underscore b/common/static/common/templates/discussion/new-post.underscore index 3ccfcc742f..f84188d203 100644 --- a/common/static/common/templates/discussion/new-post.underscore +++ b/common/static/common/templates/discussion/new-post.underscore @@ -29,6 +29,13 @@ + <% } else if (is_discussion_division_enabled) { %> +
+ +
<% } %>