Commit d2322a7d by Andy Armstrong

Run JSHint as part of the build

I relaxed some of the restrictions that were too
onerous to fix, but then fixed all the other issues
that were reported.
parent 4b3f6d66
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
"nonbsp" : true, // Warns about "non-breaking whitespace" characters. "nonbsp" : true, // Warns about "non-breaking whitespace" characters.
"nonew" : false, // Prohibits the use of constructor functions for side-effects. "nonew" : false, // Prohibits the use of constructor functions for side-effects.
"plusplus" : false, // Prohibits the use of unary increment and decrement operators. "plusplus" : false, // Prohibits the use of unary increment and decrement operators.
"quotmark" : "single", // Enforces the consistency of quotation marks used throughout your code. It accepts three values: true, "single", and "double". "quotmark" : false, // Enforces the consistency of quotation marks used throughout your code. It accepts three values: true, "single", and "double".
"undef" : true, // Prohibits the use of explicitly undeclared variables. "undef" : true, // Prohibits the use of explicitly undeclared variables.
"unused" : true, // Warns when you define and never use your variables. "unused" : true, // Warns when you define and never use your variables.
"strict" : true, // Requires all functions to run in ECMAScript 5's strict mode. "strict" : false, // Requires all functions to run in ECMAScript 5's strict mode.
"trailing" : true, // Makes it an error to leave a trailing whitespace in your code. "trailing" : true, // Makes it an error to leave a trailing whitespace in your code.
"maxlen" : 120, // Lets you set the maximum length of a line. "maxlen" : 120, // Lets you set the maximum length of a line.
//"maxparams" : 4, // Lets you set the max number of formal parameters allowed per function. //"maxparams" : 4, // Lets you set the max number of formal parameters allowed per function.
...@@ -141,6 +141,17 @@ ...@@ -141,6 +141,17 @@
"readFixtures", "readFixtures",
"setFixtures", "setFixtures",
"appendSetFixtures", "appendSetFixtures",
"spyOnEvent" "spyOnEvent",
// MathJax
"MathJax",
// Miscellaneous
"Logger",
"gettext",
"ngettext",
// ORA-specific globals
"OpenAssessment"
] ]
} }
\ No newline at end of file
...@@ -46,8 +46,17 @@ install-dev: ...@@ -46,8 +46,17 @@ install-dev:
install: install-wheels install-python install-js install-nltk-data install-test install-dev javascript install: install-wheels install-python install-js install-nltk-data install-test install-dev javascript
test: quality:
jshint openassessment/xblock/static/js/src -c .jshintrc --verbose
test: quality
./scripts/test.sh ./scripts/test.sh
test-js: test-js:
./scripts/test-js.sh ./scripts/test-js.sh
test-js-debug:
./scripts/js-debugger.sh
sass:
./scripts/sass.sh
...@@ -108,16 +108,16 @@ OpenAssessment.BaseView.prototype = { ...@@ -108,16 +108,16 @@ OpenAssessment.BaseView.prototype = {
toggleActionError: function(type, msg) { toggleActionError: function(type, msg) {
var element = this.element; var element = this.element;
var container = null; var container = null;
if (type == 'save') { if (type === 'save') {
container = '.response__submission__actions'; container = '.response__submission__actions';
} }
else if (type == 'submit' || type == 'peer' || type == 'self' || type == 'student-training') { else if (type === 'submit' || type === 'peer' || type === 'self' || type === 'student-training') {
container = '.step__actions'; container = '.step__actions';
} }
else if (type == 'feedback_assess') { else if (type === 'feedback_assess') {
container = '.submission__feedback__actions'; container = '.submission__feedback__actions';
} }
else if (type == 'upload') { else if (type === 'upload') {
container = '#upload__error'; container = '#upload__error';
} }
...@@ -150,6 +150,7 @@ OpenAssessment.BaseView.prototype = { ...@@ -150,6 +150,7 @@ OpenAssessment.BaseView.prototype = {
}; };
/* XBlock JavaScript entry point for OpenAssessmentXBlock. */ /* XBlock JavaScript entry point for OpenAssessmentXBlock. */
/* jshint unused:false */
function OpenAssessmentBlock(runtime, element) { function OpenAssessmentBlock(runtime, element) {
/** /**
Render views within the base view on page load. Render views within the base view on page load.
......
...@@ -26,7 +26,7 @@ OpenAssessment.FileUploader = function() { ...@@ -26,7 +26,7 @@ OpenAssessment.FileUploader = function() {
processData: false, processData: false,
contentType: file.type, contentType: file.type,
}).done( }).done(
function(data, textStatus, jqXHR) { function() {
// Log an analytics event // Log an analytics event
Logger.log( Logger.log(
"openassessment.upload_file", "openassessment.upload_file",
...@@ -41,7 +41,7 @@ OpenAssessment.FileUploader = function() { ...@@ -41,7 +41,7 @@ OpenAssessment.FileUploader = function() {
defer.resolve(); defer.resolve();
} }
).fail( ).fail(
function(data, textStatus, jqXHR) { function(data, textStatus) {
defer.rejectWith(this, [textStatus]); defer.rejectWith(this, [textStatus]);
} }
); );
......
...@@ -98,7 +98,7 @@ OpenAssessment.GradeView.prototype = { ...@@ -98,7 +98,7 @@ OpenAssessment.GradeView.prototype = {
if (typeof options === 'undefined') { if (typeof options === 'undefined') {
return $.map( return $.map(
$('.feedback__overall__value:checked', view.element), $('.feedback__overall__value:checked', view.element),
function(element, index) { return $(element).val(); } function(element) { return $(element).val(); }
); );
} else { } else {
// Uncheck all the options // Uncheck all the options
...@@ -136,7 +136,7 @@ OpenAssessment.GradeView.prototype = { ...@@ -136,7 +136,7 @@ OpenAssessment.GradeView.prototype = {
boolean boolean
**/ **/
isHidden: function(sel) { isHidden: function(sel) {
return sel.hasClass('is--hidden') && sel.attr('aria-hidden') == 'true'; return sel.hasClass('is--hidden') && sel.attr('aria-hidden') === 'true';
}, },
/** /**
...@@ -199,7 +199,7 @@ OpenAssessment.GradeView.prototype = { ...@@ -199,7 +199,7 @@ OpenAssessment.GradeView.prototype = {
} }
else { else {
if (newState == 'open') { if (newState === 'open') {
containerSel.toggleClass('is--transitioning', false); containerSel.toggleClass('is--transitioning', false);
containerSel.toggleClass('is--submitting', false); containerSel.toggleClass('is--submitting', false);
containerSel.toggleClass('is--submitted', false); containerSel.toggleClass('is--submitted', false);
...@@ -210,7 +210,7 @@ OpenAssessment.GradeView.prototype = { ...@@ -210,7 +210,7 @@ OpenAssessment.GradeView.prototype = {
this.setHidden(messageSel, true); this.setHidden(messageSel, true);
} }
else if (newState == 'submitting') { else if (newState === 'submitting') {
containerSel.toggleClass('is--transitioning', true); containerSel.toggleClass('is--transitioning', true);
containerSel.toggleClass('is--submitting', true); containerSel.toggleClass('is--submitting', true);
containerSel.toggleClass('is--submitted', false); containerSel.toggleClass('is--submitted', false);
...@@ -221,7 +221,7 @@ OpenAssessment.GradeView.prototype = { ...@@ -221,7 +221,7 @@ OpenAssessment.GradeView.prototype = {
this.setHidden(messageSel, true); this.setHidden(messageSel, true);
} }
else if (newState == 'submitted') { else if (newState === 'submitted') {
containerSel.toggleClass('is--transitioning', false); containerSel.toggleClass('is--transitioning', false);
containerSel.toggleClass('is--submitting', false); containerSel.toggleClass('is--submitting', false);
containerSel.toggleClass('is--submitted', true); containerSel.toggleClass('is--submitted', true);
......
...@@ -32,4 +32,4 @@ OpenAssessment.MessageView.prototype = { ...@@ -32,4 +32,4 @@ OpenAssessment.MessageView.prototype = {
baseView.showLoadError('message', errMsg); baseView.showLoadError('message', errMsg);
}); });
} }
} };
\ No newline at end of file
...@@ -31,7 +31,7 @@ OpenAssessment.PeerView.prototype = { ...@@ -31,7 +31,7 @@ OpenAssessment.PeerView.prototype = {
view.server.renderLatex($('#openassessment__peer-assessment', view.element)); view.server.renderLatex($('#openassessment__peer-assessment', view.element));
view.installHandlers(false); view.installHandlers(false);
} }
).fail(function(errMsg) { ).fail(function() {
view.baseView.showLoadError('peer-assessment'); view.baseView.showLoadError('peer-assessment');
}); });
// Called to update Messagview with info on whether or not it was able to grab a submission // Called to update Messagview with info on whether or not it was able to grab a submission
...@@ -55,7 +55,7 @@ OpenAssessment.PeerView.prototype = { ...@@ -55,7 +55,7 @@ OpenAssessment.PeerView.prototype = {
view.server.renderLatex($('#openassessment__peer-assessment', view.element)); view.server.renderLatex($('#openassessment__peer-assessment', view.element));
view.installHandlers(true); view.installHandlers(true);
} }
).fail(function(errMsg) { ).fail(function() {
view.baseView.showLoadError('peer-assessment'); view.baseView.showLoadError('peer-assessment');
view.continueAssessmentEnabled(true); view.continueAssessmentEnabled(true);
}); });
...@@ -208,7 +208,5 @@ OpenAssessment.PeerView.prototype = { ...@@ -208,7 +208,5 @@ OpenAssessment.PeerView.prototype = {
view.baseView.toggleActionError('peer', errMsg); view.baseView.toggleActionError('peer', errMsg);
view.peerSubmitEnabled(true); view.peerSubmitEnabled(true);
}); });
}, }
}; };
...@@ -48,7 +48,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -48,7 +48,7 @@ OpenAssessment.ResponseView.prototype = {
view.installHandlers(); view.installHandlers();
view.setAutoSaveEnabled(true); view.setAutoSaveEnabled(true);
} }
).fail(function(errMsg) { ).fail(function() {
view.baseView.showLoadError('response'); view.baseView.showLoadError('response');
}); });
}, },
...@@ -65,7 +65,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -65,7 +65,7 @@ OpenAssessment.ResponseView.prototype = {
// Install change handler for textarea (to enable submission button) // Install change handler for textarea (to enable submission button)
this.savedResponse = this.response(); this.savedResponse = this.response();
var handleChange = function(eventData) { view.handleResponseChanged(); }; var handleChange = function() { view.handleResponseChanged(); };
sel.find('.submission__answer__part__text__value').on('change keyup drop paste', handleChange); sel.find('.submission__answer__part__text__value').on('change keyup drop paste', handleChange);
var handlePrepareUpload = function(eventData) { view.prepareUpload(eventData.target.files); }; var handlePrepareUpload = function(eventData) { view.prepareUpload(eventData.target.files); };
...@@ -248,6 +248,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -248,6 +248,7 @@ OpenAssessment.ResponseView.prototype = {
if (enabled) { if (enabled) {
window.onbeforeunload = function() { window.onbeforeunload = function() {
// Keep this on one big line to avoid gettext bug: http://stackoverflow.com/a/24579117 // Keep this on one big line to avoid gettext bug: http://stackoverflow.com/a/24579117
/* jshint maxlen:300 */
return gettext("If you leave this page without saving or submitting your response, you'll lose any work you've done on the response."); return gettext("If you leave this page without saving or submitting your response, you'll lose any work you've done on the response.");
}; };
} }
...@@ -274,9 +275,9 @@ OpenAssessment.ResponseView.prototype = { ...@@ -274,9 +275,9 @@ OpenAssessment.ResponseView.prototype = {
return $.trim($(this).val()); return $.trim($(this).val());
}).get(); }).get();
} else { } else {
sel.map(function(index, element) { sel.map(function(index) {
$(this).val(texts[index]); $(this).val(texts[index]);
}) });
} }
}, },
...@@ -287,7 +288,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -287,7 +288,7 @@ OpenAssessment.ResponseView.prototype = {
**/ **/
responseChanged: function() { responseChanged: function() {
var savedResponse = this.savedResponse; var savedResponse = this.savedResponse;
return this.response().some(function(element, index, array) { return this.response().some(function(element, index) {
return element !== savedResponse[index]; return element !== savedResponse[index];
}); });
...@@ -320,8 +321,8 @@ OpenAssessment.ResponseView.prototype = { ...@@ -320,8 +321,8 @@ OpenAssessment.ResponseView.prototype = {
**/ **/
handleResponseChanged: function() { handleResponseChanged: function() {
// Enable the save/submit button only for non-blank responses // Enable the save/submit button only for non-blank responses
var isNotBlank = !this.response().every(function(element, index, array) { var isNotBlank = !this.response().every(function(element) {
return $.trim(element) == ''; return $.trim(element) === '';
}); });
this.submitEnabled(isNotBlank); this.submitEnabled(isNotBlank);
...@@ -363,12 +364,12 @@ OpenAssessment.ResponseView.prototype = { ...@@ -363,12 +364,12 @@ OpenAssessment.ResponseView.prototype = {
// ... but update the UI based on what the user may have entered // ... but update the UI based on what the user may have entered
// since hitting the save button. // since hitting the save button.
var currentResponse = view.response(); var currentResponse = view.response();
var currentResponseIsEmpty = currentResponse.every(function(element, index, array) { var currentResponseIsEmpty = currentResponse.every(function(element) {
return element == ''; return element === '';
}); });
view.submitEnabled(!currentResponseIsEmpty); view.submitEnabled(!currentResponseIsEmpty);
var currentResponseEqualsSaved = currentResponse.every(function(element, index, array) { var currentResponseEqualsSaved = currentResponse.every(function(element, index) {
return element === savedResponse[index]; return element === savedResponse[index];
}); });
if (currentResponseEqualsSaved) { if (currentResponseEqualsSaved) {
...@@ -418,7 +419,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -418,7 +419,7 @@ OpenAssessment.ResponseView.prototype = {
// If the error is "multiple submissions", then we should move to the next // If the error is "multiple submissions", then we should move to the next
// step. Otherwise, the user will be stuck on the current step with no // step. Otherwise, the user will be stuck on the current step with no
// way to continue. // way to continue.
if (errCode == 'ENOMULTI') { view.moveToNextStep(); } if (errCode === 'ENOMULTI') { view.moveToNextStep(); }
else { else {
// If there is an error message, display it // If there is an error message, display it
if (errMsg) { baseView.toggleActionError('submit', errMsg); } if (errMsg) { baseView.toggleActionError('submit', errMsg); }
...@@ -451,6 +452,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -451,6 +452,7 @@ OpenAssessment.ResponseView.prototype = {
**/ **/
confirmSubmission: function() { confirmSubmission: function() {
// Keep this on one big line to avoid gettext bug: http://stackoverflow.com/a/24579117 // Keep this on one big line to avoid gettext bug: http://stackoverflow.com/a/24579117
/* jshint maxlen:300 */
var msg = gettext("You're about to submit your response for this assignment. After you submit this response, you can't change it or submit a new response."); var msg = gettext("You're about to submit your response for this assignment. After you submit this response, you can't change it or submit a new response.");
// TODO -- UI for confirmation dialog instead of JS confirm // TODO -- UI for confirmation dialog instead of JS confirm
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
...@@ -477,7 +479,7 @@ OpenAssessment.ResponseView.prototype = { ...@@ -477,7 +479,7 @@ OpenAssessment.ResponseView.prototype = {
this.baseView.toggleActionError( this.baseView.toggleActionError(
'upload', gettext("File size must be 5MB or less.") 'upload', gettext("File size must be 5MB or less.")
); );
} else if (this.imageType.substring(0,6) != 'image/') { } else if (this.imageType.substring(0,6) !== 'image/') {
this.baseView.toggleActionError( this.baseView.toggleActionError(
'upload', gettext("File must be an image.") 'upload', gettext("File must be an image.")
); );
......
...@@ -105,7 +105,7 @@ OpenAssessment.Rubric.prototype = { ...@@ -105,7 +105,7 @@ OpenAssessment.Rubric.prototype = {
// Check the selected options // Check the selected options
$(selector, this.element).each(function(index, sel) { $(selector, this.element).each(function(index, sel) {
if (optionsSelected.hasOwnProperty(sel.name)) { if (optionsSelected.hasOwnProperty(sel.name)) {
if (sel.value == optionsSelected[sel.name]) { if (sel.value === optionsSelected[sel.name]) {
$(sel).prop('checked', true); $(sel).prop('checked', true);
} }
} }
...@@ -153,7 +153,7 @@ OpenAssessment.Rubric.prototype = { ...@@ -153,7 +153,7 @@ OpenAssessment.Rubric.prototype = {
} }
}); });
return (numChecked == numAvailable && completedRequiredComments); return (numChecked === numAvailable && completedRequiredComments);
}, },
/** /**
......
...@@ -31,7 +31,7 @@ OpenAssessment.SelfView.prototype = { ...@@ -31,7 +31,7 @@ OpenAssessment.SelfView.prototype = {
view.server.renderLatex($('#openassessment__self-assessment', view.element)); view.server.renderLatex($('#openassessment__self-assessment', view.element));
view.installHandlers(); view.installHandlers();
} }
).fail(function(errMsg) { ).fail(function() {
view.showLoadError('self-assessment'); view.showLoadError('self-assessment');
}); });
}, },
......
...@@ -35,7 +35,7 @@ OpenAssessment.StaffInfoView.prototype = { ...@@ -35,7 +35,7 @@ OpenAssessment.StaffInfoView.prototype = {
view.server.renderLatex($('#openassessment__staff-info', view.element)); view.server.renderLatex($('#openassessment__staff-info', view.element));
view.installHandlers(); view.installHandlers();
} }
).fail(function(errMsg) { ).fail(function() {
view.baseView.showLoadError('staff_info'); view.baseView.showLoadError('staff_info');
}); });
} }
...@@ -56,7 +56,7 @@ OpenAssessment.StaffInfoView.prototype = { ...@@ -56,7 +56,7 @@ OpenAssessment.StaffInfoView.prototype = {
$('#openassessment__student-info', view.element).replaceWith(html); $('#openassessment__student-info', view.element).replaceWith(html);
// Install key handler for new staff grade Save button. // Install key handler for new staff grade Save button.
var selCancelSub = $('#openassessment__staff-info__cancel__submission', this.element); var selCancelSub = $('#openassessment__staff-info__cancel__submission', view.element);
selCancelSub.on('click', '#submit_cancel_submission', function (eventObject) { selCancelSub.on('click', '#submit_cancel_submission', function (eventObject) {
eventObject.preventDefault(); eventObject.preventDefault();
view.cancelSubmission($(this).data('submission-uuid')); view.cancelSubmission($(this).data('submission-uuid'));
...@@ -64,11 +64,12 @@ OpenAssessment.StaffInfoView.prototype = { ...@@ -64,11 +64,12 @@ OpenAssessment.StaffInfoView.prototype = {
); );
// Install change handler for textarea (to enable cancel submission button) // Install change handler for textarea (to enable cancel submission button)
var handleChange = function(eventData) { view.handleCommentChanged(); }; var handleChange = function() { view.handleCommentChanged(); };
selCancelSub.find('#staff-info__cancel-submission__comments').on('change keyup drop paste', handleChange); selCancelSub.find('#staff-info__cancel-submission__comments')
.on('change keyup drop paste', handleChange);
} }
).fail(function(errMsg) { ).fail(function() {
view.showLoadError('student_info'); view.showLoadError('student_info');
}); });
}, },
...@@ -130,10 +131,10 @@ OpenAssessment.StaffInfoView.prototype = { ...@@ -130,10 +131,10 @@ OpenAssessment.StaffInfoView.prototype = {
var view = this; var view = this;
this.server.scheduleTraining().done( this.server.scheduleTraining().done(
function(msg) { function(msg) {
$('#schedule_training_message', this.element).text(msg) $('#schedule_training_message', view.element).text(msg);
} }
).fail(function(errMsg) { ).fail(function(errMsg) {
$('#schedule_training_message', this.element).text(errMsg) $('#schedule_training_message', view.element).text(errMsg);
}); });
}, },
...@@ -147,10 +148,10 @@ OpenAssessment.StaffInfoView.prototype = { ...@@ -147,10 +148,10 @@ OpenAssessment.StaffInfoView.prototype = {
var view = this; var view = this;
this.server.rescheduleUnfinishedTasks().done( this.server.rescheduleUnfinishedTasks().done(
function(msg) { function(msg) {
$('#reschedule_unfinished_tasks_message', this.element).text(msg) $('#reschedule_unfinished_tasks_message', view.element).text(msg);
} }
).fail(function(errMsg) { ).fail(function(errMsg) {
$('#reschedule_unfinished_tasks_message', this.element).text(errMsg) $('#reschedule_unfinished_tasks_message', view.element).text(errMsg);
}); });
}, },
......
...@@ -31,7 +31,7 @@ OpenAssessment.StudentTrainingView.prototype = { ...@@ -31,7 +31,7 @@ OpenAssessment.StudentTrainingView.prototype = {
view.server.renderLatex($('#openassessment__student-training', view.element)); view.server.renderLatex($('#openassessment__student-training', view.element));
view.installHandlers(); view.installHandlers();
} }
).fail(function(errMsg) { ).fail(function() {
view.baseView.showLoadError('student-training'); view.baseView.showLoadError('student-training');
}); });
}, },
...@@ -85,8 +85,8 @@ OpenAssessment.StudentTrainingView.prototype = { ...@@ -85,8 +85,8 @@ OpenAssessment.StudentTrainingView.prototype = {
var baseView = this.baseView; var baseView = this.baseView;
this.server.trainingAssess(options).done( this.server.trainingAssess(options).done(
function(corrections) { function(corrections) {
var incorrect = $("#openassessment__student-training--incorrect", this.element); var incorrect = $("#openassessment__student-training--incorrect", view.element);
var instructions = $("#openassessment__student-training--instructions", this.element); var instructions = $("#openassessment__student-training--instructions", view.element);
if (!view.rubric.showCorrections(corrections)) { if (!view.rubric.showCorrections(corrections)) {
view.load(); view.load();
......
...@@ -4,7 +4,7 @@ Encapsulate interactions with OpenAssessment XBlock handlers. ...@@ -4,7 +4,7 @@ Encapsulate interactions with OpenAssessment XBlock handlers.
// Since the server is included by both LMS and Studio views, // Since the server is included by both LMS and Studio views,
// skip loading it the second time. // skip loading it the second time.
if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { if (typeof OpenAssessment.Server === "undefined" || !OpenAssessment.Server) {
/** /**
Interface for server-side XBlock handlers. Interface for server-side XBlock handlers.
...@@ -56,7 +56,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -56,7 +56,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
) )
**/ **/
render: function(component) { render: function(component) {
var that = this; var view = this;
var url = this.url('render_' + component); var url = this.url('render_' + component);
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ $.ajax({
...@@ -64,9 +64,9 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -64,9 +64,9 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
type: "POST", type: "POST",
dataType: "html" dataType: "html"
}).done(function(data) { }).done(function(data) {
defer.resolveWith(this, [data]); defer.resolveWith(view, [data]);
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, [gettext('This section could not be loaded.')]); defer.rejectWith(view, [gettext('This section could not be loaded.')]);
}); });
}).promise(); }).promise();
}, },
...@@ -108,9 +108,9 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -108,9 +108,9 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
dataType: "html", dataType: "html",
data: {continue_grading: true} data: {continue_grading: true}
}).done(function(data) { }).done(function(data) {
defer.resolveWith(this, [data]); defer.resolveWith(view, [data]);
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, [gettext('This section could not be loaded.')]); defer.rejectWith(view, [gettext('This section could not be loaded.')]);
}); });
}).promise(); }).promise();
}, },
...@@ -128,7 +128,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -128,7 +128,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
data: {student_username: student_username} data: {student_username: student_username}
}).done(function(data) { }).done(function(data) {
defer.resolveWith(this, [data]); defer.resolveWith(this, [data]);
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, [gettext('This section could not be loaded.')]); defer.rejectWith(this, [gettext('This section could not be loaded.')]);
}); });
}).promise(); }).promise();
...@@ -164,7 +164,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -164,7 +164,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
var errorMsg = data[2]; var errorMsg = data[2];
defer.rejectWith(this, [errorNum, errorMsg]); defer.rejectWith(this, [errorNum, errorMsg]);
} }
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, ["AJAX", gettext("This response could not be submitted.")]); defer.rejectWith(this, ["AJAX", gettext("This response could not be submitted.")]);
}); });
}).promise(); }).promise();
...@@ -191,7 +191,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -191,7 +191,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolve(); } if (data.success) { defer.resolve(); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, [gettext("This response could not be saved.")]); defer.rejectWith(this, [gettext("This response could not be saved.")]);
}); });
}).promise(); }).promise();
...@@ -228,7 +228,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -228,7 +228,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
if (data.success) { defer.resolve(); } if (data.success) { defer.resolve(); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
} }
).fail(function(data) { ).fail(function() {
defer.rejectWith(this, [gettext('This feedback could not be submitted.')]); defer.rejectWith(this, [gettext('This feedback could not be submitted.')]);
}); });
}).promise(); }).promise();
...@@ -275,7 +275,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -275,7 +275,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
defer.rejectWith(this, [data.msg]); defer.rejectWith(this, [data.msg]);
} }
} }
).fail(function(data) { ).fail(function() {
defer.rejectWith(this, [gettext('This assessment could not be submitted.')]); defer.rejectWith(this, [gettext('This assessment could not be submitted.')]);
}); });
}).promise(); }).promise();
...@@ -319,7 +319,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -319,7 +319,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
defer.rejectWith(this, [data.msg]); defer.rejectWith(this, [data.msg]);
} }
} }
).fail(function(data) { ).fail(function() {
defer.rejectWith(this, [gettext('This assessment could not be submitted.')]); defer.rejectWith(this, [gettext('This assessment could not be submitted.')]);
}); });
}); });
...@@ -360,7 +360,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -360,7 +360,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
defer.rejectWith(this, [data.msg]); defer.rejectWith(this, [data.msg]);
} }
} }
).fail(function(data) { ).fail(function() {
defer.rejectWith(this, [gettext('This assessment could not be submitted.')]); defer.rejectWith(this, [gettext('This assessment could not be submitted.')]);
}); });
}); });
...@@ -394,7 +394,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -394,7 +394,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
defer.rejectWith(this, [data.msg]); defer.rejectWith(this, [data.msg]);
} }
} }
).fail(function(data) { ).fail(function() {
defer.rejectWith(this, [gettext('This assessment could not be submitted.')]); defer.rejectWith(this, [gettext('This assessment could not be submitted.')]);
}); });
}); });
...@@ -418,7 +418,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -418,7 +418,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
defer.rejectWith(this, [data.msg]); defer.rejectWith(this, [data.msg]);
} }
} }
).fail(function(data) { ).fail(function() {
defer.rejectWith(this, [gettext('One or more rescheduling tasks failed.')]); defer.rejectWith(this, [gettext('One or more rescheduling tasks failed.')]);
}); });
}); });
...@@ -467,7 +467,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -467,7 +467,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolve(); } if (data.success) { defer.resolve(); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, [gettext('This problem could not be saved.')]); defer.rejectWith(this, [gettext('This problem could not be saved.')]);
}); });
}).promise(); }).promise();
...@@ -497,7 +497,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -497,7 +497,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolveWith(this, [data.is_released]); } if (data.success) { defer.resolveWith(this, [data.is_released]); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, [gettext("The server could not be contacted.")]); defer.rejectWith(this, [gettext("The server could not be contacted.")]);
}); });
}).promise(); }).promise();
...@@ -519,11 +519,14 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -519,11 +519,14 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
var url = this.url('upload_url'); var url = this.url('upload_url');
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
$.ajax({ $.ajax({
type: "POST", url: url, data: JSON.stringify({contentType: contentType}), contentType: jsonContentType type: "POST",
url: url,
data: JSON.stringify({contentType: contentType}),
contentType: jsonContentType
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolve(data.url); } if (data.success) { defer.resolve(data.url); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, [gettext('Could not retrieve upload url.')]); defer.rejectWith(this, [gettext('Could not retrieve upload url.')]);
}); });
}).promise(); }).promise();
...@@ -544,7 +547,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -544,7 +547,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
}).done(function(data) { }).done(function(data) {
if (data.success) { defer.resolve(data.url); } if (data.success) { defer.resolve(data.url); }
else { defer.rejectWith(this, [data.msg]); } else { defer.rejectWith(this, [data.msg]); }
}).fail(function(data) { }).fail(function() {
defer.rejectWith(this, [gettext('Could not retrieve download url.')]); defer.rejectWith(this, [gettext('Could not retrieve download url.')]);
}); });
}).promise(); }).promise();
...@@ -572,7 +575,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) { ...@@ -572,7 +575,7 @@ if (typeof OpenAssessment.Server == "undefined" || !OpenAssessment.Server) {
defer.rejectWith(this, [data.msg]); defer.rejectWith(this, [data.msg]);
} }
} }
).fail(function(data) { ).fail(function() {
defer.rejectWith(this, [gettext('The submission could not be removed from the grading pool.')]); defer.rejectWith(this, [gettext('The submission could not be removed from the grading pool.')]);
}); });
}).promise(); }).promise();
......
...@@ -8,9 +8,11 @@ an object! ...@@ -8,9 +8,11 @@ an object!
/* Namespace for open assessment */ /* Namespace for open assessment */
/* jshint ignore:start */
if (typeof OpenAssessment == "undefined" || !OpenAssessment) { if (typeof OpenAssessment == "undefined" || !OpenAssessment) {
OpenAssessment = {}; OpenAssessment = {};
} }
/* jshint ignore:end */
// Stub gettext if the runtime doesn't provide it // Stub gettext if the runtime doesn't provide it
...@@ -27,14 +29,14 @@ if (typeof window.ngetgext === 'undefined') { ...@@ -27,14 +29,14 @@ if (typeof window.ngetgext === 'undefined') {
} else { } else {
return singular_text; return singular_text;
} }
} };
} }
// Stub event logging if the runtime doesn't provide it // Stub event logging if the runtime doesn't provide it
if (typeof window.Logger === 'undefined') { if (typeof window.Logger === 'undefined') {
window.Logger = { window.Logger = {
log: function(event_type, data, kwargs) {} log: function() {}
}; };
} }
...@@ -43,8 +45,8 @@ if (typeof window.Logger === 'undefined') { ...@@ -43,8 +45,8 @@ if (typeof window.Logger === 'undefined') {
if (typeof window.MathJax === 'undefined') { if (typeof window.MathJax === 'undefined') {
window.MathJax = { window.MathJax = {
Hub: { Hub: {
Typeset: function(data){}, Typeset: function() {},
Queue: function(list){} Queue: function() {}
} }
}; };
} }
\ No newline at end of file
...@@ -58,21 +58,21 @@ Kwargs: ...@@ -58,21 +58,21 @@ Kwargs:
notifier (OpenAssessment.Notifier): Used to send notifications of updates to container items. notifier (OpenAssessment.Notifier): Used to send notifications of updates to container items.
**/ **/
OpenAssessment.Container = function(containerItem, kwargs) { OpenAssessment.Container = function(ContainerItem, kwargs) {
this.containerElement = kwargs.containerElement; this.containerElement = kwargs.containerElement;
this.templateElement = kwargs.templateElement; this.templateElement = kwargs.templateElement;
this.addButtonElement = kwargs.addButtonElement; this.addButtonElement = kwargs.addButtonElement;
this.removeButtonClass = kwargs.removeButtonClass; this.removeButtonClass = kwargs.removeButtonClass;
this.containerItemClass = kwargs.containerItemClass; this.containerItemClass = kwargs.containerItemClass;
this.notifier = kwargs.notifier; this.notifier = kwargs.notifier;
this.addRemoveEnabled = (typeof kwargs.addRemoveEnabled == 'undefined') || kwargs.addRemoveEnabled; this.addRemoveEnabled = (typeof kwargs.addRemoveEnabled === 'undefined') || kwargs.addRemoveEnabled;
// Since every container item should be instantiated with // Since every container item should be instantiated with
// the notifier we were given, create a helper method // the notifier we were given, create a helper method
// that does this automatically. // that does this automatically.
var container = this; var container = this;
this.createContainerItem = function(element) { this.createContainerItem = function(element) {
return new containerItem(element, container.notifier); return new ContainerItem(element, container.notifier);
}; };
}; };
......
...@@ -613,7 +613,7 @@ OpenAssessment.RubricCriterion.prototype = { ...@@ -613,7 +613,7 @@ OpenAssessment.RubricCriterion.prototype = {
OpenAssessment.TrainingExample = function(element){ OpenAssessment.TrainingExample = function(element){
this.element = element; this.element = element;
this.criteria = $(".openassessment_training_example_criterion_option", this.element); this.criteria = $(".openassessment_training_example_criterion_option", this.element);
this.answer = $('.openassessment_training_example_essay_part textarea', this.element) this.answer = $('.openassessment_training_example_essay_part textarea', this.element);
}; };
OpenAssessment.TrainingExample.prototype = { OpenAssessment.TrainingExample.prototype = {
......
...@@ -273,11 +273,12 @@ OpenAssessment.StudioView.prototype = { ...@@ -273,11 +273,12 @@ OpenAssessment.StudioView.prototype = {
/* XBlock entry point for Studio view */ /* XBlock entry point for Studio view */
/* jshint unused:false */
function OpenAssessmentEditor(runtime, element) { function OpenAssessmentEditor(runtime, element) {
/** /**
Initialize the editing interface on page load. Initialize the editing interface on page load.
**/ **/
var server = new OpenAssessment.Server(runtime, element); var server = new OpenAssessment.Server(runtime, element);
var view = new OpenAssessment.StudioView(runtime, element, server); new OpenAssessment.StudioView(runtime, element, server);
} }
...@@ -136,7 +136,7 @@ OpenAssessment.ToggleControl.prototype = { ...@@ -136,7 +136,7 @@ OpenAssessment.ToggleControl.prototype = {
Returns: Returns:
OpenAssessment.ToggleControl OpenAssessment.ToggleControl
**/ **/
install: function(checkboxSelector) { install: function() {
this.checkbox.change( this.checkbox.change(
this, function(event) { this, function(event) {
var control = event.data; var control = event.data;
......
...@@ -12,9 +12,9 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -12,9 +12,9 @@ OpenAssessment.StudentTrainingListener.prototype = {
/** /**
Add a answer part in the training examples when a prompt is added. Add a answer part in the training examples when a prompt is added.
*/ */
promptAdd: function(data) { promptAdd: function() {
var view = this.element; var view = this.element;
var essay_part = $("#openassessment_training_example_part_template") $("#openassessment_training_example_part_template")
.children().first() .children().first()
.clone() .clone()
.removeAttr('id') .removeAttr('id')
...@@ -93,6 +93,7 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -93,6 +93,7 @@ OpenAssessment.StudentTrainingListener.prototype = {
}); });
if (criterionAdded) { if (criterionAdded) {
/* jshint maxlen:300 */
this.displayAlertMsg( this.displayAlertMsg(
gettext("Criterion Added"), gettext("Criterion Added"),
gettext("You've added a criterion. You'll need to select an option for the criterion in the Student Training step. To do this, click the Settings tab.") gettext("You've added a criterion. You'll need to select an option for the criterion in the Student Training step. To do this, click the Settings tab.")
...@@ -133,13 +134,14 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -133,13 +134,14 @@ OpenAssessment.StudentTrainingListener.prototype = {
// If all options have been removed from the Criterion, remove // If all options have been removed from the Criterion, remove
// the criterion entirely. // the criterion entirely.
if ($("option", criterionOption).length == 1) { if ($("option", criterionOption).length === 1) {
handler.removeAllOptions(data); handler.removeAllOptions(data);
invalidated = false; invalidated = false;
} }
}); });
if (invalidated) { if (invalidated) {
/* jshint maxlen:300 */
this.displayAlertMsg( this.displayAlertMsg(
gettext("Option Deleted"), gettext("Option Deleted"),
gettext("You've deleted an option. The system has removed that option from its criterion in the sample responses in the Student Training step. You may have to select a new option for the criterion.") gettext("You've deleted an option. The system has removed that option from its criterion in the sample responses in the Student Training step. You may have to select a new option for the criterion.")
...@@ -148,7 +150,10 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -148,7 +150,10 @@ OpenAssessment.StudentTrainingListener.prototype = {
}, },
_optionSel: function(criterionName) { _optionSel: function(criterionName) {
return $('.openassessment_training_example_criterion_option[data-criterion="' + criterionName + '"]', this.element); return $(
'.openassessment_training_example_criterion_option[data-criterion="' + criterionName + '"]',
this.element
);
}, },
/** /**
...@@ -165,13 +170,14 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -165,13 +170,14 @@ OpenAssessment.StudentTrainingListener.prototype = {
var changed = false; var changed = false;
$('.openassessment_training_example_criterion', this.element).each(function() { $('.openassessment_training_example_criterion', this.element).each(function() {
var criterion = this; var criterion = this;
if ($(criterion).data('criterion') == data.criterionName) { if ($(criterion).data('criterion') === data.criterionName) {
$(criterion).remove(); $(criterion).remove();
changed = true; changed = true;
} }
}); });
if (changed) { if (changed) {
/* jshint maxlen:300 */
this.displayAlertMsg( this.displayAlertMsg(
gettext("Option Deleted"), gettext("Option Deleted"),
gettext("You've deleted all the options for this criterion. The system has removed the criterion from the sample responses in the Student Training step.") gettext("You've deleted all the options for this criterion. The system has removed the criterion from the sample responses in the Student Training step.")
...@@ -199,6 +205,7 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -199,6 +205,7 @@ OpenAssessment.StudentTrainingListener.prototype = {
); );
if (changed) { if (changed) {
/* jshint maxlen:300 */
this.displayAlertMsg( this.displayAlertMsg(
gettext("Criterion Deleted"), gettext("Criterion Deleted"),
gettext("You've deleted a criterion. The system has removed the criterion from the sample responses in the Student Training step.") gettext("You've deleted a criterion. The system has removed the criterion from the sample responses in the Student Training step.")
...@@ -369,14 +376,14 @@ OpenAssessment.AssessmentToggleListener = function() { ...@@ -369,14 +376,14 @@ OpenAssessment.AssessmentToggleListener = function() {
}; };
OpenAssessment.AssessmentToggleListener.prototype = { OpenAssessment.AssessmentToggleListener.prototype = {
toggleOff: function(data) { toggleOff: function() {
this.alert.setMessage( this.alert.setMessage(
gettext("Warning"), gettext("Warning"),
gettext("Changes to steps that are not selected as part of the assignment will not be saved.") gettext("Changes to steps that are not selected as part of the assignment will not be saved.")
).show(); ).show();
}, },
toggleOn: function(data) { toggleOn: function() {
this.alert.hide(); this.alert.hide();
} }
}; };
...@@ -11,7 +11,7 @@ Returns: ...@@ -11,7 +11,7 @@ Returns:
OpenAssessment.EditPromptsView = function(element, notifier) { OpenAssessment.EditPromptsView = function(element, notifier) {
this.element = element; this.element = element;
this.editorElement = $(this.element).closest("#openassessment-editor"); this.editorElement = $(this.element).closest("#openassessment-editor");
this.addRemoveEnabled = !(this.editorElement.attr('data-is-released') === 'true'); this.addRemoveEnabled = this.editorElement.attr('data-is-released') !== 'true';
this.promptsContainer = new OpenAssessment.Container( this.promptsContainer = new OpenAssessment.Container(
OpenAssessment.Prompt, { OpenAssessment.Prompt, {
......
...@@ -65,7 +65,7 @@ OpenAssessment.EditSettingsView.prototype = { ...@@ -65,7 +65,7 @@ OpenAssessment.EditSettingsView.prototype = {
.sortable('refresh').sortable('refreshPositions'); .sortable('refresh').sortable('refreshPositions');
}, },
// On stop, we redisplay the divs to their original state // On stop, we redisplay the divs to their original state
stop: function(event, ui){ stop: function() {
$('.openassessment_assessment_module_editor', view.element).show(); $('.openassessment_assessment_module_editor', view.element).show();
}, },
snap: true, snap: true,
...@@ -134,10 +134,10 @@ OpenAssessment.EditSettingsView.prototype = { ...@@ -134,10 +134,10 @@ OpenAssessment.EditSettingsView.prototype = {
imageSubmissionEnabled: function(isEnabled) { imageSubmissionEnabled: function(isEnabled) {
var sel = $("#openassessment_submission_image_editor", this.settingsElement); var sel = $("#openassessment_submission_image_editor", this.settingsElement);
if (isEnabled !== undefined) { if (isEnabled !== undefined) {
if (isEnabled) { sel.val(1); } if (isEnabled) { sel.val("1"); }
else { sel.val(0); } else { sel.val("0"); }
} }
return (sel.val() == 1); return sel.val() === "1";
}, },
/** /**
...@@ -154,10 +154,10 @@ OpenAssessment.EditSettingsView.prototype = { ...@@ -154,10 +154,10 @@ OpenAssessment.EditSettingsView.prototype = {
if (isEnabled) { if (isEnabled) {
sel.val(1); sel.val(1);
} else { } else {
sel.val(0) sel.val(0);
} }
} }
return (sel.val() == 1); return sel.val() === 1;
}, },
/** /**
Get or set the number of scores to show in the leaderboard. Get or set the number of scores to show in the leaderboard.
...@@ -212,7 +212,7 @@ OpenAssessment.EditSettingsView.prototype = { ...@@ -212,7 +212,7 @@ OpenAssessment.EditSettingsView.prototype = {
var asmntView = view.assessmentViews[$(this).attr('id')]; var asmntView = view.assessmentViews[$(this).attr('id')];
if (asmntView.isEnabled()) { if (asmntView.isEnabled()) {
var description = asmntView.description(); var description = asmntView.description();
description["name"] = asmntView.name; description.name = asmntView.name;
assessmentDescList.push(description); assessmentDescList.push(description);
} }
} }
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"karma-jasmine": "0.1.5", "karma-jasmine": "0.1.5",
"karma-phantomjs-launcher": "^0.1.4", "karma-phantomjs-launcher": "^0.1.4",
"karma-spec-reporter": "^0.0.20", "karma-spec-reporter": "^0.0.20",
"uglify-js": "2.3.6" "uglify-js": "2.3.6",
"jshint": "2.8.0"
}, },
"scripts": { "scripts": {
"test": "./node_modules/karma/bin/karma start --reporters spec,coverage" "test": "./node_modules/karma/bin/karma start --reporters spec,coverage"
......
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