Try to make server and validation errors work together. Getting double
errors when there are parent and child views both defining on error handlers still.
This commit is contained in:
@@ -68,12 +68,10 @@ CMS.Models.Settings.CourseDetails = Backbone.Model.extend({
|
|||||||
save_videosource: function(newsource) {
|
save_videosource: function(newsource) {
|
||||||
// newsource either is <video youtube="speed:key, *"/> or just the "speed:key, *" string
|
// newsource either is <video youtube="speed:key, *"/> or just the "speed:key, *" string
|
||||||
// returns the videosource for the preview which iss the key whose speed is closest to 1
|
// returns the videosource for the preview which iss the key whose speed is closest to 1
|
||||||
if (_.isEmpty(newsource) && !_.isEmpty(this.get('intro_video'))) this.save({'intro_video': null},
|
if (_.isEmpty(newsource) && !_.isEmpty(this.get('intro_video'))) this.set({'intro_video': null});
|
||||||
{ error : CMS.ServerError});
|
|
||||||
// TODO remove all whitespace w/in string
|
// TODO remove all whitespace w/in string
|
||||||
else {
|
else {
|
||||||
if (this.get('intro_video') !== newsource) this.save('intro_video', newsource,
|
if (this.get('intro_video') !== newsource) this.set('intro_video', newsource);
|
||||||
{ error : CMS.ServerError});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.videosourceSample();
|
return this.videosourceSample();
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
|
|||||||
setupDatePicker: function (fieldName) {
|
setupDatePicker: function (fieldName) {
|
||||||
var cacheModel = this.model;
|
var cacheModel = this.model;
|
||||||
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("input:.date");
|
||||||
var timefield = $(div).find(".time");
|
var timefield = $(div).find("input:.time");
|
||||||
var cachethis = this;
|
var cachethis = this;
|
||||||
var savefield = function () {
|
var savefield = function () {
|
||||||
cachethis.clearValidationErrors();
|
cachethis.clearValidationErrors();
|
||||||
@@ -97,7 +97,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
|
|||||||
}
|
}
|
||||||
var newVal = new Date(date.getTime() + time * 1000);
|
var newVal = new Date(date.getTime() + time * 1000);
|
||||||
if (cacheModel.get(fieldName).getTime() !== newVal.getTime()) {
|
if (cacheModel.get(fieldName).getTime() !== newVal.getTime()) {
|
||||||
cacheModel.save(fieldName, newVal, { error: CMS.ServerError});
|
cacheModel.save(fieldName, newVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -149,8 +149,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
removeSyllabus: function() {
|
removeSyllabus: function() {
|
||||||
if (this.model.has('syllabus')) this.model.save({'syllabus': null},
|
if (this.model.has('syllabus')) this.model.save({'syllabus': null});
|
||||||
{ error : CMS.ServerError});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
assetSyllabus : function() {
|
assetSyllabus : function() {
|
||||||
@@ -184,8 +183,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
|
|||||||
mirror.save();
|
mirror.save();
|
||||||
cachethis.clearValidationErrors();
|
cachethis.clearValidationErrors();
|
||||||
var newVal = mirror.getValue();
|
var newVal = mirror.getValue();
|
||||||
if (cachethis.model.get(field) != newVal) cachethis.model.save(field, newVal,
|
if (cachethis.model.get(field) != newVal) cachethis.model.save(field, newVal);
|
||||||
{ error: CMS.ServerError});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,19 @@ CMS.Views.ValidatingView = Backbone.View.extend({
|
|||||||
},
|
},
|
||||||
_cacheValidationErrors : [],
|
_cacheValidationErrors : [],
|
||||||
handleValidationError : function(model, error) {
|
handleValidationError : function(model, error) {
|
||||||
|
// error triggered either by validation or server 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]);
|
||||||
|
if (ele.length === 0) {
|
||||||
|
// check if it might a server error: note a typo in the field name
|
||||||
|
// or failure to put in a map may cause this to muffle validation errors
|
||||||
|
if (_.has(error, 'error') && _.has(error, 'responseText')) {
|
||||||
|
CMS.ServerError(model, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else continue;
|
||||||
|
}
|
||||||
this._cacheValidationErrors.push(ele);
|
this._cacheValidationErrors.push(ele);
|
||||||
if ($(ele).is('div')) {
|
if ($(ele).is('div')) {
|
||||||
// put error on the contained inputs
|
// put error on the contained inputs
|
||||||
@@ -50,9 +60,9 @@ CMS.Views.ValidatingView = Backbone.View.extend({
|
|||||||
var field = this.selectorToField[event.currentTarget.id];
|
var field = this.selectorToField[event.currentTarget.id];
|
||||||
var currentVal = this.model.get(field);
|
var currentVal = this.model.get(field);
|
||||||
var newVal = $(event.currentTarget).val();
|
var newVal = $(event.currentTarget).val();
|
||||||
|
this.clearValidationErrors(); // curr = new if user reverts manually
|
||||||
if (currentVal != newVal) {
|
if (currentVal != newVal) {
|
||||||
this.clearValidationErrors();
|
this.model.save(field, newVal);
|
||||||
this.model.save(field, newVal, { error : CMS.ServerError});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user