Commit fd67c387 by Adam Palay

keep track of number of components in a vertical

parent 649f3ccd
...@@ -15,25 +15,30 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview', 'common/js/compo ...@@ -15,25 +15,30 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview', 'common/js/compo
initialize: function(options) { initialize: function(options) {
BaseView.prototype.initialize.call(this, options); BaseView.prototype.initialize.call(this, options);
that = this;
this.template = this.loadTemplate('add-xblock-component'); this.template = this.loadTemplate('add-xblock-component');
this.model.set({number_children: $('.level-element').length});
// this.model.on('change:number_children', function(model){
// console.log('number of children changed!');
// console.log(model.get('number_children'));
// }, this.model);
this.model.on('change:number_children', this.render, this);
}, },
render: function() { render: function() {
if (!this.$el.html()) { var that = this;
var that = this; this.$el.html(this.template({numberChildren: that.model.get('number_children')}));
this.$el.html(this.template({})); this.collection.each(
this.collection.each( function(componentModel) {
function(componentModel) { var view, menu;
var view, menu;
view = new AddXBlockButton({model: componentModel}); view = new AddXBlockButton({model: componentModel});
that.$el.find('.new-component-type').append(view.render().el); that.$el.find('.new-component-type').append(view.render().el);
menu = new AddXBlockMenu({model: componentModel}); menu = new AddXBlockMenu({model: componentModel});
that.$el.append(menu.render().el); that.$el.append(menu.render().el);
} }
); );
}
}, },
showComponentTemplates: function(event) { showComponentTemplates: function(event) {
...@@ -65,7 +70,9 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview', 'common/js/compo ...@@ -65,7 +70,9 @@ define(['jquery', 'underscore', 'gettext', 'js/views/baseview', 'common/js/compo
ViewUtils.runOperationShowingMessage( ViewUtils.runOperationShowingMessage(
gettext('Adding'), gettext('Adding'),
_.bind(this.options.createComponent, this, saveData, element) _.bind(this.options.createComponent, this, saveData, element)
).always(function() { ).success(function(){
self.model.set({number_children: self.model.get('number_children') + 1});
}).always(function() {
// Restore the scroll position of the buttons so that the new // Restore the scroll position of the buttons so that the new
// component appears above them. // component appears above them.
ViewUtils.setScrollOffset(self.$el, oldOffset); ViewUtils.setScrollOffset(self.$el, oldOffset);
......
...@@ -170,7 +170,8 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page ...@@ -170,7 +170,8 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page
var component = new AddXBlockComponent({ var component = new AddXBlockComponent({
el: element, el: element,
createComponent: _.bind(self.createComponent, self), createComponent: _.bind(self.createComponent, self),
collection: self.options.templates collection: self.options.templates,
model: self.model
}); });
component.render(); component.render();
}); });
...@@ -288,13 +289,16 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page ...@@ -288,13 +289,16 @@ define(['jquery', 'underscore', 'backbone', 'gettext', 'js/views/pages/base_page
onDelete: function(xblockElement) { onDelete: function(xblockElement) {
// get the parent so we can remove this component from its parent. // get the parent so we can remove this component from its parent.
var xblockView = this.xblockView, var xblockView = this.xblockView,
parent = this.findXBlockElement(xblockElement.parent()); parent = this.findXBlockElement(xblockElement.parent()),
model = this.model;
xblockElement.remove(); xblockElement.remove();
// Inform the runtime that the child has been deleted in case // Inform the runtime that the child has been deleted in case
// other views are listening to deletion events. // other views are listening to deletion events.
xblockView.acknowledgeXBlockDeletion(parent.data('locator')); xblockView.acknowledgeXBlockDeletion(parent.data('locator'));
model.set({number_children: model.get('number_children') - 1});
// Update publish and last modified information from the server. // Update publish and last modified information from the server.
this.model.fetch(); this.model.fetch();
}, },
......
<div class="new-component">
<h5>This is the nudge</h5>
<p>There are <%= numberChildren %> components in this vertical</p>
<ul class="new-component-type">
</ul>
</div>
<div class="new-component"> <div class="new-component">
<h5><%= gettext("Add New Component") %></h5> <h5><%= gettext("Add New Component") %></h5>
<p>There are <%= numberChildren %> components in this unit!</p>
<ul class="new-component-type"> <ul class="new-component-type">
</ul> </ul>
</div> </div>
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