Added support for multiple model views in one widget area.

This commit is contained in:
Jonathan Frederic 2013-10-25 09:58:51 -07:00
parent 0af18e8c13
commit c7ded710dc

View File

@ -56,11 +56,14 @@ define(["../../components/underscore/underscore-min.js",
this.save(this.changedAttributes(), {patch: true}); this.save(this.changedAttributes(), {patch: true});
for (var cell_index in this.views) { for (var cell_index in this.views) {
var view = this.views[cell_index]; var views = this.views[cell_index];
for (var view_index in views) {
var view = views[view_index];
if (view !== caller) { if (view !== caller) {
view.update(); view.update();
} }
} }
}
}, },
@ -177,9 +180,12 @@ define(["../../components/underscore/underscore-min.js",
// Handle when a widget is closed. // Handle when a widget is closed.
handle_comm_closed: function (msg) { handle_comm_closed: function (msg) {
for (var cell_index in this.views) { for (var cell_index in this.views) {
var view = this.views[cell_index]; var views = this.views[cell_index];
for (var view_index in views) {
var view = views[view_index];
view.remove(); view.remove();
} }
}
}, },
@ -187,17 +193,23 @@ define(["../../components/underscore/underscore-min.js",
display_view: function (view_name, parent_comm_id, cell_index) { display_view: function (view_name, parent_comm_id, cell_index) {
var view = new this.widget_view_types[view_name]({model: this}); var view = new this.widget_view_types[view_name]({model: this});
view.render(); view.render();
this.views[cell_index] = view; if (this.views[cell_index]==undefined) {
this.views[cell_index] = []
}
this.views[cell_index].push(view);
view.cell_index = cell_index; view.cell_index = cell_index;
// Handle when the view element is remove from the page. // Handle when the view element is remove from the page.
var that = this; var that = this;
view.$el.on("remove", function(){ view.$el.on("remove", function(){
var index = that.views.indexOf(view); var index = that.views[cell_index].indexOf(view);
if (index > -1) { if (index > -1) {
that.views.splice(index, 1); that.views[cell_index].splice(index, 1);
} }
view.remove(); // Clean-up view view.remove(); // Clean-up view
if (that.views[cell_index].length()==0) {
delete that.views[cell_index];
}
// Close the comm if there are no views left. // Close the comm if there are no views left.
if (that.views.length()==0) { if (that.views.length()==0) {