Commit c43aa62f by Don Mitchell

Need to still add create and delete but otherwise done.

parent 39024a7f
...@@ -123,7 +123,7 @@ class CourseGradingModel: ...@@ -123,7 +123,7 @@ class CourseGradingModel:
get_modulestore(course_location).update_item(course_location, descriptor.definition['data']) get_modulestore(course_location).update_item(course_location, descriptor.definition['data'])
return grader return CourseGradingModel.jsonize_grader(index, descriptor.raw_grader[index])
@staticmethod @staticmethod
def update_cutoffs_from_json(course_location, cutoffs): def update_cutoffs_from_json(course_location, cutoffs):
...@@ -219,10 +219,10 @@ class CourseGradingModel: ...@@ -219,10 +219,10 @@ class CourseGradingModel:
# manual to clear out kruft # manual to clear out kruft
result = { result = {
"type" : json_grader["type"], "type" : json_grader["type"],
"min_count" : json_grader.get('min_count', 0), "min_count" : int(json_grader.get('min_count', 0)),
"drop_count" : json_grader.get('drop_count', 0), "drop_count" : int(json_grader.get('drop_count', 0)),
"short_label" : json_grader.get('short_label', None), "short_label" : json_grader.get('short_label', None),
"weight" : json_grader.get('weight', 0) / 100.0 "weight" : float(json_grader.get('weight', 0)) / 100.0
} }
return result return result
......
...@@ -73,25 +73,27 @@ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({ ...@@ -73,25 +73,27 @@ CMS.Models.Settings.CourseGrader = Backbone.Model.extend({
} }
} }
if (attrs['weight']) { if (attrs['weight']) {
if (!parseInt(attrs.weight)) { if (!isFinite(attrs.weight) || !parseInt(attrs.weight)) {
errors.weight = "Please enter an integer between 0 and 100."; errors.weight = "Please enter an integer between 0 and 100.";
} }
else { else {
attrs.weight = parseInt(attrs.weight); // see if this ensures value saved is int attrs.weight = parseInt(attrs.weight); // see if this ensures value saved is int
if (this.collection && attrs.weight > 0) { if (this.collection && attrs.weight > 0) {
// if get() doesn't get the value before the call, use previous() // FIXME b/c saves don't update the models if validation fails, we should
if ((this.collection.sumWeights() + attrs.weight - this.get('weight')) > 100) // either revert the field value to the one in the model and make them make room
errors.weight = "The weights cannot add to more than 100."; // or figure out a wholistic way to balance the vals across the whole
// if ((this.collection.sumWeights() + attrs.weight - this.get('weight')) > 100)
// errors.weight = "The weights cannot add to more than 100.";
} }
}} }}
if (attrs['min_count']) { if (attrs['min_count']) {
if (!parseInt(attrs.min_count)) { if (!isFinite(attrs.min_count) || !parseInt(attrs.min_count)) {
errors.min_count = "Please enter an integer."; errors.min_count = "Please enter an integer.";
} }
else attrs.min_count = parseInt(attrs.min_count); else attrs.min_count = parseInt(attrs.min_count);
} }
if (attrs['drop_count']) { if (attrs['drop_count']) {
if (!parseInt(attrs.drop_count)) { if (!isFinite(attrs.drop_count) || !parseInt(attrs.drop_count)) {
errors.drop_count = "Please enter an integer."; errors.drop_count = "Please enter an integer.";
} }
else attrs.drop_count = parseInt(attrs.drop_count); else attrs.drop_count = parseInt(attrs.drop_count);
......
...@@ -20,12 +20,12 @@ CMS.Views.ValidatingView = Backbone.View.extend({ ...@@ -20,12 +20,12 @@ CMS.Views.ValidatingView = Backbone.View.extend({
// Your subclass must populate this w/ all of the model keys and dom selectors // Your subclass must populate this w/ all of the model keys and dom selectors
// which may be the subjects of validation errors // which may be the subjects of validation errors
}, },
_cacheValidationErrors : null, _cacheValidationErrors : [],
handleValidationError : function(model, error) { handleValidationError : function(model, error) {
this._cacheValidationErrors = error;
// error is object w/ fields and error strings // error is object w/ fields and error strings
for (var field in error) { for (var field in error) {
var ele = this.$el.find(this.fieldToSelectorMap[field]); var ele = this.$el.find('#' + this.fieldToSelectorMap[field]);
this._cacheValidationErrors.push(ele);
if ($(ele).is('div')) { if ($(ele).is('div')) {
// put error on the contained inputs // put error on the contained inputs
$(ele).find('input, textarea').addClass('error'); $(ele).find('input, textarea').addClass('error');
...@@ -36,10 +36,9 @@ CMS.Views.ValidatingView = Backbone.View.extend({ ...@@ -36,10 +36,9 @@ CMS.Views.ValidatingView = Backbone.View.extend({
}, },
clearValidationErrors : function() { clearValidationErrors : function() {
if (this._cacheValidationErrors == null) return;
// error is object w/ fields and error strings // error is object w/ fields and error strings
for (var field in this._cacheValidationErrors) { while (this._cacheValidationErrors.length > 0) {
var ele = this.$el.find(this.fieldToSelectorMap[field]); var ele = this._cacheValidationErrors.pop();
if ($(ele).is('div')) { if ($(ele).is('div')) {
// put error on the contained inputs // put error on the contained inputs
$(ele).find('input, textarea').removeClass('error'); $(ele).find('input, textarea').removeClass('error');
...@@ -47,7 +46,6 @@ CMS.Views.ValidatingView = Backbone.View.extend({ ...@@ -47,7 +46,6 @@ CMS.Views.ValidatingView = Backbone.View.extend({
else $(ele).removeClass('error'); else $(ele).removeClass('error');
$(ele).nextAll('.message-error').remove(); $(ele).nextAll('.message-error').remove();
} }
this._cacheValidationErrors = null;
} }
}) })
...@@ -194,7 +192,9 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -194,7 +192,9 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
var div = this.$el.find(this.fieldToSelectorMap[fieldName]); var div = this.$el.find(this.fieldToSelectorMap[fieldName]);
var datefield = $(div).find(".date"); var datefield = $(div).find(".date");
var timefield = $(div).find(".time"); var timefield = $(div).find(".time");
var cachethis = this;
var savefield = function() { var savefield = function() {
cachethis.clearValidationErrors();
cacheModel.save(fieldName, new Date(datefield.datepicker('getDate').getTime() cacheModel.save(fieldName, new Date(datefield.datepicker('getDate').getTime()
+ timefield.timepicker("getSecondsFromMidnight") * 1000)); + timefield.timepicker("getSecondsFromMidnight") * 1000));
}; };
...@@ -219,13 +219,16 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -219,13 +219,16 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
break; break;
case 'course-overview': case 'course-overview':
this.clearValidationErrors();
this.model.save('overview', $(event.currentTarget).val()); this.model.save('overview', $(event.currentTarget).val());
break; break;
case 'course-effort': case 'course-effort':
this.clearValidationErrors();
this.model.save('effort', $(event.currentTarget).val()); this.model.save('effort', $(event.currentTarget).val());
break; break;
case 'course-introduction-video': case 'course-introduction-video':
this.clearValidationErrors();
var previewsource = this.model.save_videosource($(event.currentTarget).val()); var previewsource = this.model.save_videosource($(event.currentTarget).val());
this.$el.find(".current-course-introduction-video iframe").attr("src", previewsource); this.$el.find(".current-course-introduction-video iframe").attr("src", previewsource);
break break
...@@ -324,15 +327,16 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ ...@@ -324,15 +327,16 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
'grace_period' : 'course-grading-graceperiod' 'grace_period' : 'course-grading-graceperiod'
}, },
updateModel : function(event) { updateModel : function(event) {
if (!this.selectorToField[event.currentTarget.id]) return;
switch (this.selectorToField[event.currentTarget.id]) { switch (this.selectorToField[event.currentTarget.id]) {
case null:
break;
case 'grace_period': case 'grace_period':
this.clearValidationErrors();
this.model.save('grace_period', $(event.currentTarget).timepicker('getTime')); this.model.save('grace_period', $(event.currentTarget).timepicker('getTime'));
break; break;
default: default:
this.clearValidationErrors();
this.model.save(this.selectorToField[event.currentTarget.id], $(event.currentTarget).val()); this.model.save(this.selectorToField[event.currentTarget.id], $(event.currentTarget).val());
break; break;
} }
...@@ -568,6 +572,7 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({ ...@@ -568,6 +572,7 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({
this.$el.find('#course-grading-assignment-droppable').attr('max', $(event.currentTarget).val()); this.$el.find('#course-grading-assignment-droppable').attr('max', $(event.currentTarget).val());
// no break b/c want to use the default save // no break b/c want to use the default save
default: default:
this.clearValidationErrors();
this.model.save(this.selectorToField[event.currentTarget.id], $(event.currentTarget).val()); this.model.save(this.selectorToField[event.currentTarget.id], $(event.currentTarget).val());
break; break;
......
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