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({ ...@@ -69,17 +69,11 @@ CMS.Models.Settings.CourseDetails = Backbone.Model.extend({
// 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.save({'intro_video': null},
{ error : function(model, error) { { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
// 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.save('intro_video', newsource,
{ error : function(model, error) { { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
} }
return this.videosourceSample(); return this.videosourceSample();
......
...@@ -99,10 +99,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -99,10 +99,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
var targetModel = this.eventModel(event); var targetModel = this.eventModel(event);
targetModel.set({ date : this.dateEntry(event).val(), content : this.$codeMirror.getValue() }); targetModel.set({ date : this.dateEntry(event).val(), content : this.$codeMirror.getValue() });
// push change to display, hide the editor, submit the change // push change to display, hide the editor, submit the change
targetModel.save({}, {error : function(model, xhr) { targetModel.save({}, {error : CMS.ServerError});
// TODO use a standard component
window.alert(xhr.responseText);
}});
this.closeEditor(this); this.closeEditor(this);
}, },
...@@ -145,8 +142,10 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -145,8 +142,10 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
this.modelDom(event).remove(); this.modelDom(event).remove();
var cacheThis = this; var cacheThis = this;
targetModel.destroy({success : function (model, response) { 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({ ...@@ -225,7 +224,8 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({
self.render(); self.render();
} }
); );
} },
error : CMS.ServerError
} }
); );
}, },
...@@ -267,7 +267,7 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({ ...@@ -267,7 +267,7 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({
onSave: function(event) { onSave: function(event) {
this.model.set('data', this.$codeMirror.getValue()); this.model.set('data', this.$codeMirror.getValue());
this.render(); this.render();
this.model.save(); this.model.save({}, {error: CMS.ServerError});
this.$form.hide(); this.$form.hide();
this.closeEditor(this); 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({ ...@@ -55,10 +55,7 @@ CMS.Views.ValidatingView = Backbone.View.extend({
var newVal = $(event.currentTarget).val(); var newVal = $(event.currentTarget).val();
if (currentVal != newVal) { if (currentVal != newVal) {
this.clearValidationErrors(); this.clearValidationErrors();
this.model.save(field, newVal, { error : function(model, error) { this.model.save(field, newVal, { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
return true; return true;
} }
else return false; else return false;
...@@ -231,10 +228,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -231,10 +228,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) != newVal) cacheModel.save(fieldName, newVal, if (cacheModel.get(fieldName) != newVal) cacheModel.save(fieldName, newVal,
{ error : function(model, error) { { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
} }
}; };
...@@ -284,10 +278,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -284,10 +278,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 : function(model, error) { { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
}, },
assetSyllabus : function() { assetSyllabus : function() {
...@@ -321,10 +312,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -321,10 +312,7 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
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 : function(model, error) { { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
} }
}); });
} }
...@@ -420,10 +408,7 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ ...@@ -420,10 +408,7 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
event.data.clearValidationErrors(); event.data.clearValidationErrors();
var newVal = event.data.model.dateToGracePeriod($(event.currentTarget).timepicker('getTime')); 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, if (event.data.model.get('grace_period') != newVal) event.data.model.save('grace_period', newVal,
{ error : function(model, error) { { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
}, },
updateModel : function(event) { updateModel : function(event) {
if (!this.selectorToField[event.currentTarget.id]) return; if (!this.selectorToField[event.currentTarget.id]) return;
...@@ -560,10 +545,7 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({ ...@@ -560,10 +545,7 @@ CMS.Views.Settings.Grading = CMS.Views.ValidatingView.extend({
return object; return object;
}, },
{}), {}),
{ error : function(model, error) { { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
}, },
addNewGrade: function(e) { addNewGrade: function(e) {
...@@ -695,10 +677,7 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({ ...@@ -695,10 +677,7 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({
}, },
deleteModel : function(e) { deleteModel : function(e) {
this.model.destroy( this.model.destroy(
{ error : function(model, error) { { error : CMS.ServerError});
// this handler is for the client:server communication not the vlidation errors which handleValidationError catches
window.alert("Error during save: " + error.responseText);
}});
e.preventDefault(); e.preventDefault();
} }
......
...@@ -10,6 +10,7 @@ ...@@ -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/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/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/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')}" /> <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/jquery.timepicker.js')}"></script>
<script src="${static.url('js/vendor/timepicker/datepair.js')}"></script> <script src="${static.url('js/vendor/timepicker/datepair.js')}"></script>
......
...@@ -20,6 +20,7 @@ from contentstore import utils ...@@ -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_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/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/settings/main_settings_view.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/server_error.js')}"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(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