diff --git a/IPython/html/static/widgets/js/manager.js b/IPython/html/static/widgets/js/manager.js index 1b4558e..e9a25a4 100644 --- a/IPython/html/static/widgets/js/manager.js +++ b/IPython/html/static/widgets/js/manager.js @@ -95,6 +95,11 @@ define([ WidgetManager.prototype.create_view = function(model, options, view) { // Creates a view for a particular model. + + var view_name = model.get('_view_name'); + var view_mod = model.get('_view_module'); + errback = options.errback || function(err) {console.log(err)}; + var instantiate_view = function(ViewType) { if (ViewType) { // If a view is passed into the method, use that view's cell as @@ -110,15 +115,16 @@ define([ view.render(); model.on('destroy', view.remove, view); options.callback(view); + } else { + errback({unknown_view: true, view_name: view_name, + view_module: view_mod}) } } - - var view_name = model.get('_view_name'); - var view_mod = model.get('_view_module'); + if (view_mod) { require([view_mod], function(module) { instantiate_view(module[view_name]) - }); + }, errback); } else { instantiate_view(WidgetManager._view_types[view_name]); } diff --git a/IPython/html/static/widgets/js/widget.js b/IPython/html/static/widgets/js/widget.js index 4fa8776..81dcf2c 100644 --- a/IPython/html/static/widgets/js/widget.js +++ b/IPython/html/static/widgets/js/widget.js @@ -308,7 +308,7 @@ define(["widgets/js/manager", // Update view to be consistent with this.model }, - create_child_view: function(child_model, callback, options) { + create_child_view: function(child_model, options) { // Create and return a child view. // // -given a model and (optionally) a view name if the view name is @@ -318,6 +318,7 @@ define(["widgets/js/manager", // it would be great to have the widget manager add the cell metadata // to the subview without having to add it here. var that = this; + var old_callback = options.callback || function(view) {}; options = $.extend({ parent: this, callback: function(child_view) { // Associate the view id with the model id. if (that.child_model_views[child_model.id] === undefined) { @@ -327,7 +328,7 @@ define(["widgets/js/manager", // Remember the view by id. that.child_views[child_view.id] = child_view; - callback(child_view); + old_callback(child_view); }}, options || {}); this.model.widget_manager.create_view(child_model, options, this); diff --git a/IPython/html/static/widgets/js/widget_box.js b/IPython/html/static/widgets/js/widget_box.js index 39e4612..1d2edcb 100644 --- a/IPython/html/static/widgets/js/widget_box.js +++ b/IPython/html/static/widgets/js/widget_box.js @@ -75,14 +75,14 @@ define([ add_child_model: function(model) { // Called when a model is added to the children list. var that = this; - this.create_child_view(model, function(view) { + this.create_child_view(model, {callback: function(view) { that.$box.append(view.$el); // Trigger the displayed event of the child view. that.after_displayed(function() { view.trigger('displayed'); }); - }); + }}); }, }); diff --git a/IPython/html/static/widgets/js/widget_selectioncontainer.js b/IPython/html/static/widgets/js/widget_selectioncontainer.js index 98c6825..40b6e43 100644 --- a/IPython/html/static/widgets/js/widget_selectioncontainer.js +++ b/IPython/html/static/widgets/js/widget_selectioncontainer.js @@ -114,7 +114,7 @@ define([ accordion_group.container_index = container_index; this.model_containers[model.id] = accordion_group; - this.create_child_view(model, function(view) { + this.create_child_view(model, {callback: function(view) { accordion_inner.append(view.$el); that.update(); @@ -124,7 +124,7 @@ define([ that.after_displayed(function() { view.trigger('displayed'); }); - }); + }}); }, }); @@ -186,7 +186,7 @@ define([ .css('list-style-type', 'none') .appendTo(this.$tabs); - this.create_child_view(model, function(view) { + this.create_child_view(model, {callback: function(view) { view.parent_tab = tab; var tab_text = $('') @@ -215,7 +215,7 @@ define([ that.after_displayed(function() { view.trigger('displayed'); }); - }); + }}); }, update: function(options) {