Show More
@@ -95,6 +95,11 b' define([' | |||||
95 |
|
95 | |||
96 | WidgetManager.prototype.create_view = function(model, options, view) { |
|
96 | WidgetManager.prototype.create_view = function(model, options, view) { | |
97 | // Creates a view for a particular model. |
|
97 | // Creates a view for a particular model. | |
|
98 | ||||
|
99 | var view_name = model.get('_view_name'); | |||
|
100 | var view_mod = model.get('_view_module'); | |||
|
101 | errback = options.errback || function(err) {console.log(err)}; | |||
|
102 | ||||
98 | var instantiate_view = function(ViewType) { |
|
103 | var instantiate_view = function(ViewType) { | |
99 | if (ViewType) { |
|
104 | if (ViewType) { | |
100 | // If a view is passed into the method, use that view's cell as |
|
105 | // If a view is passed into the method, use that view's cell as | |
@@ -110,15 +115,16 b' define([' | |||||
110 | view.render(); |
|
115 | view.render(); | |
111 | model.on('destroy', view.remove, view); |
|
116 | model.on('destroy', view.remove, view); | |
112 | options.callback(view); |
|
117 | options.callback(view); | |
|
118 | } else { | |||
|
119 | errback({unknown_view: true, view_name: view_name, | |||
|
120 | view_module: view_mod}) | |||
113 | } |
|
121 | } | |
114 | } |
|
122 | } | |
115 |
|
123 | |||
116 | var view_name = model.get('_view_name'); |
|
|||
117 | var view_mod = model.get('_view_module'); |
|
|||
118 | if (view_mod) { |
|
124 | if (view_mod) { | |
119 | require([view_mod], function(module) { |
|
125 | require([view_mod], function(module) { | |
120 | instantiate_view(module[view_name]) |
|
126 | instantiate_view(module[view_name]) | |
121 | }); |
|
127 | }, errback); | |
122 | } else { |
|
128 | } else { | |
123 | instantiate_view(WidgetManager._view_types[view_name]); |
|
129 | instantiate_view(WidgetManager._view_types[view_name]); | |
124 | } |
|
130 | } |
@@ -308,7 +308,7 b' define(["widgets/js/manager",' | |||||
308 | // Update view to be consistent with this.model |
|
308 | // Update view to be consistent with this.model | |
309 | }, |
|
309 | }, | |
310 |
|
310 | |||
311 |
create_child_view: function(child_model, |
|
311 | create_child_view: function(child_model, options) { | |
312 | // Create and return a child view. |
|
312 | // Create and return a child view. | |
313 | // |
|
313 | // | |
314 | // -given a model and (optionally) a view name if the view name is |
|
314 | // -given a model and (optionally) a view name if the view name is | |
@@ -318,6 +318,7 b' define(["widgets/js/manager",' | |||||
318 | // it would be great to have the widget manager add the cell metadata |
|
318 | // it would be great to have the widget manager add the cell metadata | |
319 | // to the subview without having to add it here. |
|
319 | // to the subview without having to add it here. | |
320 | var that = this; |
|
320 | var that = this; | |
|
321 | var old_callback = options.callback || function(view) {}; | |||
321 | options = $.extend({ parent: this, callback: function(child_view) { |
|
322 | options = $.extend({ parent: this, callback: function(child_view) { | |
322 | // Associate the view id with the model id. |
|
323 | // Associate the view id with the model id. | |
323 | if (that.child_model_views[child_model.id] === undefined) { |
|
324 | if (that.child_model_views[child_model.id] === undefined) { | |
@@ -327,7 +328,7 b' define(["widgets/js/manager",' | |||||
327 |
|
328 | |||
328 | // Remember the view by id. |
|
329 | // Remember the view by id. | |
329 | that.child_views[child_view.id] = child_view; |
|
330 | that.child_views[child_view.id] = child_view; | |
330 | callback(child_view); |
|
331 | old_callback(child_view); | |
331 | }}, options || {}); |
|
332 | }}, options || {}); | |
332 |
|
333 | |||
333 | this.model.widget_manager.create_view(child_model, options, this); |
|
334 | this.model.widget_manager.create_view(child_model, options, this); |
@@ -75,14 +75,14 b' define([' | |||||
75 | add_child_model: function(model) { |
|
75 | add_child_model: function(model) { | |
76 | // Called when a model is added to the children list. |
|
76 | // Called when a model is added to the children list. | |
77 | var that = this; |
|
77 | var that = this; | |
78 | this.create_child_view(model, function(view) { |
|
78 | this.create_child_view(model, {callback: function(view) { | |
79 | that.$box.append(view.$el); |
|
79 | that.$box.append(view.$el); | |
80 |
|
80 | |||
81 | // Trigger the displayed event of the child view. |
|
81 | // Trigger the displayed event of the child view. | |
82 | that.after_displayed(function() { |
|
82 | that.after_displayed(function() { | |
83 | view.trigger('displayed'); |
|
83 | view.trigger('displayed'); | |
84 | }); |
|
84 | }); | |
85 | }); |
|
85 | }}); | |
86 | }, |
|
86 | }, | |
87 | }); |
|
87 | }); | |
88 |
|
88 |
@@ -114,7 +114,7 b' define([' | |||||
114 | accordion_group.container_index = container_index; |
|
114 | accordion_group.container_index = container_index; | |
115 | this.model_containers[model.id] = accordion_group; |
|
115 | this.model_containers[model.id] = accordion_group; | |
116 |
|
116 | |||
117 | this.create_child_view(model, function(view) { |
|
117 | this.create_child_view(model, {callback: function(view) { | |
118 | accordion_inner.append(view.$el); |
|
118 | accordion_inner.append(view.$el); | |
119 |
|
119 | |||
120 | that.update(); |
|
120 | that.update(); | |
@@ -124,7 +124,7 b' define([' | |||||
124 | that.after_displayed(function() { |
|
124 | that.after_displayed(function() { | |
125 | view.trigger('displayed'); |
|
125 | view.trigger('displayed'); | |
126 | }); |
|
126 | }); | |
127 | }); |
|
127 | }}); | |
128 | }, |
|
128 | }, | |
129 | }); |
|
129 | }); | |
130 |
|
130 | |||
@@ -186,7 +186,7 b' define([' | |||||
186 | .css('list-style-type', 'none') |
|
186 | .css('list-style-type', 'none') | |
187 | .appendTo(this.$tabs); |
|
187 | .appendTo(this.$tabs); | |
188 |
|
188 | |||
189 | this.create_child_view(model, function(view) { |
|
189 | this.create_child_view(model, {callback: function(view) { | |
190 | view.parent_tab = tab; |
|
190 | view.parent_tab = tab; | |
191 |
|
191 | |||
192 | var tab_text = $('<a />') |
|
192 | var tab_text = $('<a />') | |
@@ -215,7 +215,7 b' define([' | |||||
215 | that.after_displayed(function() { |
|
215 | that.after_displayed(function() { | |
216 | view.trigger('displayed'); |
|
216 | view.trigger('displayed'); | |
217 | }); |
|
217 | }); | |
218 | }); |
|
218 | }}); | |
219 | }, |
|
219 | }, | |
220 |
|
220 | |||
221 | update: function(options) { |
|
221 | update: function(options) { |
General Comments 0
You need to be logged in to leave comments.
Login now