Commit d0eefc6a by Christina Roberts

Merge pull request #1580 from MITx/bug/dhm/course_update_js

Fix for script tags w/in json objects being oddly evaluated on html page
parents df5ad6ba 020e1e94
...@@ -1109,6 +1109,7 @@ def module_info(request, module_location): ...@@ -1109,6 +1109,7 @@ def module_info(request, module_location):
else: else:
return HttpResponseBadRequest() return HttpResponseBadRequest()
@login_required @login_required
@ensure_csrf_cookie @ensure_csrf_cookie
def get_course_settings(request, org, course, name): def get_course_settings(request, org, course, name):
...@@ -1124,12 +1125,15 @@ def get_course_settings(request, org, course, name): ...@@ -1124,12 +1125,15 @@ def get_course_settings(request, org, course, name):
raise PermissionDenied() raise PermissionDenied()
course_module = modulestore().get_item(location) course_module = modulestore().get_item(location)
course_details = CourseDetails.fetch(location)
return render_to_response('settings.html', { return render_to_response('settings.html', {
'context_course': course_module, 'context_course': course_module,
'course_location' : location, 'course_location': location,
'course_details' : json.dumps(course_details, cls=CourseSettingsEncoder) 'details_url': reverse(course_settings_updates,
kwargs={"org": org,
"course": course,
"name": name,
"section": "details"})
}) })
@login_required @login_required
......
...@@ -59,11 +59,6 @@ CMS.Models.Settings.CourseDetails = Backbone.Model.extend({ ...@@ -59,11 +59,6 @@ CMS.Models.Settings.CourseDetails = Backbone.Model.extend({
// NOTE don't return empty errors as that will be interpreted as an error state // NOTE don't return empty errors as that will be interpreted as an error state
}, },
url: function() {
var location = this.get('location');
return '/' + location.get('org') + "/" + location.get('course') + '/settings-details/' + location.get('name') + '/section/details';
},
_videokey_illegal_chars : /[^a-zA-Z0-9_-]/g, _videokey_illegal_chars : /[^a-zA-Z0-9_-]/g,
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
......
if (!CMS.Models['Settings']) CMS.Models.Settings = new Object();
CMS.Models.Settings.CourseSettings = Backbone.Model.extend({
// a container for the models representing the n possible tabbed states
defaults: {
courseLocation: null,
details: null,
faculty: null,
grading: null,
problems: null,
discussions: null
},
retrieve: function(submodel, callback) {
if (this.get(submodel)) callback();
else {
var cachethis = this;
switch (submodel) {
case 'details':
var details = new CMS.Models.Settings.CourseDetails({location: this.get('courseLocation')});
details.fetch( {
success : function(model) {
cachethis.set('details', model);
callback(model);
}
});
break;
case 'grading':
var grading = new CMS.Models.Settings.CourseGradingPolicy({course_location: this.get('courseLocation')});
grading.fetch( {
success : function(model) {
cachethis.set('grading', model);
callback(model);
}
});
break;
default:
break;
}
}
}
})
\ No newline at end of file
...@@ -44,6 +44,8 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -44,6 +44,8 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
self.render(); self.render();
} }
); );
// when the client refetches the updates as a whole, re-render them
this.listenTo(this.collection, 'reset', this.render);
}, },
render: function () { render: function () {
...@@ -53,8 +55,12 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -53,8 +55,12 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
$(updateEle).empty(); $(updateEle).empty();
var self = this; var self = this;
this.collection.each(function (update) { this.collection.each(function (update) {
var newEle = self.template({ updateModel : update }); try {
$(updateEle).append(newEle); var newEle = self.template({ updateModel : update });
$(updateEle).append(newEle);
} catch (e) {
// ignore
}
}); });
this.$el.find(".new-update-form").hide(); this.$el.find(".new-update-form").hide();
this.$el.find('.date').datepicker({ 'dateFormat': 'MM d, yy' }); this.$el.find('.date').datepicker({ 'dateFormat': 'MM d, yy' });
...@@ -150,7 +156,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -150,7 +156,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
}, },
closeEditor: function(self, removePost) { closeEditor: function(self, removePost) {
var targetModel = self.collection.getByCid(self.$currentPost.attr('name')); var targetModel = self.collection.get(self.$currentPost.attr('name'));
if(removePost) { if(removePost) {
self.$currentPost.remove(); self.$currentPost.remove();
...@@ -160,8 +166,13 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -160,8 +166,13 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
self.$currentPost.removeClass('editing'); self.$currentPost.removeClass('editing');
self.$currentPost.find('.date-display').html(targetModel.get('date')); self.$currentPost.find('.date-display').html(targetModel.get('date'));
self.$currentPost.find('.date').val(targetModel.get('date')); self.$currentPost.find('.date').val(targetModel.get('date'));
self.$currentPost.find('.update-contents').html(targetModel.get('content')); try {
self.$currentPost.find('.new-update-content').val(targetModel.get('content')); // just in case the content causes an error (embedded js errors)
self.$currentPost.find('.update-contents').html(targetModel.get('content'));
self.$currentPost.find('.new-update-content').val(targetModel.get('content'));
} catch (e) {
// ignore but handle rest of page
}
self.$currentPost.find('form').hide(); self.$currentPost.find('form').hide();
window.$modalCover.unbind('click'); window.$modalCover.unbind('click');
window.$modalCover.hide(); window.$modalCover.hide();
...@@ -172,7 +183,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -172,7 +183,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
// Dereferencing from events to screen elements // Dereferencing from events to screen elements
eventModel: function(event) { eventModel: function(event) {
// not sure if it should be currentTarget or delegateTarget // not sure if it should be currentTarget or delegateTarget
return this.collection.getByCid($(event.currentTarget).attr("name")); return this.collection.get($(event.currentTarget).attr("name"));
}, },
modelDom: function(event) { modelDom: function(event) {
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
$(document).ready(function(){ $(document).ready(function(){
var course_updates = new CMS.Models.CourseUpdateCollection(); var course_updates = new CMS.Models.CourseUpdateCollection();
course_updates.reset(${course_updates|n});
course_updates.urlbase = '${url_base}'; course_updates.urlbase = '${url_base}';
course_updates.fetch();
var course_handouts = new CMS.Models.ModuleInfo({ var course_handouts = new CMS.Models.ModuleInfo({
id: '${handouts_location}' id: '${handouts_location}'
......
...@@ -30,13 +30,18 @@ from contentstore import utils ...@@ -30,13 +30,18 @@ from contentstore import utils
}).blur(function() { }).blur(function() {
$("label").removeClass("is-focused"); $("label").removeClass("is-focused");
}); });
var model = new CMS.Models.Settings.CourseDetails();
var editor = new CMS.Views.Settings.Details({ model.urlRoot = '${details_url}';
el: $('.settings-details'), model.fetch({success :
model: new CMS.Models.Settings.CourseDetails(${course_details|n},{parse:true}) function(model) {
}); var editor = new CMS.Views.Settings.Details({
el: $('.settings-details'),
editor.render(); model: model
});
editor.render();
}
});
}); });
</script> </script>
......
...@@ -127,6 +127,7 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -127,6 +127,7 @@ class CourseDescriptor(SequenceDescriptor):
# NOTE (THK): This is a last-minute addition for Fall 2012 launch to dynamically # NOTE (THK): This is a last-minute addition for Fall 2012 launch to dynamically
# disable the syllabus content for courses that do not provide a syllabus # disable the syllabus content for courses that do not provide a syllabus
self.syllabus_present = self.system.resources_fs.exists(path('syllabus')) self.syllabus_present = self.system.resources_fs.exists(path('syllabus'))
self._grading_policy = {}
self.set_grading_policy(self.definition['data'].get('grading_policy', None)) self.set_grading_policy(self.definition['data'].get('grading_policy', None))
self.test_center_exams = [] self.test_center_exams = []
...@@ -196,11 +197,9 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -196,11 +197,9 @@ class CourseDescriptor(SequenceDescriptor):
grading_policy.update(course_policy) grading_policy.update(course_policy)
# Here is where we should parse any configurations, so that we can fail early # Here is where we should parse any configurations, so that we can fail early
grading_policy['RAW_GRADER'] = grading_policy['GRADER'] # used for cms access # Use setters so that side effecting to .definitions works
grading_policy['GRADER'] = grader_from_conf(grading_policy['GRADER']) self.raw_grader = grading_policy['GRADER'] # used for cms access
self._grading_policy = grading_policy self.grade_cutoffs = grading_policy['GRADE_CUTOFFS']
@classmethod @classmethod
def read_grading_policy(cls, paths, system): def read_grading_policy(cls, paths, system):
...@@ -318,10 +317,6 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -318,10 +317,6 @@ class CourseDescriptor(SequenceDescriptor):
self.metadata['enrollment_end'] = stringify_time(value) self.metadata['enrollment_end'] = stringify_time(value)
@property @property
def grader(self):
return self._grading_policy['GRADER']
@property
def raw_grader(self): def raw_grader(self):
return self._grading_policy['RAW_GRADER'] return self._grading_policy['RAW_GRADER']
......
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