Added update_children pattern to remaining parent widgets

This commit is contained in:
Jonathan Frederic 2014-01-02 09:13:40 -08:00 committed by Jonathan Frederic
parent 2211abd28d
commit 8732761524
2 changed files with 36 additions and 11 deletions

View File

@ -81,6 +81,12 @@ define(["notebook/js/widgets/base"], function(widget_manager) {
render: function(){
var that = this;
this.children={};
this.update_children([], this.model.get('children'));
this.model.on('change:children', function(model, value, options) {
this.update_children(model.previous('children'), value);
}, this);
this.$el
.html('')
.on("remove", function(){
@ -210,6 +216,14 @@ define(["notebook/js/widgets/base"], function(widget_manager) {
this.$window.css('z-index', max_zindex);
},
update_children: function(old_list, new_list) {
this.$el.empty();
this.update_child_views(old_list, new_list);
_.each(new_list, function(element, index, list) {
this.$body.append(this.child_views[element].$el);
}, this)
},
update: function(){
set_flex_properties(this, this.$body);

View File

@ -28,8 +28,8 @@ define(["notebook/js/widgets/base"], function(widget_manager){
this.containers = [];
this.update_children([], this.model.get('children'));
this.model.on('change:children', function(model, value, options) {
this.update_children(model.previous('children'), value);
}, this);
this.update_children(model.previous('children'), value);
}, this);
},
update_children: function(old_list, new_list) {
@ -119,10 +119,10 @@ define(["notebook/js/widgets/base"], function(widget_manager){
var TabView = IPython.WidgetView.extend({
initialize: function() {
this.containers = [];
IPython.WidgetView.prototype.initialize.apply(this, arguments);
},
initialize: function() {
this.containers = [];
IPython.WidgetView.prototype.initialize.apply(this, arguments);
},
render: function(){
var uuid = 'tabs'+IPython.utils.uuid();
@ -134,11 +134,22 @@ define(["notebook/js/widgets/base"], function(widget_manager){
this.$tab_contents = $('<div />', {id: uuid + 'Content'})
.addClass('tab-content')
.appendTo(this.$el);
var children = this.model.get('children');
for (var i in children) {
this.add_child_view(this.child_view(children[i]))
}
this.update();
this.containers = [];
this.update_children([], this.model.get('children'));
this.model.on('change:children', function(model, value, options) {
this.update_children(model.previous('children'), value);
}, this);
},
update_children: function(old_list, new_list) {
_.each(this.containers, function(element, index, list) {
element.remove();
}, this);
this.containers = [];
this.update_child_views(old_list, new_list);
_.each(new_list, function(element, index, list) {
this.add_child_view(this.child_views[element]);
}, this)
},
update: function() {