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