# If some function wants to be called before sending the answer to the
# server, give it a chance to do so.
#
# submit_save_waitfor allows the callee to send alerts if the user's input is
# invalid. To do so, the callee must throw an exception named "Waitfor
# Exception". This and any other errors or exceptions that arise from the
# callee are rethrown and abort the submission.
#
# In order to use this feature, add a 'data-waitfor' attribute to the input,
# and specify the function to be called by the submit button before sending
# off @answers
submit_save_waitfor:(callback)=>
flag=false
forinpin@inputs
if($(inp).is("input[waitfor]"))
try
$(inp).data("waitfor")(()=>
@refreshAnswers()
callback()
)
catche
ife.name=="Waitfor Exception"
alerte.message
else
alert"Could not grade your answer. The submission was aborted."
throwe
flag=true
else
flag=false
returnflag
# Scroll to problem metadata and next focus is problem input
scroll_to_problem_meta:=>
questionTitle=@$(".problem-header")
ifquestionTitle.length>0
$('html, body').animate({
scrollTop:questionTitle.offset().top
},500);
questionTitle.focus()
focus_on_notification:(type)=>
notification=@$('.notification-'+type)
ifnotification.length>0
notification.focus()
focus_on_submit_notification:=>
@focus_on_notification('submit')
focus_on_hint_notification:=>
@focus_on_notification('hint')
focus_on_save_notification:=>
@focus_on_notification('save')
###
# 'submit_fd' uses FormData to allow file submissions in the 'problem_check' dispatch,
# in addition to simple querystring-based answers
#
# NOTE: The dispatch 'problem_check' is being singled out for the use of FormData;
# maybe preferable to consolidate all dispatches to use FormData
###
submit_fd:=>
# If there are no file inputs in the problem, we can fall back on @submit
if@el.find('input:file').length==0
@submit()
return
@enableSubmitButtonfalse
ifnotwindow.FormData
alert"Submission aborted! Sorry, your browser does not support file uploads. If you can, please use Chrome or Safari which have been verified to support file uploads."
// This comment needs to be on one line to be properly scraped for the translators.
// Translators: %(earned)s is the number of points earned. %(possible)s is the total number of points (examples: 0/1, 1/1, 2/3, 5/10). The total number of points will always be at least 1. We pluralize based on the total number of points (example: 0/1 point; 1/2 points);
'%(earned)s/%(possible)s point (graded)','%(earned)s/%(possible)s points (graded)',
possible
);
}else{
progressTemplate=ngettext(
// This comment needs to be on one line to be properly scraped for the translators.
// Translators: %(earned)s is the number of points earned. %(possible)s is the total number of points (examples: 0/1, 1/1, 2/3, 5/10). The total number of points will always be at least 1. We pluralize based on the total number of points (example: 0/1 point; 1/2 points);
'%(earned)s/%(possible)s point (ungraded)','%(earned)s/%(possible)s points (ungraded)',
possible
);
}
progress=interpolate(
progressTemplate,{
earned:earned,
possible:possible
},true
);
}
// Render 'x point(s) possible' if student has not yet attempted question
// Status is set to none when a user has a score of 0, and 0 when the problem has a weight of 0.
// If there are no file inputs in the problem, we can fall back on submit.
if(this.el.find('input:file').length===0){
this.submit();
return;
}
this.enableSubmitButton(false);
if(!window.FormData){
alert(gettext('Submission aborted! Sorry, your browser does not support file uploads. If you can, please use Chrome or Safari which have been verified to support file uploads.'));// eslint-disable-line max-len, no-alert
window.SR.readText(gettext('Answers to this problem are now shown. Navigate through the problem to review it with answers inline.'));// eslint-disable-line max-len