Refactor rubric JS so that we don't have to keep duplicating this code.

This commit is contained in:
Diana Huang
2013-02-01 08:43:55 -05:00
parent 1fde3c5ec5
commit 92b7dbdc69
3 changed files with 41 additions and 40 deletions

View File

@@ -1,3 +1,32 @@
class @Rubric
constructor: () ->
# finds the scores for each rubric category
@get_score_list: () =>
# find the number of categories:
num_categories = $('table.rubric tr').length
score_lst = []
# get the score for each one
for i in [0..(num_categories-2)]
score = $("input[name='score-selection-#{i}']:checked").val()
score_lst.push(score)
return score_lst
@get_total_score: () ->
score_lst = @get_score_list()
@check_complete: () ->
# check to see whether or not any categories have not been scored
num_categories = $('table.rubric tr').length
# -2 because we want to skip the header
for i in [0..(num_categories-2)]
score = $("input[name='score-selection-#{i}']:checked").val()
if score == undefined
return false
return true
class @CombinedOpenEnded
constructor: (element) ->
@element=element

View File

@@ -239,7 +239,7 @@ class PeerGradingProblem
score_lst = []
# get the score for each one
for i in [0..(num_categories-1)]
for i in [0..(num_categories-2)]
score = $("input[name='score-selection-#{i}']:checked").val()
score_lst.push(score)
@@ -315,17 +315,10 @@ class PeerGradingProblem
# called after a grade is selected on the interface
graded_callback: (event) =>
@grade = $("input[name='grade-selection']:checked").val()
if @grade == undefined
return
# check to see whether or not any categories have not been scored
num_categories = $('table.rubric tr').length
for i in [0..(num_categories-1)]
score = $("input[name='score-selection-#{i}']:checked").val()
if score == undefined
return
# show button if we have scores for all categories
@show_submit_button()
if Rubric.check_complete():
# show button if we have scores for all categories
@show_submit_button()

View File

@@ -232,35 +232,14 @@ class @StaffGrading
graded_callback: () =>
@grade = $("input[name='grade-selection']:checked").val()
if @grade == undefined
return
# check to see whether or not any categories have not been scored
num_categories = $('table.rubric tr').length
for i in [0..(num_categories-1)]
score = $("input[name='score-selection-#{i}']:checked").val()
if score == undefined
return
# show button if we have scores for all categories
@state = state_graded
@submit_button.show()
# show button if we have scores for all categories
if Rubric.check_complete()
@state = state_graded
@submit_button.show()
set_button_text: (text) =>
@action_button.attr('value', text)
# finds the scores for each rubric category
get_score_list: () =>
# find the number of categories:
num_categories = $('table.rubric tr').length
score_lst = []
# get the score for each one
for i in [0..(num_categories-1)]
score = $("input[name='score-selection-#{i}']:checked").val()
score_lst.push(score)
return score_lst
ajax_callback: (response) =>
# always clear out errors and messages on transition.
@error_msg = ''
@@ -285,8 +264,8 @@ class @StaffGrading
skip_and_get_next: () =>
data =
score: @grade
rubric_scores: @get_score_list()
score: Rubric.get_total_score()
rubric_scores: Rubric.get_score_list()
feedback: @feedback_area.val()
submission_id: @submission_id
location: @location
@@ -299,8 +278,8 @@ class @StaffGrading
submit_and_get_next: () ->
data =
score: @grade
rubric_scores: @get_score_list()
score: Rubric.get_total_score()
rubric_scores: Rubric.get_score_list()
feedback: @feedback_area.val()
submission_id: @submission_id
location: @location