Show More
@@ -186,9 +186,30 function(widget_manager, underscore, backbone){ | |||||
186 | // if the view name is not given, it defaults to the model's default view attribute |
|
186 | // if the view name is not given, it defaults to the model's default view attribute | |
187 | var child_model = this.comm_manager.comms[comm_id].model; |
|
187 | var child_model = this.comm_manager.comms[comm_id].model; | |
188 | var child_view = this.widget_manager.create_view(child_model, view_name, this.cell); |
|
188 | var child_view = this.widget_manager.create_view(child_model, view_name, this.cell); | |
189 |
this.child_views |
|
189 | this.child_views[comm_id] = child_view; | |
190 | return child_view; |
|
190 | return child_view; | |
191 | }, |
|
191 | }, | |
|
192 | ||||
|
193 | update_child_views: function(old_list, new_list) { | |||
|
194 | // this function takes an old list and new list of comm ids | |||
|
195 | // views in child_views that correspond to deleted ids are deleted | |||
|
196 | // views corresponding to added ids are added child_views | |||
|
197 | ||||
|
198 | // delete old views | |||
|
199 | _.each(_.difference(old_list, new_list), function(element, index, list) { | |||
|
200 | var view = this.child_views[element]; | |||
|
201 | delete this.child_views[element]; | |||
|
202 | view.remove(); | |||
|
203 | }, this); | |||
|
204 | ||||
|
205 | // add new views | |||
|
206 | _.each(_.difference(new_list, old_list), function(element, index, list) { | |||
|
207 | // this function adds the view to the child_views dictionary | |||
|
208 | this.child_view(element); | |||
|
209 | }, this); | |||
|
210 | }, | |||
|
211 | ||||
|
212 | ||||
192 |
|
213 | |||
193 | render: function(){ |
|
214 | render: function(){ | |
194 | // render the view. By default, this is only called the first time the view is created |
|
215 | // render the view. By default, this is only called the first time the view is created |
@@ -52,12 +52,20 define(["notebook/js/widgets/base"], function(widget_manager) { | |||||
52 | render: function(){ |
|
52 | render: function(){ | |
53 | this.$el |
|
53 | this.$el | |
54 | .addClass('widget-container'); |
|
54 | .addClass('widget-container'); | |
55 | var children = this.model.get('children'); |
|
55 | this.children={}; | |
56 | for(var i in children) { |
|
56 | this.update_children([], this.model.get('children')); | |
57 | var view = this.child_view(children[i]); |
|
57 | this.model.on('change:children', function(model, value, options) { | |
58 | this.$el.append(view.$el); |
|
58 | this.update_children(model.previous('children'), value); | |
59 | } |
|
59 | }, this); | |
60 |
|
|
60 | this.update() | |
|
61 | }, | |||
|
62 | ||||
|
63 | update_children: function(old_list, new_list) { | |||
|
64 | this.$el.empty(); | |||
|
65 | this.update_child_views(old_list, new_list); | |||
|
66 | _.each(new_list, function(element, index, list) { | |||
|
67 | this.$el.append(this.child_views[element].$el); | |||
|
68 | }, this) | |||
61 | }, |
|
69 | }, | |
62 |
|
70 | |||
63 | update: function(){ |
|
71 | update: function(){ |
@@ -26,11 +26,24 define(["notebook/js/widgets/base"], function(widget_manager){ | |||||
26 | .attr('id', guid) |
|
26 | .attr('id', guid) | |
27 | .addClass('accordion'); |
|
27 | .addClass('accordion'); | |
28 | this.containers = []; |
|
28 | this.containers = []; | |
29 | for (var i in children) { |
|
29 | this.update_children([], this.model.get('children')); | |
30 | this.add_child_view(this.child_view(children[i])) |
|
30 | this.model.on('change:children', function(model, value, options) { | |
31 | } |
|
31 | this.update_children(model.previous('children'), value); | |
32 |
|
32 | }, this); | ||
33 | }, |
|
33 | }, | |
|
34 | ||||
|
35 | update_children: function(old_list, new_list) { | |||
|
36 | _.each(this.containers, function(element, index, list) { | |||
|
37 | element.remove(); | |||
|
38 | }, this); | |||
|
39 | this.containers = []; | |||
|
40 | this.update_child_views(old_list, new_list); | |||
|
41 | _.each(new_list, function(element, index, list) { | |||
|
42 | this.add_child_view(this.child_views[element]); | |||
|
43 | }, this) | |||
|
44 | }, | |||
|
45 | ||||
|
46 | ||||
34 | update: function() { |
|
47 | update: function() { | |
35 | // Set tab titles |
|
48 | // Set tab titles | |
36 | var titles = this.model.get('_titles'); |
|
49 | var titles = this.model.get('_titles'); |
General Comments 0
You need to be logged in to leave comments.
Login now