Skip to content

Commit ab7edda

Browse files
slothellesimonista
authored andcommitted
manages focus for assignments/discussion page menus
fixes CNVS-12718 test plan: - in a course with 2+ assignment groups - once with 1 assignment each, once with 2+ each - with draft state on - on assignment index page - using keyboard navigation for everything - click 'move to' for an assignment, close the dialog - verify that focus is directed to the settings cog for that assignment - repeat for an assignment group - click 'delete' for an assignment, click cancel - verify that focus is directed to the settings cog - click 'delete' for an assignment, click ok - for groups with 1 assignment: verify that focus goes to parent assignment group - for groups with 2+ assignments: verify that focus goes to previous assignment in list - for first assignment in list: verify that focus goes to parent assignment group - with draft state on - on discussion index page - repeat 'move to' and 'delete' verifications from above Change-Id: I0940b5eed70cecb628c25c597b8439598d096d24 Reviewed-on: https://gerrit.instructure.com/35120 Reviewed-by: Cameron Sutter <csutter@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> Product-Review: Aaron Cannon <acannon@instructure.com>
1 parent 608b089 commit ab7edda

7 files changed

Lines changed: 42 additions & 4 deletions

File tree

app/coffeescripts/views/DiscussionTopics/DiscussionView.coffee

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ define [
5959
@moveItemView = new MoveDialogView
6060
model: @model
6161
nested: true
62+
closeTarget: @$el.find('a[id=manage_link]')
6263
saveURL: -> @model.collection.reorderURL()
6364
super
6465

@@ -88,7 +89,11 @@ define [
8889
# Returns nothing.
8990
onDelete: (e) =>
9091
e.preventDefault()
91-
@delete() if confirm(@messages.confirm)
92+
if confirm(@messages.confirm)
93+
@goToPrevItem()
94+
@delete()
95+
else
96+
@$el.find('a[id=manage_link]').focus()
9297

9398
# Public: Delete the model and update the server.
9499
#
@@ -97,6 +102,20 @@ define [
97102
@model.destroy()
98103
@$el.remove()
99104

105+
goToPrevItem: =>
106+
if @previousDiscussionInGroup()?
107+
$('#' + @previousDiscussionInGroup().id + '_discussion_content').attr("tabindex",-1).focus()
108+
else if @model.get('pinned')
109+
$('.pinned&.discussion-list').attr("tabindex",-1).focus()
110+
else if @model.get('locked')
111+
$('.locked&.discussion-list').attr("tabindex",-1).focus()
112+
else
113+
$('.open&.discussion-list').attr("tabindex",-1).focus()
114+
115+
previousDiscussionInGroup: =>
116+
current_index = @model.collection.models.indexOf(@model)
117+
@model.collection.models[current_index - 1]
118+
100119
# Public: Pin or unpin the model and update it on the server.
101120
#
102121
# e - Event object.

app/coffeescripts/views/MoveDialogView.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ define [
4646
# required if @nested
4747
@optionProperty 'childKey'
4848

49+
# {jQuery selector}
50+
# link to focus on after dialog is closed
51+
# without taking any action
52+
@optionProperty 'closeTarget'
53+
4954
# {string or function}
5055
# url to post to when saving the form
5156
#
@@ -104,6 +109,7 @@ define [
104109
@listView?.remove()
105110
@parentListView = @listView = null
106111
@dialog.option "close", null
112+
@closeTarget?.focus()
107113

108114
#lookup new collection, and set it on
109115
#the nested view

app/coffeescripts/views/assignments/AssignmentGroupListItemView.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ define [
120120
model: @model
121121
@moveGroupView = new MoveDialogView
122122
model: @model
123+
closeTarget: @$el.find('a[id*=manage_link]')
123124
saveURL: -> ENV.URLS.sort_url
124125

125126
initCache: ->

app/coffeescripts/views/assignments/AssignmentListItemView.coffee

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ define [
7676
parentLabelText: @messages.ag_move_label
7777
parentKey: 'assignment_group_id'
7878
childKey: 'assignments'
79+
closeTarget: @$el.find('a[id*=manage_link]')
7980
saveURL: -> "#{ENV.URLS.assignment_sort_base_url}/#{@parentListView.value()}/reorder"
8081

8182
@dateDueColumnView = new DateDueColumnView(model: @model)
@@ -158,7 +159,14 @@ define [
158159

159160
onDelete: (e) =>
160161
e.preventDefault()
161-
@delete() if confirm(@messages.confirm)
162+
return @$el.find('a[id*=manage_link]').focus() unless confirm(@messages.confirm)
163+
if @previousAssignmentInGroup()?
164+
@focusOnAssignment(@previousAssignmentInGroup())
165+
@delete()
166+
else
167+
id = @model.attributes.assignment_group_id
168+
@delete()
169+
@focusOnGroupByID(id)
162170

163171
delete: ->
164172
@model.destroy()

app/views/jst/DiscussionTopics/discussion.handlebars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="discussion-content">
1+
<div class="discussion-content" id="{{id}}_discussion_content">
22
<div class="discussion-row{{#if ENV.permissions.publish}} {{#if published}}discussion-published{{else}}discussion-unpublished{{/if}}{{/if}}">
33
{{#if permissions.moderate}}
44
<div class="draggable-handle">
@@ -85,7 +85,7 @@
8585

8686
<div class="discussion-actions" role="application">
8787
{{#if permissions.delete}}
88-
<a href="#" class="al-trigger" role="button">
88+
<a href="#" class="al-trigger" role="button" id="manage_link">
8989
<i class="icon-settings"></i><i class="icon-mini-arrow-down"></i>
9090
<span class="screenreader-only">{{#t "manage"}}Manage{{/t}}</span>
9191
</a>

spec/coffeescripts/views/assignments/AssignmentListItemViewSpec.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ define [
169169
test 'asks for confirmation before deleting an assignment', ->
170170
view = createView(@model)
171171

172+
group_stub = sinon.stub(view, 'visibleAssignments', -> [])
172173
confirm_stub = sinon.stub(window, "confirm", -> true )
173174
delete_spy = sinon.spy view, "delete"
174175

@@ -179,6 +180,7 @@ define [
179180

180181
confirm_stub.restore()
181182
delete_spy.restore()
183+
group_stub.restore()
182184

183185
test "delete destroys model", ->
184186
old_asset_string = ENV.context_asset_string
@@ -277,6 +279,7 @@ define [
277279
@server.respond()
278280

279281
equal @model.get('published'), true
282+
@server.restore()
280283

281284
test "correctly displays module's name", ->
282285
mods = genModules(1)

spec/coffeescripts/views/external_tools/AddAppViewSpec.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ define [
120120

121121
teardown: ->
122122
view.remove()
123+
server.restore()
123124

124125
test 'AddAppView: render', ->
125126
equal $.trim($('.ui-dialog-title:visible').text()), "Add App",

0 commit comments

Comments
 (0)