Put callbacks for create_view and create_child_view in options

And add errback support
Thomas Kluyver 12 years ago
parent c4a9cf9020
commit 1ff846520b

@ -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]);
}

@ -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);

@ -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');
});
});
}});
},
});

@ -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 = $('<a />')
@ -215,7 +215,7 @@ define([
that.after_displayed(function() {
view.trigger('displayed');
});
});
}});
},
update: function(options) {

Loading…
Cancel
Save