From 7cbda99b0d2f05555bbaa0c4744ced97a2afb1d5 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Sat, 4 Jan 2014 13:25:54 -0700 Subject: [PATCH] Add widget view options in creating child views --- .../html/static/notebook/js/widgetmanager.js | 30 ++++++++++++++++++- .../html/static/notebook/js/widgets/base.js | 11 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/notebook/js/widgetmanager.js b/IPython/html/static/notebook/js/widgetmanager.js index 8a9314276..16c7dc209 100644 --- a/IPython/html/static/notebook/js/widgetmanager.js +++ b/IPython/html/static/notebook/js/widgetmanager.js @@ -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 diff --git a/IPython/html/static/notebook/js/widgets/base.js b/IPython/html/static/notebook/js/widgets/base.js index 9e013e439..a776caa92 100644 --- a/IPython/html/static/notebook/js/widgets/base.js +++ b/IPython/html/static/notebook/js/widgets/base.js @@ -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; },