Ensure settings and course info CRUD operations tell the user if there's
a server error and pull the server error handler into a common function.
This commit is contained in:
@@ -69,17 +69,11 @@ CMS.Models.Settings.CourseDetails = Backbone.Model.extend({
|
||||
// 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
|
||||
if (_.isEmpty(newsource) && !_.isEmpty(this.get('intro_video'))) this.save({'intro_video': null},
|
||||
{ error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
{ error : CMS.ServerError});
|
||||
// TODO remove all whitespace w/in string
|
||||
else {
|
||||
if (this.get('intro_video') !== newsource) this.save('intro_video', newsource,
|
||||
{ error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
{ error : CMS.ServerError});
|
||||
}
|
||||
|
||||
return this.videosourceSample();
|
||||
|
||||
@@ -99,10 +99,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
|
||||
var targetModel = this.eventModel(event);
|
||||
targetModel.set({ date : this.dateEntry(event).val(), content : this.$codeMirror.getValue() });
|
||||
// push change to display, hide the editor, submit the change
|
||||
targetModel.save({}, {error : function(model, xhr) {
|
||||
// TODO use a standard component
|
||||
window.alert(xhr.responseText);
|
||||
}});
|
||||
targetModel.save({}, {error : CMS.ServerError});
|
||||
this.closeEditor(this);
|
||||
},
|
||||
|
||||
@@ -145,8 +142,10 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
|
||||
this.modelDom(event).remove();
|
||||
var cacheThis = this;
|
||||
targetModel.destroy({success : function (model, response) {
|
||||
cacheThis.collection.fetch({success : function() {cacheThis.render();}});
|
||||
}
|
||||
cacheThis.collection.fetch({success : function() {cacheThis.render();},
|
||||
error : CMS.ServerError});
|
||||
},
|
||||
error : CMS.ServerError
|
||||
});
|
||||
},
|
||||
|
||||
@@ -225,7 +224,8 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({
|
||||
self.render();
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
error : CMS.ServerError
|
||||
}
|
||||
);
|
||||
},
|
||||
@@ -267,7 +267,7 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({
|
||||
onSave: function(event) {
|
||||
this.model.set('data', this.$codeMirror.getValue());
|
||||
this.render();
|
||||
this.model.save();
|
||||
this.model.save({}, {error: CMS.ServerError});
|
||||
this.$form.hide();
|
||||
this.closeEditor(this);
|
||||
},
|
||||
|
||||
4
cms/static/js/views/server_error.js
Normal file
4
cms/static/js/views/server_error.js
Normal file
@@ -0,0 +1,4 @@
|
||||
CMS.ServerError = function(model, error) {
|
||||
// this handler is for the client:server communication not the validation errors which handleValidationError catches
|
||||
window.alert("Server Error: " + error.responseText);
|
||||
};
|
||||
@@ -55,10 +55,7 @@ CMS.Views.ValidatingView = Backbone.View.extend({
|
||||
var newVal = $(event.currentTarget).val();
|
||||
if (currentVal != newVal) {
|
||||
this.clearValidationErrors();
|
||||
this.model.save(field, newVal, { error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
this.model.save(field, newVal, { error : CMS.ServerError});
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
@@ -231,10 +228,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
|
||||
}
|
||||
var newVal = new Date(date.getTime() + time * 1000);
|
||||
if (cacheModel.get(fieldName) != newVal) cacheModel.save(fieldName, newVal,
|
||||
{ error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
{ error : CMS.ServerError});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -284,10 +278,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
|
||||
|
||||
removeSyllabus: function() {
|
||||
if (this.model.has('syllabus')) this.model.save({'syllabus': null},
|
||||
{ error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
{ error : CMS.ServerError});
|
||||
},
|
||||
|
||||
assetSyllabus : function() {
|
||||
@@ -321,10 +312,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
|
||||
cachethis.clearValidationErrors();
|
||||
var newVal = mirror.getValue();
|
||||
if (cachethis.model.get(field) != newVal) cachethis.model.save(field, newVal,
|
||||
{ error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
{ error : CMS.ServerError});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -420,10 +408,7 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
|
||||
event.data.clearValidationErrors();
|
||||
var newVal = event.data.model.dateToGracePeriod($(event.currentTarget).timepicker('getTime'));
|
||||
if (event.data.model.get('grace_period') != newVal) event.data.model.save('grace_period', newVal,
|
||||
{ error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
{ error : CMS.ServerError});
|
||||
},
|
||||
updateModel : function(event) {
|
||||
if (!this.selectorToField[event.currentTarget.id]) return;
|
||||
@@ -560,10 +545,7 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
|
||||
return object;
|
||||
},
|
||||
{}),
|
||||
{ error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
{ error : CMS.ServerError});
|
||||
},
|
||||
|
||||
addNewGrade: function(e) {
|
||||
@@ -695,10 +677,7 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({
|
||||
},
|
||||
deleteModel : function(e) {
|
||||
this.model.destroy(
|
||||
{ error : function(model, error) {
|
||||
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
|
||||
window.alert("Error during save: " + error.responseText);
|
||||
}});
|
||||
{ error : CMS.ServerError});
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user