delete assignment group dialog

fixes CNVS-6812

test plan:
- delete an assignment group with the dialog
- it should disappear from the page
- refresh and it should be gone
- delete an assignment group with assignments
- the assignments should be gone too
- delete an assignment group with assignments and move them
to another assignment group
- the assignments should be in the other group

Change-Id: I77a471b5cf4f83cd298051766d71a14aeb3313d0
Reviewed-on: https://gerrit.instructure.com/22212
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: Amber Taniuchi <amber@instructure.com>
Product-Review: Cameron Sutter <csutter@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
This commit is contained in:
Cameron Sutter 2013-07-10 15:39:04 -06:00 committed by Simon Williams
parent 2d52c85430
commit 1068c74b28
8 changed files with 205 additions and 2 deletions

View File

@ -26,6 +26,7 @@ require [
'compiled/views/assignments/AssignmentSettingsView'
'compiled/views/assignments/AssignmentGroupWeightsView'
'jst/assignments/teacher_index/AssignmentGroupList'
], (AssignmentGroupCollection, Course, CollectionView, InputFilterView, AssignmentGroupListItemView, CreateGroupView, TeacherIndexView, AssignmentSettingsView, AssignmentGroupWeightsView, assignmentGroupsTemplate) ->
course = new Course

View File

@ -5,6 +5,7 @@ define [
$.fn.serializeForm = ->
rselectTextarea = /^(?:select|textarea)/i
rcheckboxOrRadio = /checkbox|radio/i
rradio = /(?:radio)/i
rCRLF = /\r?\n/g
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week|checkbox|radio|file)$/i
@ -13,6 +14,9 @@ define [
isInput = (el) ->
el.name && !el.disabled && rselectTextarea.test(el.nodeName) or rinput.test(el.type)
isRadioChecked = (el) ->
!rradio.test(el.type) || $(el).is(':checked')
getValue = (el) ->
resultFor = (val) ->
name: el.name
@ -42,5 +46,6 @@ define [
_.chain(this[0].elements || this.find(':input'))
.filter(isInput)
.filter(isRadioChecked)
.map(getValue)
.value()

View File

@ -6,8 +6,9 @@ define [
'compiled/views/assignments/AssignmentListItemView'
'compiled/views/assignments/CreateAssignmentView'
'compiled/views/assignments/CreateGroupView'
'compiled/views/assignments/DeleteGroupView'
'jst/assignments/teacher_index/AssignmentGroupListItem'
], (I18n, _, AssignmentCollection, CollectionView, AssignmentListItemView, CreateAssignmentView, CreateGroupView, template) ->
], (I18n, _, AssignmentCollection, CollectionView, AssignmentListItemView, CreateAssignmentView, CreateGroupView, DeleteGroupView, template) ->
class AssignmentGroupListItemView extends CollectionView
@ -17,9 +18,11 @@ define [
@child 'createAssignmentView', '[data-view=createAssignment]'
@child 'editGroupView', '[data-view=editAssignmentGroup]'
@child 'deleteGroupView', '[data-view=deleteAssignmentGroup]'
els: _.extend({}, @::els, {
'.add_assignment': '$addAssignmentButton'
'.delete_group': '$deleteGroupButton'
'.edit_group': '$editGroupButton'
})
@ -36,12 +39,15 @@ define [
# child views so they get rendered automatically, need to stop it
@createAssignmentView.hide()
@editGroupView.hide()
@deleteGroupView.hide()
# its trigger would not be rendered yet, set it manually
@createAssignmentView.setTrigger @$addAssignmentButton
@editGroupView.setTrigger @$editGroupButton
@deleteGroupView.setTrigger @$deleteGroupButton
initialize: ->
@collection = new AssignmentCollection @model.get('assignments')
@collection.on('add remove', @refreshDeleteDialog)
super
@editGroupView = new CreateGroupView
@ -50,6 +56,17 @@ define [
@createAssignmentView = new CreateAssignmentView
assignmentGroup: @model
collection: @collection
@deleteGroupView = new DeleteGroupView
model: @model
assignments: @collection
# this is the only way to get the number of assignments to update properly
# when an assignment is created in a new assignment group (before refreshing the page)
refreshDeleteDialog: =>
@deleteGroupView.remove()
@deleteGroupView = new DeleteGroupView
model: @model
assignments: @collection
toJSON: ->
count = @countRules()

View File

@ -0,0 +1,78 @@
define [
'i18n!assignments'
'underscore'
'compiled/models/AssignmentGroup'
'compiled/views/DialogFormView'
'jst/assignments/teacher_index/DeleteGroup'
'jst/EmptyDialogFormWrapper'
], (I18n, _, AssignmentGroup, DialogFormView, template, wrapper) ->
class DeleteGroupView extends DialogFormView
defaults:
width: 500
height: 275
events: _.extend({}, @::events,
'click .dialog_closer': 'close'
'click .delete_group': 'destroy'
'change .group_select': 'selectMove'
)
template: template
wrapperTemplate: wrapper
@optionProperty 'assignments'
toJSON: ->
data = super
groups = @model.collection.reject (model) =>
model.get('id') == @model.get('id')
groups_json = groups.map (model) ->
model.toJSON()
_.extend(data, {
assignment_count: @assignments.length
groups: groups_json
label_id: data.id
})
destroy: ->
data = @getFormData()
if data.action == "move" && data.move_assignments_to
@destroyModel(data.move_assignments_to)
@close()
if data.action == "delete"
@destroyModel()
@close()
destroyModel: (moveTo=null) ->
@collection = @model.collection
data = if moveTo then "move_assignments_to=#{moveTo}" else ''
if moveTo
#delay the fetch until the destroy request is done
@model.on('sync', @refreshCollection)
@model.destroy({data: data})
@collection.view.render()
refreshCollection: (model,xhr,options) =>
@collection.fetch()
selectMove: ->
if !@$el.find(".group_select :selected").hasClass("blank")
@$el.find('.assignment_group_move').prop('checked', true)
openAgain: ->
# make sure there is more than one assignment group
if @model.collection.models.length > 1
# check if it has assignments
if @assignments.length > 0
super
else
# no assignments, so just confirm
if confirm I18n.t('confirm_delete_group', "Are you sure you want to delete this Assignment Group?")
@destroyModel()
else
# last assignment group, so alert, but don't destroy
alert I18n.t('cannot_delete_group', "You must have at least one Assignment Group")

View File

@ -6,6 +6,9 @@
top: 0
right: 0
.group_select
margin-left: 20px
#ag_weights_wrapper
height: 330px
overflow-y: scroll

View File

@ -46,7 +46,7 @@
<a
href="#"
class="delete_group icon-trash"
title='{{#t "title_delete"}}Delete Assignment Group{{/t}}'
title='{{#t "title_delete"}}Delete Assignment Group?{{/t}}'
data-focus-returns-to="ag_{{id}}_manage_link"
>{{#t "delete"}}Delete{{/t}}</a>
</li>
@ -58,4 +58,5 @@
<ul class="collectionViewItems ig-list"></ul>
<form data-view="createAssignment" class="form-dialog"></form>
<form data-view="editAssignmentGroup" class="form-dialog"></form>
<form data-view="deleteAssignmentGroup" class="form-dialog" serialize-radio-value></form>
</div>

View File

@ -0,0 +1,32 @@
<div class="form-dialog-content">
<div class="form-horizontal">
<p>{{#t 'warnings.delete_assignment_group'}}You are about to delete <strong>{{name}}</strong>, which has <strong>{{assignment_count}}</strong> assignments in it.{{/t}}
</p>
<p>{{#t 'would_you_like'}}Would you like to:{{/t}}</p>
<p>
<label class="radio"><input type="radio" class="assignment_group_delete" name="action" value="delete" checked="checked"/> {{#t 'labels.delete_assignments_in_group'}}Delete its assignments{{/t}}</label>
</p>
<p>
<label id="ag_move_{{label_id}}" class="radio"><input type="radio" class="assignment_group_move" name="action" value="move"/> {{#t 'labels.move_assignments_to'}}Move its assignments to {{/t}}</label>
<select name="move_assignments_to" class="group_select" title="{{#t 'tooltips.target_group'}}Select a group to move this assignment to{{/t}}" aria-labelledby="ag_move_{{label_id}}">
<option value="" class="blank">[ {{#t 'options.select_group'}}Select a Group{{/t}} ]</option>
{{#each groups}}
<option value="{{id}}">{{name}}</option>
{{/each}}
</select>
</p>
</div>
</div>
<div class="form-controls">
<button
class="cancel_button btn dialog_closer"
type="button"
>{{#t "cancel"}}Cancel{{/t}}</button>
<button
class="delete_group btn btn-primary"
data-text-while-loading='{{#t "deleting"}}Deleting...{{/t}}'
type="button"
>{{#t "delete"}}Delete Group{{/t}}</button>
</div>

View File

@ -275,5 +275,71 @@ describe "assignment groups" do
ag.reload.rules_hash.should be_blank
f("#assignment_group_#{ag.id} .ig-header").text.should_not match "Rule"
end
it "should delete an assignment group with assignments" do
@ag2 = @course.assignment_groups.create!(:name => "2nd Group")
@course.assignments.create(:name => "Test assignment", :assignment_group => @ag2)
refresh_page
wait_for_ajaximations
f("#assignment_group_#{@ag2.id} .al-trigger").click
f("#assignment_group_#{@ag2.id} .delete_group").click
wait_for_animations
fj('.delete_group:visible').click
wait_for_ajaximations
@ag2.reload
@ag2.workflow_state.should == 'deleted'
end
it "should delete an assignment group without assignments" do
@ag2 = @course.assignment_groups.create!(:name => "2nd Group")
refresh_page
wait_for_ajaximations
f("#assignment_group_#{@ag2.id} .al-trigger").click
f("#assignment_group_#{@ag2.id} .delete_group").click
driver.switch_to.alert.should_not be nil
driver.switch_to.alert.accept
wait_for_ajaximations
@ag2.reload
@ag2.workflow_state.should == 'deleted'
end
it "should not delete the last assignment group" do
f("#assignment_group_#{@assignment_group.id} .al-trigger").click
f("#assignment_group_#{@assignment_group.id} .delete_group").click
driver.switch_to.alert.should_not be nil
driver.switch_to.alert.accept
@assignment_group.reload
@assignment_group.should_not be nil
end
it "should move assignments to another assignment group" do
before_count = @assignment_group.assignments.count
@ag2 = @course.assignment_groups.create!(:name => "2nd Group")
@assignment = @course.assignments.create(:name => "Test assignment", :assignment_group => @ag2)
refresh_page
wait_for_ajaximations
f("#assignment_group_#{@ag2.id} .al-trigger").click
f("#assignment_group_#{@ag2.id} .delete_group").click
wait_for_animations
fj('.assignment_group_move:visible').click
click_option('.group_select:visible', @assignment_group.id.to_s, :value)
fj('.delete_group:visible').click
wait_for_ajaximations
@assignment.reload
@assignment.assignment_group.should == @assignment_group
end
end
end