Move more forum nav rendering logic to front end
The cohort selector is rendered only for a privileged user in a cohorted course, and that logic is now in an Underscore template instead of Mako.
This commit is contained in:
@@ -75,6 +75,7 @@ describe "DiscussionThreadListView", ->
|
||||
<option value="flagged">Flagged</option>
|
||||
</select>
|
||||
</label>
|
||||
<% if (isCohorted && isPrivilegedUser) { %>
|
||||
<label class="forum-nav-filter-cohort">
|
||||
<span class="sr">Cohort:</span>
|
||||
<select class="forum-nav-filter-cohort-control">
|
||||
@@ -83,6 +84,7 @@ describe "DiscussionThreadListView", ->
|
||||
<option value="2">Cohort2</option>
|
||||
</select>
|
||||
</label>
|
||||
<% } %>
|
||||
<label class="forum-nav-sort">
|
||||
<select class="forum-nav-sort-control">
|
||||
<option value="date">by recent activity</option>
|
||||
@@ -123,7 +125,11 @@ describe "DiscussionThreadListView", ->
|
||||
spyOn($, "ajax")
|
||||
|
||||
@discussion = new Discussion([])
|
||||
@view = new DiscussionThreadListView({collection: @discussion, el: $("#fixture-element")})
|
||||
@view = new DiscussionThreadListView(
|
||||
collection: @discussion,
|
||||
el: $("#fixture-element"),
|
||||
courseSettings: new DiscussionCourseSettings({is_cohorted: true})
|
||||
)
|
||||
@view.render()
|
||||
|
||||
setupAjax = (callback) ->
|
||||
@@ -141,7 +147,8 @@ describe "DiscussionThreadListView", ->
|
||||
makeView = (discussion) ->
|
||||
return new DiscussionThreadListView(
|
||||
el: $("#fixture-element"),
|
||||
collection: discussion
|
||||
collection: discussion,
|
||||
courseSettings: new DiscussionCourseSettings({is_cohorted: true})
|
||||
)
|
||||
|
||||
expectFilter = (filterVal) ->
|
||||
@@ -164,7 +171,12 @@ describe "DiscussionThreadListView", ->
|
||||
)
|
||||
|
||||
describe "cohort selector", ->
|
||||
it "should filter correctly", ->
|
||||
it "should not be visible to students", ->
|
||||
expect(@view.$(".forum-nav-filter-cohort-control:visible")).not.toExist()
|
||||
|
||||
it "should allow moderators to select visibility", ->
|
||||
DiscussionSpecHelper.makeModerator()
|
||||
@view.render()
|
||||
expectedGroupId = null
|
||||
setupAjax((params) => expect(params.data.group_id).toEqual(expectedGroupId))
|
||||
_.each(
|
||||
@@ -498,6 +510,8 @@ describe "DiscussionThreadListView", ->
|
||||
expect($(".forum-nav-browse-current").text()).toEqual("Posts I'm Following")
|
||||
|
||||
it "should show/hide the cohort selector", ->
|
||||
DiscussionSpecHelper.makeModerator()
|
||||
@view.render()
|
||||
setupAjax()
|
||||
_.each(
|
||||
[
|
||||
|
||||
@@ -8,7 +8,11 @@ if Backbone?
|
||||
@discussion = options['discussion']
|
||||
@course_settings = options['course_settings']
|
||||
|
||||
@nav = new DiscussionThreadListView(collection: @discussion, el: $(".forum-nav"))
|
||||
@nav = new DiscussionThreadListView(
|
||||
collection: @discussion,
|
||||
el: $(".forum-nav"),
|
||||
courseSettings: @course_settings
|
||||
)
|
||||
@nav.on "thread:selected", @navigateToThread
|
||||
@nav.on "thread:removed", @navigateToAllThreads
|
||||
@nav.on "threads:rendered", @setActiveThread
|
||||
|
||||
@@ -13,7 +13,8 @@ if Backbone?
|
||||
"change .forum-nav-filter-main-control": "chooseFilter"
|
||||
"change .forum-nav-filter-cohort-control": "chooseCohort"
|
||||
|
||||
initialize: ->
|
||||
initialize: (options) ->
|
||||
@courseSettings = options.courseSettings
|
||||
@displayedCollection = new Discussion(@collection.models, pages: @collection.pages)
|
||||
@collection.on "change", @reloadDisplayedCollection
|
||||
@discussionIds=""
|
||||
@@ -121,7 +122,12 @@ if Backbone?
|
||||
|
||||
render: ->
|
||||
@timer = 0
|
||||
@$el.html(@template())
|
||||
@$el.html(
|
||||
@template({
|
||||
isCohorted: @courseSettings.get("is_cohorted"),
|
||||
isPrivilegedUser: DiscussionUtil.isPrivilegedUser()
|
||||
})
|
||||
)
|
||||
@$(".forum-nav-sort-control").val(@collection.sort_preference)
|
||||
|
||||
$(window).bind "load", @updateSidebar
|
||||
|
||||
@@ -37,10 +37,7 @@
|
||||
<option value="flagged">${_("Flagged")}</option>
|
||||
%endif
|
||||
</select>
|
||||
</label>\
|
||||
%if is_course_cohorted and is_moderator:
|
||||
## Lack of indentation is intentional to avoid whitespace between this and siblings
|
||||
<label class="forum-nav-filter-cohort">
|
||||
</label>${"<% if (isCohorted && isPrivilegedUser) { %>"}<label class="forum-nav-filter-cohort">
|
||||
## Translators: This labels a cohort menu in forum navigation
|
||||
<span class="sr">${_("Cohort:")}</span>
|
||||
<select class="forum-nav-filter-cohort-control">
|
||||
@@ -49,10 +46,7 @@
|
||||
<option value="${c['id']}">${c['name']}</option>
|
||||
%endfor
|
||||
</select>
|
||||
</label>\
|
||||
%endif
|
||||
## Lack of indentation is intentional to avoid whitespace between this and siblings
|
||||
<label class="forum-nav-sort">
|
||||
</label>${"<% } %>"}<label class="forum-nav-sort">
|
||||
## Translators: This labels a sort menu in forum navigation
|
||||
<span class="sr">${_("Sort:")}</span>
|
||||
<select class="forum-nav-sort-control">
|
||||
|
||||
Reference in New Issue
Block a user