Commit 56b87a06 by Stephen Sanchez

Adding checks to the alerts for student training.

parent a0131c36
...@@ -590,6 +590,10 @@ ...@@ -590,6 +590,10 @@
] ]
} }
}, },
"student_training": {
"start": "",
"due": ""
},
"peer_assessment": { "peer_assessment": {
"start": "2014-01-02T00:00", "start": "2014-01-02T00:00",
"due": "2020-01-01T12:34", "due": "2020-01-01T12:34",
......
...@@ -273,6 +273,48 @@ describe("OpenAssessment.StudentTrainingListener", function() { ...@@ -273,6 +273,48 @@ describe("OpenAssessment.StudentTrainingListener", function() {
// The alert should be displayed // The alert should be displayed
expect(listener.alert.isVisible()).toBe(true); expect(listener.alert.isVisible()).toBe(true);
}); });
it("does not display an alert when student training is disabled", function() {
var studentTrainingView =
new OpenAssessment.EditStudentTrainingView($('#oa_student_training_editor'));
studentTrainingView.isEnabled(false);
// Initial state, set by the fixture
assertExampleLabels(
listener.examplesCriteriaLabels(),
{ criterion_with_two_options: "Criterion with two options" }
);
expect(listener.alert.isVisible()).toBe(false);
// Remove the criterion
listener.criterionRemove({
criterionName: "criterion_with_two_options"
});
// The criterion should no longer be displayed
assertExampleLabels(listener.examplesCriteriaLabels(), {}, 1);
// The alert should not be displayed.
expect(listener.alert.isVisible()).toBe(false);
});
it("does not display an alert with no training examples", function() {
// Clear out all examples.
var studentTrainingView =
new OpenAssessment.EditStudentTrainingView($('#oa_student_training_editor'));
var items = studentTrainingView.exampleContainer.getAllItems();
$(items).each(function(){
studentTrainingView.exampleContainer.remove(this);
});
expect(listener.alert.isVisible()).toBe(false);
// Remove the criterion
listener.criterionRemove({
criterionName: "criterion_with_two_options"
});
// The alert should not be displayed.
expect(listener.alert.isVisible()).toBe(false);
});
}); });
......
...@@ -20,10 +20,7 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -20,10 +20,7 @@ OpenAssessment.StudentTrainingListener.prototype = {
points (int): The point value for the option. points (int): The point value for the option.
*/ */
optionUpdated: function(data) { optionUpdated: function(data) {
var view = this; this._optionSel(data.criterionName).each(
var sel = '.openassessment_training_example_criterion[data-criterion="' + data.criterionName + '"]';
$(sel, this.element).each(
function() { function() {
var criterion = this; var criterion = this;
var option = $('option[value="' + data.name + '"]', criterion) var option = $('option[value="' + data.name + '"]', criterion)
...@@ -52,34 +49,28 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -52,34 +49,28 @@ OpenAssessment.StudentTrainingListener.prototype = {
*/ */
optionAdd: function(data) { optionAdd: function(data) {
// First, check to see if the criterion exists on the training examples // First, check to see if the criterion exists on the training examples
var options = $('.openassessment_training_example_criterion_option[data-criterion="' + data.criterionName + '"]');
var view = this;
var criterionAdded = false; var criterionAdded = false;
var examplesUpdated = false; if (this._optionSel(data.criterionName).length === 0) {
if (options.length === 0) {
this.criterionAdd(data); this.criterionAdd(data);
criterionAdded = true; criterionAdded = true;
} }
$('.openassessment_training_example_criterion_option', this.element).each(function() { this._optionSel(data.criterionName).each(function() {
if ($(this).data('criterion') === data.criterionName) { var criterion = this;
var criterion = this; // Risky; making an assumption that options will remain simple.
// Risky; making an assumption that options will remain simple. // updates could cause this to get out of sync with templates,
// updates could cause this to get out of sync with templates, // but this avoids overly complex templating code.
// but this avoids overly complex templating code. var option = $("<option></option>")
var option = $("<option></option>") .attr("value", data.name)
.attr("value", data.name) .data("points", data.points)
.data("points", data.points) .data("label", data.label);
.data("label", data.label);
// Sets the option's text description, and adds it to the criterion.
// Sets the option's text description, and adds it to the criterion. OpenAssessment.ItemUtilities.refreshOptionString(option);
OpenAssessment.ItemUtilities.refreshOptionString(option); $(criterion).append(option);
$(criterion).append(option);
examplesUpdated = true;
}
}); });
if (criterionAdded && examplesUpdated) { if (criterionAdded) {
this.displayAlertMsg( this.displayAlertMsg(
gettext("Criterion Addition requires Training Example Updates"), gettext("Criterion Addition requires Training Example Updates"),
gettext("Because you added a criterion, student training examples will have to be updated.") gettext("Because you added a criterion, student training examples will have to be updated.")
...@@ -105,26 +96,24 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -105,26 +96,24 @@ OpenAssessment.StudentTrainingListener.prototype = {
optionRemove: function(data) { optionRemove: function(data) {
var handler = this; var handler = this;
var invalidated = false; var invalidated = false;
$('.openassessment_training_example_criterion_option', this.element).each(function() { this._optionSel(data.criterionName).each(function() {
var criterionOption = this; var criterionOption = this;
if ($(criterionOption).data('criterion') === data.criterionName) { if ($(criterionOption).val() === data.name.toString()) {
if ($(criterionOption).val() === data.name.toString()) { $(criterionOption).val("")
$(criterionOption).val(""); .addClass("openassessment_highlighted_field")
$(criterionOption).addClass("openassessment_highlighted_field"); .click(function() {
$(criterionOption).click(function() { $(criterionOption).removeClass("openassessment_highlighted_field");
$(criterionOption).removeClass("openassessment_highlighted_field"); });
}); invalidated = true;
invalidated = true; }
}
$('option[value="' + data.name + '"]', criterionOption).remove();
$('option[value="' + data.name + '"]', criterionOption).remove();
// 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;
}
} }
}); });
...@@ -136,6 +125,10 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -136,6 +125,10 @@ OpenAssessment.StudentTrainingListener.prototype = {
} }
}, },
_optionSel: function(criterionName) {
return $('.openassessment_training_example_criterion_option[data-criterion="' + criterionName + '"]', this.element);
},
/** /**
Event handler for when all options are removed from a criterion. Right now, Event handler for when all options are removed from a criterion. Right now,
the logic is the same as if the criterion was removed. When all options are the logic is the same as if the criterion was removed. When all options are
...@@ -192,7 +185,8 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -192,7 +185,8 @@ OpenAssessment.StudentTrainingListener.prototype = {
}, },
/** /**
Sets up the alert window based on a change message. Sets up the alert window based on a change message. Checks that there is
at least one training example, and that student training is enabled.
Args: Args:
title (str): Title of the alert message. title (str): Title of the alert message.
...@@ -200,7 +194,11 @@ OpenAssessment.StudentTrainingListener.prototype = { ...@@ -200,7 +194,11 @@ OpenAssessment.StudentTrainingListener.prototype = {
*/ */
displayAlertMsg: function(title, msg) { displayAlertMsg: function(title, msg) {
this.alert.setMessage(title, msg).show(); if ($("#include_student_training", this.element).is(":checked") &&
// Check for at least more than one example, to exclude the template
$(".openassessment_training_example", this.element).length > 1) {
this.alert.setMessage(title, msg).show();
}
}, },
/** /**
......
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