Beginning test of details tab.

This commit is contained in:
Don Mitchell
2012-11-21 15:17:18 -05:00
parent f8ee5c2614
commit f0c94a2c7e
7 changed files with 229 additions and 31 deletions

View File

@@ -1,8 +1,8 @@
CMS.Models.Settings.CourseDetails = Backbone.Models.extend({
defaults: {
location : null, # a Location model, required
start_date: null, # maps to 'start'
end_date: null, # maps to 'end'
location : null, // the course's Location model, required
start_date: null, // maps to 'start'
end_date: null, // maps to 'end'
enrollment_start: null,
enrollment_end: null,
syllabus: null,
@@ -19,6 +19,7 @@ CMS.Models.Settings.CourseDetails = Backbone.Models.extend({
},
urlRoot: function() {
// TODO impl
var location = this.get('location');
return '/' + location.get('org') + "/" + location.get('course') + '/settings/' + location.get('name') + '/section/details';
}
});

View File

@@ -3,7 +3,6 @@ CMS.Views.Settings.Main = Backbone.View.extend({
// allow navigation between the tabs
events: {
'click .settings-page-menu a': "showSettingsTab",
'blur input' : 'updateModel'
},
currentTab: null,
@@ -72,19 +71,50 @@ CMS.Views.Settings.Main = Backbone.View.extend({
CMS.Views.Settings.Details = Backbone.View.extend({
// Model class is CMS.Models.Settings.CourseDetails
events : {
"blur input" : "updateModel"
"blur input" : "updateModel",
'click .remove-course-syllabus' : "removeSyllabus",
'click .new-course-syllabus' : 'assetSyllabus',
'click .remove-course-introduction-video' : "removeVideo",
'click .new-course-introduction-video' : 'assetVideo',
},
initialize : function() {
// TODO move the html frag to a loaded asset
this.fileAnchorTemplate = _.template('<a href="<%= fullpath %>"> <i class="ss-icon ss-standard">&#x1F4C4;</i><%= filename %></a>');
// Save every change as it occurs. This may be too noisy!!! If not every change, then need sophisticated logic.
this.model.on('change', this.model.save);
},
render: function() {
if (this.model.has('start_date')) this.$el.find('#course-start-date').datepicker('setDate', this.model.get('start_date'));
if (this.model.has('end_date')) this.$el.find('#course-end-date').datepicker('setDate', this.model.get('end_date'));
if (this.model.has('enrollment_start')) this.$el.find('#course-enrollment-start').datepicker('setDate', this.model.get('enrollment_start'));
if (this.model.has('enrollment_end')) this.$el.find('#course-enrollment-end').datepicker('setDate', this.model.get('enrollment_end'));
if (this.model.has('syllabus')) {
this.$el.find('.current-course-syllabus .doc-filename').html(
this.fileAnchorTemplate({
fullpath : this.model.get('syllabus'),
filename: 'syllabus'}));
this.$el.find('.remove-course-syllabus').show();
}
else this.$el.find('.remove-course-syllabus').hide();
if (this.model.has('overview'))
this.$el.find('#course-overview').text(this.model.get('overview'));
if (this.model.has('intro_video')) {
this.$el.find('.current-course-introduction-video iframe').attr('src', this.model.get('intro_video'));
this.$el.find('.remove-course-introduction-video').show();
}
else this.$el.find('.remove-course-introduction-video').hide();
},
updateModel: function(event) {
// figure out which field
switch (event.currentTarget.id) {
case 'course-start-date':
this.model.set('start_date', $(event.currentTarget).datepicker('getDate'));
var val = $(event.currentTarget).datepicker('getDate');
this.model.set('start_date', val);
break;
case 'course-end-date':
this.model.set('end_date', $(event.currentTarget).datepicker('getDate'));
@@ -96,10 +126,28 @@ CMS.Views.Settings.Details = Backbone.View.extend({
this.model.set('enrollment_end', $(event.currentTarget).datepicker('getDate'));
break;
case 'course-overview':
this.model.set('overview', $(event.currentTarget).text());
break;
default:
break;
}
// save the updated model
this.model.save();
},
removeSyllabus: function() {
if (this.model.has('syllabus')) this.model.set({'syllabus': null});
},
assetSyllabus : function() {
// TODO implement
},
removeVideo: function() {
if (this.model.has('intro_video')) this.model.set({'intro_video': null});
},
assetVideo : function() {
// TODO implement
}
});