mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-13 13:17:50 +08:00
Add widget view options in creating child views
This commit is contained in:
parent
7c3b21d239
commit
7cbda99b0d
@ -90,14 +90,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
WidgetManager.prototype.create_view = function(model, view_name, cell) {
|
||||
view_name = view_name || model.get('default_view_name');
|
||||
=======
|
||||
WidgetManager.prototype.create_view = function(model, view_name, cell, options) {
|
||||
view_name = view_name || model.get('default_view_name');
|
||||
>>>>>>> Add widget view options in creating child views
|
||||
var ViewType = this.widget_view_types[view_name];
|
||||
if (ViewType !== undefined && ViewType !== null) {
|
||||
var view = new ViewType({model: model, widget_manager: this, cell: cell});
|
||||
var view = new ViewType({model: model, widget_manager: this, cell: cell, options: options});
|
||||
view.render();
|
||||
model.views.push(view);
|
||||
model.on('destroy', view.remove, view);
|
||||
<<<<<<< HEAD
|
||||
/*
|
||||
// TODO: handle view deletion. Don't forget to delete child views
|
||||
var that = this;
|
||||
@ -105,6 +111,28 @@
|
||||
var index = that.views.indexOf(view);
|
||||
if (index > -1) {
|
||||
that.views.splice(index, 1);
|
||||
=======
|
||||
/*
|
||||
// TODO: handle view deletion. Don't forget to delete child views
|
||||
var that = this;
|
||||
view.$el.on("remove", function () {
|
||||
var index = that.views.indexOf(view);
|
||||
if (index > -1) {
|
||||
that.views.splice(index, 1);
|
||||
}
|
||||
view.remove(); // Clean-up view
|
||||
|
||||
// Close the comm if there are no views left.
|
||||
if (that.views.length() === 0) {
|
||||
//trigger comm close event?
|
||||
}
|
||||
|
||||
|
||||
if (that.comm !== undefined) {
|
||||
that.comm.close();
|
||||
delete that.comm.model; // Delete ref so GC will collect widget model.
|
||||
delete that.comm;
|
||||
>>>>>>> Add widget view options in creating child views
|
||||
}
|
||||
view.remove(); // Clean-up view
|
||||
|
||||
|
@ -173,7 +173,9 @@ function(widget_manager, underscore, backbone){
|
||||
this.widget_manager = options.widget_manager;
|
||||
this.comm_manager = options.widget_manager.comm_manager;
|
||||
this.cell = options.cell;
|
||||
this.options = options.options;
|
||||
this.child_views = [];
|
||||
this.model.views.push(this);
|
||||
},
|
||||
|
||||
update: function(){
|
||||
@ -181,12 +183,21 @@ function(widget_manager, underscore, backbone){
|
||||
// triggered on model change
|
||||
},
|
||||
|
||||
<<<<<<< HEAD
|
||||
child_view: function(model_id, view_name) {
|
||||
// create and return a child view, given a comm id for a model and (optionally) a view name
|
||||
// if the view name is not given, it defaults to the model's default view attribute
|
||||
var child_model = this.widget_manager.get_model(model_id);
|
||||
var child_view = this.widget_manager.create_view(child_model, view_name, this.cell);
|
||||
this.child_views[model_id] = child_view;
|
||||
=======
|
||||
child_view: function(comm_id, view_name, options) {
|
||||
// create and return a child view, given a comm id for a model and (optionally) a view name
|
||||
// if the view name is not given, it defaults to the model's default view attribute
|
||||
var child_model = this.comm_manager.comms[comm_id].model;
|
||||
var child_view = this.widget_manager.create_view(child_model, view_name, this.cell, options);
|
||||
this.child_views[comm_id] = child_view;
|
||||
>>>>>>> Add widget view options in creating child views
|
||||
return child_view;
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user