Commit f59f5d6b authored by Renfred Harper's avatar Renfred Harper

Fix collection view replication issue

parent 8d23cb30
......@@ -2,13 +2,14 @@ var advisor = advisor || {};
advisor.CourseCollectionView = Backbone.View.extend({
el: '#program3',
elements: [],
addOne: function(course) {
var view = new advisor.CourseView({ model: course });
console.log(this.$el);
this.$el.append(view.render().el);
// Fix bug where element render multiple times
var elm = view.render().el
if(!($('#' + elm.id).length))
this.$el.append(elm);
},
// Add all items in the **Todos** collection at once.
......
......@@ -14,7 +14,6 @@ advisor.ProgramCollectionView = Backbone.View.extend({
this.$el.append(el);
},
// Add all items in the **Todos** collection at once.
addAll: function() {
this.$el.html('');
advisor.Programs.each(this.addOne, this);
......
......@@ -8,25 +8,22 @@ advisor.ProgramView = Backbone.View.extend({
this.listenTo(this.model, 'change', this.render);
},
events: {
"click .panel-heading": "render_courses"
},
render: function() {
this.$el.attr('id', 'program' + this.model.get('id')).addClass('panel panel-primary program')
this.$el.attr('id', 'program-' + this.model.get('id')).addClass('panel panel-primary program')
.html(this.template(this.model.toJSON()));
this.render_courses();
return this;
},
render_courses: function() {
this.$('.panel-body').html('');
var that = this;
this.model.fetchRelated('requirements', {
success: function(requirements) {
that.model.get('requirements').forEach(function(requirement) {
requirement.fetchRelated('courses', {
success: function() {
var courseViews = new advisor.CourseCollectionView();
var courseViews = new advisor.CourseCollectionView({el: that.el});
courseViews.addAll(requirement.get('courses'));
}
})
......
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