Commit 79b3af87 by David Baumgold

tabs to spaces

parent 1b4f9c66
CMS.Models.AssignmentGrade = Backbone.Model.extend({ CMS.Models.AssignmentGrade = Backbone.Model.extend({
defaults : { defaults : {
graderType : null, // the type label (string). May be "Not Graded" which implies None. I'd like to use id but that's ephemeral graderType : 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 location : null // A location object
}, },
initialize : function(attrs) { initialize : function(attrs) {
if (attrs['assignmentUrl']) { if (attrs['assignmentUrl']) {
this.set('location', new CMS.Models.Location(attrs['assignmentUrl'], {parse: true})); this.set('location', new CMS.Models.Location(attrs['assignmentUrl'], {parse: true}));
} }
}, },
parse : function(attrs) { parse : function(attrs) {
if (attrs && attrs['location']) { if (attrs && attrs['location']) {
attrs.location = new CMS.Models.Location(attrs['location'], {parse: true}); attrs.location = new CMS.Models.Location(attrs['location'], {parse: true});
} }
}, },
urlRoot : function() { urlRoot : function() {
if (this.has('location')) { if (this.has('location')) {
var location = this.get('location'); var location = this.get('location');
return '/' + location.get('org') + "/" + location.get('course') + '/' + location.get('category') + '/' return '/' + location.get('org') + "/" + location.get('course') + '/' + location.get('category') + '/'
+ location.get('name') + '/gradeas/'; + location.get('name') + '/gradeas/';
} }
else return ""; else return "";
} }
}); });
CMS.Views.OverviewAssignmentGrader = Backbone.View.extend({ CMS.Views.OverviewAssignmentGrader = Backbone.View.extend({
// instantiate w/ { graders : CourseGraderCollection, el : <the gradable-status div> } // instantiate w/ { graders : CourseGraderCollection, el : <the gradable-status div> }
events : { events : {
"click .menu-toggle" : "showGradeMenu", "click .menu-toggle" : "showGradeMenu",
"click .menu li" : "selectGradeType" "click .menu li" : "selectGradeType"
}, },
initialize : function() { initialize : function() {
// call template w/ {assignmentType : formatname, graders : CourseGraderCollection instance } // call template w/ {assignmentType : formatname, graders : CourseGraderCollection instance }
this.template = _.template( this.template = _.template(
// TODO move to a template file // TODO move to a template file
'<h4 class="status-label"><%= assignmentType %></h4>' + '<h4 class="status-label"><%= assignmentType %></h4>' +
'<a data-tooltip="Mark/unmark this subsection as graded" class="menu-toggle" href="#">' + '<a data-tooltip="Mark/unmark this subsection as graded" class="menu-toggle" href="#">' +
'<% if (!hideSymbol) {%><i class="icon-ok"></i><%};%>' + '<% if (!hideSymbol) {%><i class="icon-ok"></i><%};%>' +
'</a>' + '</a>' +
'<ul class="menu">' + '<ul class="menu">' +
'<% graders.each(function(option) { %>' + '<% graders.each(function(option) { %>' +
'<li><a <% if (option.get("type") == assignmentType) {%>class="is-selected" <%}%> href="#"><%= option.get("type") %></a></li>' + '<li><a <% if (option.get("type") == assignmentType) {%>class="is-selected" <%}%> href="#"><%= option.get("type") %></a></li>' +
'<% }) %>' + '<% }) %>' +
'<li><a class="gradable-status-notgraded" href="#">Not Graded</a></li>' + '<li><a class="gradable-status-notgraded" href="#">Not Graded</a></li>' +
'</ul>'); '</ul>');
this.assignmentGrade = new CMS.Models.AssignmentGrade({ this.assignmentGrade = new CMS.Models.AssignmentGrade({
assignmentUrl : this.$el.closest('.id-holder').data('id'), assignmentUrl : this.$el.closest('.id-holder').data('id'),
graderType : this.$el.data('initial-status')}); graderType : this.$el.data('initial-status')});
// TODO throw exception if graders is null // TODO throw exception if graders is null
this.graders = this.options['graders']; this.graders = this.options['graders'];
var cachethis = this; var cachethis = this;
// defining here to get closure around this // defining here to get closure around this
this.removeMenu = function(e) { this.removeMenu = function(e) {
e.preventDefault(); e.preventDefault();
cachethis.$el.removeClass('is-active'); cachethis.$el.removeClass('is-active');
$(document).off('click', cachethis.removeMenu); $(document).off('click', cachethis.removeMenu);
} }
this.hideSymbol = this.options['hideSymbol']; this.hideSymbol = this.options['hideSymbol'];
this.render(); this.render();
}, },
render : function() { render : function() {
this.$el.html(this.template({ assignmentType : this.assignmentGrade.get('graderType'), graders : this.graders, this.$el.html(this.template({ assignmentType : this.assignmentGrade.get('graderType'), graders : this.graders,
hideSymbol : this.hideSymbol })); hideSymbol : this.hideSymbol }));
if (this.assignmentGrade.has('graderType') && this.assignmentGrade.get('graderType') != "Not Graded") { if (this.assignmentGrade.has('graderType') && this.assignmentGrade.get('graderType') != "Not Graded") {
this.$el.addClass('is-set'); this.$el.addClass('is-set');
} }
else { else {
this.$el.removeClass('is-set'); this.$el.removeClass('is-set');
} }
}, },
showGradeMenu : function(e) { showGradeMenu : function(e) {
e.preventDefault(); e.preventDefault();
// I sure hope this doesn't break anything but it's needed to keep the removeMenu from activating // I sure hope this doesn't break anything but it's needed to keep the removeMenu from activating
e.stopPropagation(); e.stopPropagation();
// nasty global event trap :-( // nasty global event trap :-(
$(document).on('click', this.removeMenu); $(document).on('click', this.removeMenu);
this.$el.addClass('is-active'); this.$el.addClass('is-active');
}, },
selectGradeType : function(e) { selectGradeType : function(e) {
e.preventDefault(); e.preventDefault();
this.removeMenu(e); this.removeMenu(e);
var saving = new CMS.Views.Notification.Mini({ var saving = new CMS.Views.Notification.Mini({
title: gettext('Saving') + '&hellip;' title: gettext('Saving') + '&hellip;'
}); });
saving.show(); saving.show();
// 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 // 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) // of the CourseGradingPolicy model or null for Not Graded (NOTE, change template's if check for is-selected accordingly)
this.assignmentGrade.save( this.assignmentGrade.save(
'graderType', 'graderType',
$(e.target).text(), $(e.target).text(),
{success: function () { saving.hide(); }} {success: function () { saving.hide(); }}
); );
this.render(); this.render();
} }
}) })
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