From 3ecafa9b42dc35f3389a6ca318a85d8e2c252f7d Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Tue, 19 Feb 2013 16:31:14 -0500 Subject: [PATCH 1/2] 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) From f9667849b81da4cceec58e1ef93ac85d4584526d Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Wed, 20 Feb 2013 17:31:56 -0500 Subject: [PATCH 2/2] Fix some minor bugs in event handling and add enter key support --- .../js/src/combinedopenended/display.coffee | 9 ++++++++- .../peergrading/peer_grading_problem.coffee | 18 +++++++++++++++--- .../src/staff_grading/staff_grading.coffee | 6 ++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee b/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee index ecda8845d2..c749d65b45 100644 --- a/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee +++ b/common/lib/xmodule/xmodule/js/src/combinedopenended/display.coffee @@ -5,6 +5,7 @@ class @Rubric $('.rubric').data("location", location) $('input[class="score-selection"]').change @tracking_callback # set up the hotkeys + $(window).unbind('keydown', @keypress_callback) $(window).keydown @keypress_callback # display the 'current' carat @categories = $('.rubric-category') @@ -28,7 +29,7 @@ class @Rubric return # if we actually have a current category (not past the end) - if(@category.length > 0) + if(@category_index <= @categories.length) # find the valid selections for this category inputs = $("input[name='score-selection-#{@category_index}']") max_score = inputs.length - 1 @@ -88,6 +89,7 @@ class @CombinedOpenEnded constructor: (element) -> @element=element @reinitialize(element) + $(window).keydown @keydown_handler reinitialize: (element) -> @wrapper=$(element).find('section.xmodule_CombinedOpenEndedModule') @@ -358,6 +360,11 @@ class @CombinedOpenEnded else @errors_area.html(@out_of_sync_message) + keydown_handler: (e) => + # only do anything when the key pressed is the 'enter' key + if e.which == 13 && @child_state == 'assessing' && Rubric.check_complete() + @save_assessment(e) + save_assessment: (event) => event.preventDefault() if @child_state == 'assessing' && Rubric.check_complete() diff --git a/common/lib/xmodule/xmodule/js/src/peergrading/peer_grading_problem.coffee b/common/lib/xmodule/xmodule/js/src/peergrading/peer_grading_problem.coffee index 0b38090e43..4bdb4bdf05 100644 --- a/common/lib/xmodule/xmodule/js/src/peergrading/peer_grading_problem.coffee +++ b/common/lib/xmodule/xmodule/js/src/peergrading/peer_grading_problem.coffee @@ -210,6 +210,9 @@ class @PeerGradingProblem @calibration_interstitial_page_button = $('.calibration-interstitial-page-button') @flag_student_checkbox = $('.flag-checkbox') @answer_unknown_checkbox = $('.answer-unknown-checkbox') + + $(window).keydown @keydown_handler + @collapse_question() Collapsible.setCollapsibles(@content_panel) @@ -251,9 +254,6 @@ class @PeerGradingProblem fetch_submission_essay: () => @backend.post('get_next_submission', {location: @location}, @render_submission) - gentle_alert: (msg) => - @grading_message.fadeIn() - @grading_message.html("

" + msg + "

") construct_data: () -> data = @@ -337,6 +337,14 @@ class @PeerGradingProblem @show_submit_button() @grade = Rubric.get_total_score() + keydown_handler: (event) => + if event.which == 13 && @submit_button.is(':visible') + if @calibration + @submit_calibration_essay() + else + @submit_grade() + + ########## @@ -473,6 +481,10 @@ class @PeerGradingProblem # And now hook up an event handler again $("input[class='score-selection']").change @graded_callback + gentle_alert: (msg) => + @grading_message.fadeIn() + @grading_message.html("

" + msg + "

") + collapse_question: () => @prompt_container.slideToggle() @prompt_container.toggleClass('open') diff --git a/lms/static/coffee/src/staff_grading/staff_grading.coffee b/lms/static/coffee/src/staff_grading/staff_grading.coffee index eb8a750715..6af9ecf5d1 100644 --- a/lms/static/coffee/src/staff_grading/staff_grading.coffee +++ b/lms/static/coffee/src/staff_grading/staff_grading.coffee @@ -183,6 +183,8 @@ class @StaffGrading @breadcrumbs = $('.breadcrumbs') + + $(window).keydown @keydown_handler @question_header = $('.question-header') @question_header.click @collapse_question @collapse_question() @@ -229,6 +231,10 @@ class @StaffGrading @state = state_graded @submit_button.show() + keydown_handler: (e) => + if e.which == 13 && !@list_view && Rubric.check_complete() + @submit_and_get_next() + set_button_text: (text) => @action_button.attr('value', text)