Commit 8c5b203d by David Ormsbee

Merge pull request #591 from MITx/kimth/gentler-frontend

A gentler, more helpful frontend
parents 4ce41c01 86409a2a
...@@ -8,6 +8,7 @@ Used by capa_problem.py ...@@ -8,6 +8,7 @@ Used by capa_problem.py
''' '''
# standard library imports # standard library imports
import cgi
import inspect import inspect
import json import json
import logging import logging
...@@ -725,7 +726,8 @@ class NumericalResponse(LoncapaResponse): ...@@ -725,7 +726,8 @@ class NumericalResponse(LoncapaResponse):
# I think this is just pyparsing.ParseException, calc.UndefinedVariable: # I think this is just pyparsing.ParseException, calc.UndefinedVariable:
# But we'd need to confirm # But we'd need to confirm
except: except:
raise StudentInputError('Invalid input -- please use a number only') raise StudentInputError("Invalid input: could not parse '%s' as a number" %\
cgi.escape(student_answer))
if correct: if correct:
return CorrectMap(self.answer_id, 'correct') return CorrectMap(self.answer_id, 'correct')
...@@ -1517,11 +1519,12 @@ class FormulaResponse(LoncapaResponse): ...@@ -1517,11 +1519,12 @@ class FormulaResponse(LoncapaResponse):
cs=self.case_sensitive) cs=self.case_sensitive)
except UndefinedVariable as uv: except UndefinedVariable as uv:
log.debug('formularesponse: undefined variable in given=%s' % given) log.debug('formularesponse: undefined variable in given=%s' % given)
raise StudentInputError(uv.message + " not permitted in answer") raise StudentInputError("Invalid input: " + uv.message + " not permitted in answer")
except Exception as err: except Exception as err:
#traceback.print_exc() #traceback.print_exc()
log.debug('formularesponse: error %s in formula' % err) log.debug('formularesponse: error %s in formula' % err)
raise StudentInputError("Error in formula") raise StudentInputError("Invalid input: Could not parse '%s' as a formula" %\
cgi.escape(given))
if numpy.isnan(student_result) or numpy.isinf(student_result): if numpy.isnan(student_result) or numpy.isinf(student_result):
return "incorrect" return "incorrect"
if not compare_with_tolerance(student_result, instructor_result, self.tolerance): if not compare_with_tolerance(student_result, instructor_result, self.tolerance):
......
...@@ -192,8 +192,11 @@ class @Problem ...@@ -192,8 +192,11 @@ class @Problem
if file_not_selected if file_not_selected
errors.push 'You did not select any files to submit' errors.push 'You did not select any files to submit'
if errors.length > 0 error_html = '<ul>\n'
alert errors.join("\n") for error in errors
error_html += '<li>' + error + '</li>\n'
error_html += '</ul>'
@gentle_alert error_html
abort_submission = file_too_large or file_not_selected or unallowed_file_submitted or required_files_not_submitted abort_submission = file_too_large or file_not_selected or unallowed_file_submitted or required_files_not_submitted
...@@ -208,7 +211,7 @@ class @Problem ...@@ -208,7 +211,7 @@ class @Problem
@render(response.contents) @render(response.contents)
@updateProgress response @updateProgress response
else else
alert(response.success) @gentle_alert response.success
if not abort_submission if not abort_submission
$.ajaxWithPrefix("#{@url}/problem_check", settings) $.ajaxWithPrefix("#{@url}/problem_check", settings)
...@@ -220,8 +223,10 @@ class @Problem ...@@ -220,8 +223,10 @@ class @Problem
when 'incorrect', 'correct' when 'incorrect', 'correct'
@render(response.contents) @render(response.contents)
@updateProgress response @updateProgress response
if @el.hasClass 'showed'
@el.removeClass 'showed'
else else
alert(response.success) @gentle_alert response.success
reset: => reset: =>
Logger.log 'problem_reset', @answers Logger.log 'problem_reset', @answers
...@@ -253,15 +258,19 @@ class @Problem ...@@ -253,15 +258,19 @@ class @Problem
@el.removeClass 'showed' @el.removeClass 'showed'
@$('.show').val 'Show Answer' @$('.show').val 'Show Answer'
gentle_alert: (msg) =>
if @el.find('.capa_alert').length
@el.find('.capa_alert').remove()
alert_elem = "<div class='capa_alert'>" + msg + "</div>"
@el.find('.action').after(alert_elem)
@el.find('.capa_alert').animate(opacity: 0, 500).animate(opacity: 1, 500)
save: => save: =>
Logger.log 'problem_save', @answers Logger.log 'problem_save', @answers
$.postWithPrefix "#{@url}/problem_save", @answers, (response) => $.postWithPrefix "#{@url}/problem_save", @answers, (response) =>
if response.success if response.success
if @el.find('.save_message').length saveMessage = "Your answers have been saved but not graded. Hit 'Check' to grade them."
@el.find('.save_message').animate(opacity: 0, 500).animate(opacity: 1, 500) @gentle_alert saveMessage
else
saveMessage = "<div class='save_message'>Your answers have been saved but not graded. Hit 'Check' to grade them.</div>"
@el.find('.action').after(saveMessage)
@updateProgress response @updateProgress response
refreshMath: (event, element) => refreshMath: (event, element) =>
......
...@@ -2,6 +2,7 @@ class @Sequence ...@@ -2,6 +2,7 @@ class @Sequence
constructor: (element) -> constructor: (element) ->
@el = $(element).find('.sequence') @el = $(element).find('.sequence')
@contents = @$('.seq_contents') @contents = @$('.seq_contents')
@num_contents = @contents.length
@id = @el.data('id') @id = @el.data('id')
@modx_url = @el.data('course_modx_root') @modx_url = @el.data('course_modx_root')
@initProgress() @initProgress()
...@@ -90,18 +91,28 @@ class @Sequence ...@@ -90,18 +91,28 @@ class @Sequence
@toggleArrows() @toggleArrows()
@hookUpProgressEvent() @hookUpProgressEvent()
sequence_links = @$('#seq_content a.seqnav')
sequence_links.click @goto
goto: (event) => goto: (event) =>
event.preventDefault() event.preventDefault()
new_position = $(event.target).data('element') if $(event.target).hasClass 'seqnav' # Links from courseware <a class='seqnav' href='n'>...</a>
Logger.log "seq_goto", old: @position, new: new_position, id: @id new_position = $(event.target).attr('href')
else # Tab links generated by backend template
new_position = $(event.target).data('element')
if (1 <= new_position) and (new_position <= @num_contents)
Logger.log "seq_goto", old: @position, new: new_position, id: @id
# On Sequence chage, destroy any existing polling thread # On Sequence chage, destroy any existing polling thread
# for queued submissions, see ../capa/display.coffee # for queued submissions, see ../capa/display.coffee
if window.queuePollerID if window.queuePollerID
window.clearTimeout(window.queuePollerID) window.clearTimeout(window.queuePollerID)
delete window.queuePollerID delete window.queuePollerID
@render new_position @render new_position
else
alert 'Sequence error! Cannot navigate to tab ' + new_position + 'in the current SequenceModule. Please contact the course staff.'
next: (event) => next: (event) =>
event.preventDefault() event.preventDefault()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment