Commit e6345868 by Greg Price

Merge pull request #2222 from edx/gprice/forum-new-post-buttons

Fix forum buttons
parents 4d4288f4 60fb3cfb
...@@ -105,7 +105,7 @@ class @DiscussionViewSpecHelper ...@@ -105,7 +105,7 @@ class @DiscussionViewSpecHelper
expect(view.toggleVote).toHaveBeenCalled() expect(view.toggleVote).toHaveBeenCalled()
view.toggleVote.reset() view.toggleVote.reset()
button.trigger($.Event("keydown", {which: 13})) button.trigger($.Event("keydown", {which: 13}))
expect(view.toggleVote).toHaveBeenCalled() expect(view.toggleVote).not.toHaveBeenCalled()
view.toggleVote.reset() view.toggleVote.reset()
button.trigger($.Event("keydown", {which: 32})) button.trigger($.Event("keydown", {which: 32}))
expect(view.toggleVote).not.toHaveBeenCalled() expect(view.toggleVote).toHaveBeenCalled()
...@@ -2,9 +2,11 @@ if Backbone? ...@@ -2,9 +2,11 @@ if Backbone?
class @DiscussionModuleView extends Backbone.View class @DiscussionModuleView extends Backbone.View
events: events:
"click .discussion-show": "toggleDiscussion" "click .discussion-show": "toggleDiscussion"
"keypress .discussion-show": "keydown .discussion-show":
(event) -> DiscussionUtil.activateOnEnter(event, toggleDiscussion) (event) -> DiscussionUtil.activateOnSpace(event, @toggleDiscussion)
"click .new-post-btn": "toggleNewPost" "click .new-post-btn": "toggleNewPost"
"keydown .new-post-btn":
(event) -> DiscussionUtil.activateOnSpace(event, @toggleNewPost)
"click .new-post-cancel": "hideNewPost" "click .new-post-cancel": "hideNewPost"
"click .discussion-paginator a": "navigateToPage" "click .discussion-paginator a": "navigateToPage"
...@@ -19,7 +21,7 @@ if Backbone? ...@@ -19,7 +21,7 @@ if Backbone?
else else
@page = 1 @page = 1
toggleNewPost: (event) -> toggleNewPost: (event) =>
event.preventDefault() event.preventDefault()
if !@newPostForm if !@newPostForm
@toggleDiscussion() @toggleDiscussion()
...@@ -38,13 +40,13 @@ if Backbone? ...@@ -38,13 +40,13 @@ if Backbone?
event.preventDefault() event.preventDefault()
@newPostForm.slideUp(300) @newPostForm.slideUp(300)
hideDiscussion: -> hideDiscussion: =>
@$("section.discussion").slideUp() @$("section.discussion").slideUp()
@toggleDiscussionBtn.removeClass('shown') @toggleDiscussionBtn.removeClass('shown')
@toggleDiscussionBtn.find('.button-text').html(gettext("Show Discussion")) @toggleDiscussionBtn.find('.button-text').html(gettext("Show Discussion"))
@showed = false @showed = false
toggleDiscussion: (event) -> toggleDiscussion: (event) =>
if @showed if @showed
@hideDiscussion() @hideDiscussion()
else else
......
...@@ -16,6 +16,7 @@ if Backbone? ...@@ -16,6 +16,7 @@ if Backbone?
@nav.on "thread:created", @navigateToThread @nav.on "thread:created", @navigateToThread
@newPost = $('.new-post-article') @newPost = $('.new-post-article')
$('.new-post-btn').bind "click", @showNewPost $('.new-post-btn').bind "click", @showNewPost
$('.new-post-btn').bind "keydown", (event) => DiscussionUtil.activateOnSpace(event, @showNewPost)
$('.new-post-cancel').bind "click", @hideNewPost $('.new-post-cancel').bind "click", @hideNewPost
allThreads: -> allThreads: ->
......
...@@ -88,8 +88,8 @@ class @DiscussionUtil ...@@ -88,8 +88,8 @@ class @DiscussionUtil
"notifications_status" : "/notification_prefs/status/" "notifications_status" : "/notification_prefs/status/"
}[name] }[name]
@activateOnEnter: (event, func) -> @activateOnSpace: (event, func) ->
if event.which == 13 if event.which == 32
event.preventDefault() event.preventDefault()
func(event) func(event)
......
...@@ -4,8 +4,8 @@ if Backbone? ...@@ -4,8 +4,8 @@ if Backbone?
events: events:
"click .discussion-flag-abuse": "toggleFlagAbuse" "click .discussion-flag-abuse": "toggleFlagAbuse"
"keypress .discussion-flag-abuse": "keydown .discussion-flag-abuse":
(event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) (event) -> DiscussionUtil.activateOnSpace(event, @toggleFlagAbuse)
attrRenderer: attrRenderer:
endorsed: (endorsed) -> endorsed: (endorsed) ->
...@@ -107,7 +107,7 @@ if Backbone? ...@@ -107,7 +107,7 @@ if Backbone?
@model.bind('change', @renderPartialAttrs, @) @model.bind('change', @renderPartialAttrs, @)
toggleFollowing: (event) -> toggleFollowing: (event) =>
event.preventDefault() event.preventDefault()
$elem = $(event.target) $elem = $(event.target)
url = null url = null
...@@ -122,14 +122,14 @@ if Backbone? ...@@ -122,14 +122,14 @@ if Backbone?
url: url url: url
type: "POST" type: "POST"
toggleFlagAbuse: (event) -> toggleFlagAbuse: (event) =>
event.preventDefault() event.preventDefault()
if window.user.id in @model.get("abuse_flaggers") or (DiscussionUtil.isFlagModerator and @model.get("abuse_flaggers").length > 0) if window.user.id in @model.get("abuse_flaggers") or (DiscussionUtil.isFlagModerator and @model.get("abuse_flaggers").length > 0)
@unFlagAbuse() @unFlagAbuse()
else else
@flagAbuse() @flagAbuse()
flagAbuse: -> flagAbuse: =>
url = @model.urlFor("flagAbuse") url = @model.urlFor("flagAbuse")
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$(".discussion-flag-abuse") $elem: @$(".discussion-flag-abuse")
...@@ -144,7 +144,7 @@ if Backbone? ...@@ -144,7 +144,7 @@ if Backbone?
temp_array.push(window.user.id) temp_array.push(window.user.id)
@model.set('abuse_flaggers', temp_array) @model.set('abuse_flaggers', temp_array)
unFlagAbuse: -> unFlagAbuse: =>
url = @model.urlFor("unFlagAbuse") url = @model.urlFor("unFlagAbuse")
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$(".discussion-flag-abuse") $elem: @$(".discussion-flag-abuse")
......
...@@ -5,10 +5,10 @@ if Backbone? ...@@ -5,10 +5,10 @@ if Backbone?
"click .vote-btn": "click .vote-btn":
(event) -> @toggleVote(event) (event) -> @toggleVote(event)
"keydown .vote-btn": "keydown .vote-btn":
(event) -> DiscussionUtil.activateOnEnter(event, @toggleVote) (event) -> DiscussionUtil.activateOnSpace(event, @toggleVote)
"click .action-follow": "toggleFollowing" "click .action-follow": "toggleFollowing"
"keypress .action-follow": "keydown .action-follow":
(event) -> DiscussionUtil.activateOnEnter(event, toggleFollowing) (event) -> DiscussionUtil.activateOnSpace(event, @toggleFollowing)
"click .expand-post": "expandPost" "click .expand-post": "expandPost"
"click .collapse-post": "collapsePost" "click .collapse-post": "collapsePost"
......
...@@ -5,14 +5,14 @@ if Backbone? ...@@ -5,14 +5,14 @@ if Backbone?
"click .vote-btn": "click .vote-btn":
(event) -> @toggleVote(event) (event) -> @toggleVote(event)
"keydown .vote-btn": "keydown .vote-btn":
(event) -> DiscussionUtil.activateOnEnter(event, @toggleVote) (event) -> DiscussionUtil.activateOnSpace(event, @toggleVote)
"click .discussion-flag-abuse": "toggleFlagAbuse" "click .discussion-flag-abuse": "toggleFlagAbuse"
"keypress .discussion-flag-abuse": "keydown .discussion-flag-abuse":
(event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) (event) -> DiscussionUtil.activateOnSpace(event, @toggleFlagAbuse)
"click .admin-pin": "togglePin" "click .admin-pin": "togglePin"
"click .action-follow": "toggleFollowing" "click .action-follow": "toggleFollowing"
"keypress .action-follow": "keydown .action-follow":
(event) -> DiscussionUtil.activateOnEnter(event, toggleFollowing) (event) -> DiscussionUtil.activateOnSpace(event, @toggleFollowing)
"click .action-edit": "edit" "click .action-edit": "edit"
"click .action-delete": "_delete" "click .action-delete": "_delete"
"click .action-openclose": "toggleClosed" "click .action-openclose": "toggleClosed"
......
...@@ -4,13 +4,13 @@ if Backbone? ...@@ -4,13 +4,13 @@ if Backbone?
"click .vote-btn": "click .vote-btn":
(event) -> @toggleVote(event) (event) -> @toggleVote(event)
"keydown .vote-btn": "keydown .vote-btn":
(event) -> DiscussionUtil.activateOnEnter(event, @toggleVote) (event) -> DiscussionUtil.activateOnSpace(event, @toggleVote)
"click .action-endorse": "toggleEndorse" "click .action-endorse": "toggleEndorse"
"click .action-delete": "_delete" "click .action-delete": "_delete"
"click .action-edit": "edit" "click .action-edit": "edit"
"click .discussion-flag-abuse": "toggleFlagAbuse" "click .discussion-flag-abuse": "toggleFlagAbuse"
"keypress .discussion-flag-abuse": "keydown .discussion-flag-abuse":
(event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) (event) -> DiscussionUtil.activateOnSpace(event, @toggleFlagAbuse)
$: (selector) -> $: (selector) ->
@$el.find(selector) @$el.find(selector)
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
<%block name="extratabs"> <%block name="extratabs">
% if has_permission(user, 'create_thread', course.id): % if has_permission(user, 'create_thread', course.id):
<li class="right"><a href="#" class="new-post-btn"><span class="icon icon-edit new-post-icon"></span>${_("New Post")}</a></li> <li class="right"><a href="#" class="new-post-btn" role="button"><span class="icon icon-edit new-post-icon"></span>${_("New Post")}</a></li>
% endif % endif
</%block> </%block>
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
<div class="discussion-module" data-discussion-id="${discussion_id | h}"> <div class="discussion-module" data-discussion-id="${discussion_id | h}">
<a class="discussion-show control-button" href="javascript:void(0)" data-discussion-id="${discussion_id | h}" role="button"><span class="show-hide-discussion-icon"></span><span class="button-text">${_("Show Discussion")}</span></a> <a class="discussion-show control-button" href="javascript:void(0)" data-discussion-id="${discussion_id | h}" role="button"><span class="show-hide-discussion-icon"></span><span class="button-text">${_("Show Discussion")}</span></a>
<a href="#" class="new-post-btn"><span class="icon icon-edit new-post-icon"></span>${_("New Post")}</a> <a href="#" class="new-post-btn" role="button"><span class="icon icon-edit new-post-icon"></span>${_("New Post")}</a>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment