From becffd4dbb5a75410309fe6da0d9181de2493dff Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Thu, 3 Jan 2013 14:08:56 -0500 Subject: [PATCH] Updated html and javascript for new pages as well as a fix for the peer grading service --- .../peer_grading_service.py | 1 + .../peer_grading/peer_grading_problem.coffee | 146 ++++++++++++++++-- .../peer_grading/peer_grading_problem.html | 6 +- 3 files changed, 135 insertions(+), 18 deletions(-) diff --git a/lms/djangoapps/open_ended_grading/peer_grading_service.py b/lms/djangoapps/open_ended_grading/peer_grading_service.py index cd4a94f26d..70d0721b3b 100644 --- a/lms/djangoapps/open_ended_grading/peer_grading_service.py +++ b/lms/djangoapps/open_ended_grading/peer_grading_service.py @@ -65,6 +65,7 @@ class PeerGradingService(GradingService): return response +_service = None def peer_grading_service(): """ Return a peer grading service instance--if settings.MOCK_PEER_GRADING is True, diff --git a/lms/static/coffee/src/peer_grading/peer_grading_problem.coffee b/lms/static/coffee/src/peer_grading/peer_grading_problem.coffee index 5b7aef18c7..7c0921cc98 100644 --- a/lms/static/coffee/src/peer_grading/peer_grading_problem.coffee +++ b/lms/static/coffee/src/peer_grading/peer_grading_problem.coffee @@ -18,14 +18,27 @@ class PeerGradingProblemBackend success: true calibrated: false else if cmd == 'show_calibration_essay' + #response = + # success: false + # error: "There was an error" response = success: true submission_id: 1 submission_key: 'abcd' - student_response: 'I am a fake response' + student_response: 'I am a fake calibration response' prompt: 'Answer this question' rubric: 'This is a rubric.' max_score: 4 + else if cmd == 'get_next_submission' + response = + success: true + submission_id: 1 + submission_key: 'abcd' + student_response: 'I am a fake student response' + prompt: 'Answer this question' + rubric: 'This is a rubric.' + max_score: 4 + return response @@ -48,35 +61,51 @@ class PeerGradingProblem @submission_container = $('.submission-container') @prompt_container = $('.prompt-container') @rubric_container = $('.rubric-container') + @instructions_panel = $('.instructions-panel') + @content_panel = $('.content-panel') @error_container = $('.error-container') + @submission_key_input = $("input[name='submission-key']") + @essay_id_input = $("input[name='essay-id']") + + @score_selection_container = $('.score-selection-container') + @score = null + + @submit_button = $('.submit-button') + @action_button = $('.action-button') + + @action_button.click -> document.location.reload(true) + @is_calibrated_check() + ########## + # + # Ajax calls to the backend + # + ########## is_calibrated_check: () => - @backend.post('is_student_calibrated', {}, @calibration_check_callback) + @backend.post('is_student_calibrated', {location: @location}, @calibration_check_callback) - - fetch_calibration_essay: ()=> + fetch_calibration_essay: () => @backend.post('show_calibration_essay', {location: @location}, @render_calibration) - render_calibration: (response) => - if response.success - #TODO: fill this in + fetch_submission_essay: () => + @backend.post('get_next_submission', {location: @location}, @render_submission) - @submission_container.html("

Calibration Essay

") - @submission_container.append(response.student_response) - @prompt_container.html(response.prompt) - @rubric_container.html(response.rubric) + submit_calibration_essay: ()-> + #TODO: onclick of the submit button. submits the calibration essay grade - else - @error_container.show() - @error_container.html(response.error) - - render_submission: (response) -> - #TODO: fill this in + submit_grade: () -> + #TODO: onclick of the submit button. submits the grade + + ########## + # + # Callbacks for various events + # + ########## calibration_check_callback: (response) => if response.success # check whether or not we're still calibrating @@ -86,6 +115,89 @@ class PeerGradingProblem else @fetch_calibration_essay() @calibration = true + else if response.error + @render_error(response.error) + else + @render_error("Error contacting the grading service") + + + submission_callback: (response) => + if response.success + @is_calibrated_check() + else + if response.error + @render_error(response.error) + else + @render_error("Error occurred while submitting grade") + + graded_callback: (event) => + @score = event.target.value + @show_submit_button() + + + + ########## + # + # Rendering methods and helpers + # + ########## + render_calibration: (response) => + if response.success + + # load in all the data + @submission_container.html("

Calibration Essay

") + @render_submission_data(response) + + # TODO: indicate that we're in calibration mode + + else + if response.error + @render_error(response.error) + else + @render_error("An error occurred while contacting the grading server") + + render_submission_data: (response) => + @content_panel.show() + @submission_container.append(response.student_response) + @prompt_container.html(response.prompt) + @rubric_container.html(response.rubric) + @submission_key_input.val(response.submission_key) + @essay_id_input.val(response.submission_id) + @setup_score_selection(response.max_score) + @submit_button.hide() + @action_button.hide() + + + render_submission: (response) => + #TODO: fill this in + @submit_button.hide() + @render_submission_data(response) + + render_error: (error_message) => + @error_container.show() + @error_container.html(error_message) + @content_panel.hide() + + show_submit_button: () => + @submit_button.show() + + setup_score_selection: (max_score) => + # first, get rid of all the old inputs, if any. + @score_selection_container.html('Choose score: ') + + # Now create new labels and inputs for each possible score. + for score in [0..max_score] + id = 'score-' + score + label = """""" + + input = """ + + """ # " fix broken parsing in emacs + @score_selection_container.append(input + label) + + # And now hook up an event handler again + $("input[name='score-selection']").change @graded_callback + diff --git a/lms/templates/peer_grading/peer_grading_problem.html b/lms/templates/peer_grading/peer_grading_problem.html index 116da94ece..dd577c1295 100644 --- a/lms/templates/peer_grading/peer_grading_problem.html +++ b/lms/templates/peer_grading/peer_grading_problem.html @@ -21,6 +21,7 @@
+

Calibration

@@ -68,7 +69,10 @@
-
+ +
+ +