diff --git a/cms/djangoapps/models/settings/course_grading.py b/cms/djangoapps/models/settings/course_grading.py index 1e856ce477..5a998bb044 100644 --- a/cms/djangoapps/models/settings/course_grading.py +++ b/cms/djangoapps/models/settings/course_grading.py @@ -204,23 +204,30 @@ class CourseGradingModel: @staticmethod def get_section_grader_type(location): - """ - - """ if not isinstance(location, Location): location = Location(location) - # TODO impl to return {grader-type, location, id (random)} + descriptor = get_modulestore(location).get_item(location) + return { + "grader-type" : descriptor.metadata.get('format', "Not Graded"), + "location" : location, + "id" : 99 # just an arbitrary value to + } @staticmethod def update_section_grader_type(location, jsondict): - """ - - """ if not isinstance(location, Location): location = Location(location) + + descriptor = get_modulestore(location).get_item(location) + if 'grader-type' in jsondict: + descriptor.metadata['format'] = jsondict.get('grader-type') + descriptor.metadata['graded'] = True + else: + del descriptor.metadata['format'] + descriptor.metadata['graded'] = False - # TODO impl to return {grader-type, location, id (random)} + get_modulestore(location).update_metadata(location, descriptor.metadata) @staticmethod diff --git a/cms/static/js/views/grader-select-view.js b/cms/static/js/views/grader-select-view.js new file mode 100644 index 0000000000..1107273cff --- /dev/null +++ b/cms/static/js/views/grader-select-view.js @@ -0,0 +1,73 @@ +CMS.Models.AssignmentGrade = Backbone.Model.extend({ + idAttribute : "cid", // not sure if this is kosher + defaults : { + grader-type : null, // the type label (string). May be "Not Graded" which implies None. I'd like to use id but that's ephemeral + location : null // A location object + }, + initialize : function(attrs) { + if (attrs['assignment-url']) { + this.set('location') = new CMS.Models.Location(attrs['assignment-url'], {parse: true}); + } + }, + parse : function(attrs) { + if (attrs['location']) { + attrs.location = new CMS.Models.Location(attrs['location'], {parse: true}); + } + } + urlRoot : function() { + if (this.has('location')) { + var location = this.get('location'); + return '/' + location.get('org') + "/" + location.get('course') + '/' + location.get('category') + '/' + + location.get('name') + '/gradeas/'; + } + else return ""; + } +}); + +CMS.Views.OverviewAssignmentGrader = Backbone.View.extend({ + // instantiate w/ { graders : CourseGraderCollection, el : } + events : { + "click .menu-toggle" : "showGradeMenu", + "click .menu" : "selectGradeType" + }, + initialize : function() { + // call template w/ {assignment-type : formatname, graders : CourseGraderCollection instance } + this.template = _.template( + '

<%= assignment-type %>

' + + '' + + '' + + '' + + ''); + this.assignmentGrade = new CMS.Models.AssignmentGrade({ + assignment-url : this.$el.closest('section.branch').data('id'), + grader-type : this.$el.data('initial-status')}); + this.render(); + }, + render : function() { + this.$el.html(this.template({ assignment-type : this.assignmentGrade.get('grader-type'), graders : this.graders })); + if (this.assignmentGrade.has('grader-type') && assignmentGrade.get('grader-type') != "Not Graded") { + this.$el.addClass('is-set'); + } + else { + this.$el.removeClass('is-set'); + } + }, + showGradeMenu : function(e) { + e.preventDefault(); + this.$el.toggleClass('is-active'); + }, + selectGradeType : function(e) { + e.preventDefault(); + + // TODO I'm not happy with this string fetch via the html for what should be an id. I'd rather use the id attr + // of the CourseGradingPolicy model or null for Not Graded (NOTE, change template's if check for is-selected accordingly) + this.assignmentGrade.save('grader-type', $(e.target).html()); + + this.render(); + } +}) \ No newline at end of file