Commit 19927a83 by Don Mitchell

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.
parent ab4fd03d
......@@ -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);
},
......
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);
};
\ No newline at end of file
......@@ -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();
}
......
......@@ -10,6 +10,7 @@
<script type="text/javascript" src="${static.url('js/models/course_info.js')}"></script>
<script type="text/javascript" src="${static.url('js/models/module_info.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/course_info_edit.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/server_error.js')}"></script>
<link rel="stylesheet" type="text/css" href="${static.url('js/vendor/timepicker/jquery.timepicker.css')}" />
<script src="${static.url('js/vendor/timepicker/jquery.timepicker.js')}"></script>
<script src="${static.url('js/vendor/timepicker/datepair.js')}"></script>
......
......@@ -20,6 +20,7 @@ from contentstore import utils
<script type="text/javascript" src="${static.url('js/models/settings/course_settings.js')}"></script>
<script type="text/javascript" src="${static.url('js/models/settings/course_grading_policy.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/settings/main_settings_view.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/server_error.js')}"></script>
<script type="text/javascript">
$(document).ready(function(){
......
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