##// END OF EJS Templates
Added support for multiple model views in one widget area.
Jonathan Frederic -
Show More
@@ -56,11 +56,14 define(["../../components/underscore/underscore-min.js",
56 56 this.save(this.changedAttributes(), {patch: true});
57 57
58 58 for (var cell_index in this.views) {
59 var view = this.views[cell_index];
59 var views = this.views[cell_index];
60 for (var view_index in views) {
61 var view = views[view_index];
60 62 if (view !== caller) {
61 63 view.update();
62 64 }
63 65 }
66 }
64 67 },
65 68
66 69
@@ -177,9 +180,12 define(["../../components/underscore/underscore-min.js",
177 180 // Handle when a widget is closed.
178 181 handle_comm_closed: function (msg) {
179 182 for (var cell_index in this.views) {
180 var view = this.views[cell_index];
183 var views = this.views[cell_index];
184 for (var view_index in views) {
185 var view = views[view_index];
181 186 view.remove();
182 187 }
188 }
183 189 },
184 190
185 191
@@ -187,17 +193,23 define(["../../components/underscore/underscore-min.js",
187 193 display_view: function (view_name, parent_comm_id, cell_index) {
188 194 var view = new this.widget_view_types[view_name]({model: this});
189 195 view.render();
190 this.views[cell_index] = view;
196 if (this.views[cell_index]==undefined) {
197 this.views[cell_index] = []
198 }
199 this.views[cell_index].push(view);
191 200 view.cell_index = cell_index;
192 201
193 202 // Handle when the view element is remove from the page.
194 203 var that = this;
195 204 view.$el.on("remove", function(){
196 var index = that.views.indexOf(view);
205 var index = that.views[cell_index].indexOf(view);
197 206 if (index > -1) {
198 that.views.splice(index, 1);
207 that.views[cell_index].splice(index, 1);
199 208 }
200 209 view.remove(); // Clean-up view
210 if (that.views[cell_index].length()==0) {
211 delete that.views[cell_index];
212 }
201 213
202 214 // Close the comm if there are no views left.
203 215 if (that.views.length()==0) {
General Comments 0
You need to be logged in to leave comments. Login now