From 3ecafa9b42dc35f3389a6ca318a85d8e2c252f7d Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Tue, 19 Feb 2013 16:31:14 -0500 Subject: [PATCH] Add hot keys to rubrics --- .../js/src/combinedopenended/display.coffee | 40 +++++++++++++++++++ .../src/staff_grading/staff_grading.coffee | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee b/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee index d38036c8de..ecda8845d2 100644 --- a/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee @@ -4,7 +4,46 @@ class @Rubric @initialize: (location) -> $('.rubric').data("location", location) $('input[class="score-selection"]').change @tracking_callback + # set up the hotkeys + $(window).keydown @keypress_callback + # display the 'current' carat + @categories = $('.rubric-category') + @category = $(@categories.first()) + @category.prepend('> ') + @category_index = 0 + + + @keypress_callback: (event) => + # don't try to do this when user is typing in a text input + if $(event.target).is('input, textarea') + return + # for when we select via top row + if event.which >= 48 and event.which <= 57 + selected = event.which - 48 + # for when we select via numpad + else if event.which >= 96 and event.which <= 105 + selected = event.which - 96 + # we don't want to do anything since we haven't pressed a number + else + return + # if we actually have a current category (not past the end) + if(@category.length > 0) + # find the valid selections for this category + inputs = $("input[name='score-selection-#{@category_index}']") + max_score = inputs.length - 1 + + if selected > max_score or selected < 0 + return + inputs.filter("input[value=#{selected}]").click() + + # move to the next category + old_category_text = @category.html().substring(5) + @category.html(old_category_text) + @category_index++ + @category = $(@categories[@category_index]) + @category.prepend('> ') + @tracking_callback: (event) -> target_selection = $(event.target).val() # chop off the beginning of the name so that we can get the number of the category @@ -306,6 +345,7 @@ class @CombinedOpenEnded if response.success @rubric_wrapper.html(response.rubric_html) @rubric_wrapper.show() + Rubric.initialize(@location) @answer_area.html(response.student_response) @child_state = 'assessing' @find_assessment_elements() diff --git a/lms/static/coffee/src/staff_grading/staff_grading.coffee b/lms/static/coffee/src/staff_grading/staff_grading.coffee index f2b1b387ca..eb8a750715 100644 --- a/lms/static/coffee/src/staff_grading/staff_grading.coffee +++ b/lms/static/coffee/src/staff_grading/staff_grading.coffee @@ -219,7 +219,7 @@ class @StaffGrading setup_score_selection: => @score_selection_container.html(@rubric) - $('.score-selection').click => @graded_callback() + $('input[class="score-selection"]').change => @graded_callback() Rubric.initialize(@location)