Skip to content

Commit

Permalink
hide drop options for ineligible assignment groups
Browse files Browse the repository at this point in the history
fixes CNVS-11852

Test plan:
  * start to make a new assignment group, the dialog should not have
    any options ignoring scores
  * edit an existing assignment group (that has assignments), you
    should see the usual drop options

Change-Id: I5293be9cea81044c0db08eb7593068647157cd5a
Reviewed-on: https://gerrit.instructure.com/32929
Reviewed-by: Cameron Sutter <[email protected]>
QA-Review: Amber Taniuchi <[email protected]>
Tested-by: Jenkins <[email protected]>
Product-Review: Simon Williams <[email protected]>
  • Loading branch information
cmatheson committed Apr 11, 2014
1 parent e7fcfa0 commit d3b9cc9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 38 deletions.
15 changes: 10 additions & 5 deletions app/coffeescripts/views/assignments/CreateGroupView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ define [
'jst/EmptyDialogFormWrapper'
], (round, I18n, $, _, AssignmentGroup, NeverDropCollection, NeverDropCollectionView, DialogFormView, template, wrapper) ->

SHORT_HEIGHT = 250

class CreateGroupView extends DialogFormView
defaults:
width: 600
Expand Down Expand Up @@ -43,7 +45,6 @@ define [
#@assignmentGroup will be defined when editing
@model = @assignmentGroup or new AssignmentGroup(assignments: [])


onSaveSuccess: ->
super
# meaning we are editing
Expand All @@ -59,9 +60,10 @@ define [

getFormData: ->
data = super
delete data.rules.drop_lowest if _.contains(["", "0"], data.rules.drop_lowest)
delete data.rules.drop_highest if _.contains(["", "0"], data.rules.drop_highest)
delete data.rules.never_drop if data.rules.never_drop?.length == 0
if data.rules
delete data.rules.drop_lowest if _.contains(["", "0"], data.rules.drop_lowest)
delete data.rules.drop_highest if _.contains(["", "0"], data.rules.drop_highest)
delete data.rules.never_drop if data.rules.never_drop?.length == 0
data

validateFormData: (data) ->
Expand Down Expand Up @@ -125,10 +127,13 @@ define [
label_id: @model.get('id') or 'new'
drop_lowest: @model.rules()?.drop_lowest or 0
drop_highest: @model.rules()?.drop_highest or 0
editable_never_drop: @model.get('assignments').length > 0
editable_drop: @model.get('assignments').length > 0
})

openAgain: ->
if @model.get('assignments').length == 0
@setDimensions(this.defaults.width, SHORT_HEIGHT)

super
@checkGroupWeight()
@getNeverDrops()
65 changes: 32 additions & 33 deletions app/views/jst/assignments/CreateGroup.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,40 @@
</label>
</div>
</div>
<hr/>
<fieldset>
<legend class="drop_rules_section">Number of scores to ignore for each student</legend>
{{#if editable_drop}}
<hr/>
<fieldset>
<legend class="drop_rules_section">Number of scores to ignore for each student</legend>

<div class="control-group">
<label class="control-label" for="ag_{{label_id}}_drop_lowest">
{{#t "drop_lowest"}}Lowest Scores:{{/t}}
</label>
<div class="controls">
<input
type="number"
id="ag_{{label_id}}_drop_lowest"
class="span1 field"
name="rules[drop_lowest]"
value="{{drop_lowest}}"
/>
<div class="control-group">
<label class="control-label" for="ag_{{label_id}}_drop_lowest">
{{#t "drop_lowest"}}Lowest Scores:{{/t}}
</label>
<div class="controls">
<input
type="number"
id="ag_{{label_id}}_drop_lowest"
class="span1 field"
name="rules[drop_lowest]"
value="{{drop_lowest}}"
/>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="ag_{{label_id}}_drop_highest">
{{#t "drop_highest"}}Highest Scores:{{/t}}
</label>
<div class="controls">
<input
type="number"
id="ag_{{label_id}}_drop_highest"
class="span1 field"
name="rules[drop_highest]"
value="{{drop_highest}}"
/>
<div class="control-group">
<label class="control-label" for="ag_{{label_id}}_drop_highest">
{{#t "drop_highest"}}Highest Scores:{{/t}}
</label>
<div class="controls">
<input
type="number"
id="ag_{{label_id}}_drop_highest"
class="span1 field"
name="rules[drop_highest]"
value="{{drop_highest}}"
/>
</div>
</div>
</div>

{{#if editable_never_drop}}
<hr/>
<div class="control-group">
<label class="control-label" id="ag_{{label_id}}_never_drop">
Expand All @@ -71,9 +71,8 @@
<div class="controls never_drop_rules_group">
</div>
</div>
{{/if}}
</fieldset>

</fieldset>
{{/if}}
</div>
</div>
<div class="form-controls">
Expand Down
12 changes: 12 additions & 0 deletions spec/coffeescripts/views/assignments/CreateGroupViewSpec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ define [
setup: -> fakeENV.setup()
teardown: -> fakeENV.teardown()

test 'hides drop options for no assignments', ->
view = createView()
view.render()
ok view.$('[name="rules[drop_lowest]"]').length
ok view.$('[name="rules[drop_highest]"]').length

view.assignmentGroup.get('assignments').reset []
view.render()
equal view.$('[name="rules[drop_lowest]"]').length, 0
equal view.$('[name="rules[drop_highest]"]').length, 0


test 'it should not add errors when never_drop rules are added', ->
view = createView()
data =
Expand Down

0 comments on commit d3b9cc9

Please sign in to comment.