Show More
@@ -77,11 +77,12 b'' | |||
|
77 | 77 | console.log("Could not determine where the display" + |
|
78 | 78 | " message was from. Widget will not be displayed"); |
|
79 | 79 | } else { |
|
80 |
var view = this.create_view(model, msg.content.data.view_name |
|
|
80 | var view = this.create_view(model, msg.content.data.view_name); | |
|
81 | 81 | if (view !== undefined |
|
82 | 82 | && cell.widget_subarea !== undefined |
|
83 | 83 | && cell.widget_subarea !== null) { |
|
84 | 84 | |
|
85 | view.cell = cell; | |
|
85 | 86 | cell.widget_area.show(); |
|
86 | 87 | cell.widget_subarea.append(view.$el); |
|
87 | 88 | } |
@@ -91,7 +92,11 b'' | |||
|
91 | 92 | } |
|
92 | 93 | |
|
93 | 94 | <<<<<<< HEAD |
|
95 | <<<<<<< HEAD | |
|
94 | 96 | WidgetManager.prototype.create_view = function(model, view_name, cell) { |
|
97 | ======= | |
|
98 | WidgetManager.prototype.create_view = function(model, view_name, options) { | |
|
99 | >>>>>>> Completely remove cell from model and view. | |
|
95 | 100 | view_name = view_name || model.get('default_view_name'); |
|
96 | 101 | ======= |
|
97 | 102 | WidgetManager.prototype.create_view = function(model, view_name, cell, options) { |
@@ -99,7 +104,7 b'' | |||
|
99 | 104 | >>>>>>> Add widget view options in creating child views |
|
100 | 105 | var ViewType = this.widget_view_types[view_name]; |
|
101 | 106 | if (ViewType !== undefined && ViewType !== null) { |
|
102 |
var view = new ViewType({model: model, widget_manager: this, |
|
|
107 | var view = new ViewType({model: model, widget_manager: this, options: options}); | |
|
103 | 108 | view.render(); |
|
104 | 109 | model.views.push(view); |
|
105 | 110 | model.on('destroy', view.remove, view); |
@@ -155,14 +160,14 b'' | |||
|
155 | 160 | }, |
|
156 | 161 | |
|
157 | 162 | WidgetManager.prototype.get_msg_cell = function (msg_id) { |
|
158 | var cell = null; | |
|
163 | var cell = null; | |
|
159 | 164 | // First, check to see if the msg was triggered by cell execution. |
|
160 | 165 | if (IPython.notebook !== undefined && IPython.notebook !== null) { |
|
161 | 166 | cell = IPython.notebook.get_msg_cell(msg_id); |
|
162 | 167 | } |
|
163 | if (cell !== null) { | |
|
164 | return cell | |
|
165 | } | |
|
168 | if (cell !== null) { | |
|
169 | return cell | |
|
170 | } | |
|
166 | 171 | // Second, check to see if a get_cell callback was defined |
|
167 | 172 | // for the message. get_cell callbacks are registered for |
|
168 | 173 | // widget messages, so this block is actually checking to see if the |
@@ -183,6 +188,42 b'' | |||
|
183 | 188 | return null; |
|
184 | 189 | }; |
|
185 | 190 | |
|
191 | WidgetManager.prototype.callbacks = function (view) { | |
|
192 | // callback handlers specific a view | |
|
193 | var callbacks = {}; | |
|
194 | var cell = view.cell; | |
|
195 | if (cell !== null) { | |
|
196 | // Try to get output handlers | |
|
197 | var handle_output = null; | |
|
198 | var handle_clear_output = null; | |
|
199 | if (cell.output_area !== undefined && cell.output_area !== null) { | |
|
200 | handle_output = $.proxy(cell.output_area.handle_output, cell.output_area); | |
|
201 | handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area); | |
|
202 | } | |
|
203 | ||
|
204 | // Create callback dict using what is known | |
|
205 | var that = this; | |
|
206 | callbacks = { | |
|
207 | iopub : { | |
|
208 | output : handle_output, | |
|
209 | clear_output : handle_clear_output, | |
|
210 | ||
|
211 | status : function (msg) { | |
|
212 | view.model._handle_status(msg, that.callbacks()); | |
|
213 | }, | |
|
214 | ||
|
215 | // Special function only registered by widget messages. | |
|
216 | // Allows us to get the cell for a message so we know | |
|
217 | // where to add widgets if the code requires it. | |
|
218 | get_cell : function () { | |
|
219 | return cell; | |
|
220 | }, | |
|
221 | }, | |
|
222 | }; | |
|
223 | } | |
|
224 | return callbacks; | |
|
225 | }; | |
|
226 | ||
|
186 | 227 | |
|
187 | 228 | WidgetManager.prototype.get_model = function (model_id) { |
|
188 | 229 | var model = this._model_instances[model_id]; |
@@ -172,7 +172,6 b' function(widget_manager, underscore, backbone){' | |||
|
172 | 172 | this.model.on('change',this.update,this); |
|
173 | 173 | this.widget_manager = options.widget_manager; |
|
174 | 174 | this.comm_manager = options.widget_manager.comm_manager; |
|
175 | this.cell = options.cell; | |
|
176 | 175 | this.options = options.options; |
|
177 | 176 | this.child_views = []; |
|
178 | 177 | this.model.views.push(this); |
@@ -196,7 +195,11 b' function(widget_manager, underscore, backbone){' | |||
|
196 | 195 | >>>>>>> Updated comm id comments in view to model id |
|
197 | 196 | // if the view name is not given, it defaults to the model's default view attribute |
|
198 | 197 | var child_model = this.widget_manager.get_model(model_id); |
|
198 | <<<<<<< HEAD | |
|
199 | 199 | var child_view = this.widget_manager.create_view(child_model, view_name, this.cell); |
|
200 | ======= | |
|
201 | var child_view = this.widget_manager.create_view(child_model, view_name, options); | |
|
202 | >>>>>>> Completely remove cell from model and view. | |
|
200 | 203 | this.child_views[model_id] = child_view; |
|
201 | 204 | ======= |
|
202 | 205 | child_view: function(comm_id, view_name, options) { |
@@ -234,47 +237,11 b' function(widget_manager, underscore, backbone){' | |||
|
234 | 237 | // render the view. By default, this is only called the first time the view is created |
|
235 | 238 | }, |
|
236 | 239 | send: function (content) { |
|
237 | this.model.send(content, this._callbacks()); | |
|
240 | this.model.send(content, this.widget_manager.callbacks(this)); | |
|
238 | 241 | }, |
|
239 | 242 | |
|
240 | 243 | touch: function () { |
|
241 | this.model.save(this.model.changedAttributes(), {patch: true, callbacks: this._callbacks()}); | |
|
242 | }, | |
|
243 | ||
|
244 | _callbacks: function () { | |
|
245 | // callback handlers specific to this view's cell | |
|
246 | var callbacks = {}; | |
|
247 | var cell = this.cell; | |
|
248 | if (cell !== null) { | |
|
249 | // Try to get output handlers | |
|
250 | var handle_output = null; | |
|
251 | var handle_clear_output = null; | |
|
252 | if (cell.output_area !== undefined && cell.output_area !== null) { | |
|
253 | handle_output = $.proxy(cell.output_area.handle_output, cell.output_area); | |
|
254 | handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area); | |
|
255 | } | |
|
256 | ||
|
257 | // Create callback dict using what is known | |
|
258 | var that = this; | |
|
259 | callbacks = { | |
|
260 | iopub : { | |
|
261 | output : handle_output, | |
|
262 | clear_output : handle_clear_output, | |
|
263 | ||
|
264 | status : function (msg) { | |
|
265 | that.model._handle_status(msg, that._callbacks()); | |
|
266 | }, | |
|
267 | ||
|
268 | // Special function only registered by widget messages. | |
|
269 | // Allows us to get the cell for a message so we know | |
|
270 | // where to add widgets if the code requires it. | |
|
271 | get_cell : function () { | |
|
272 | return cell; | |
|
273 | }, | |
|
274 | }, | |
|
275 | }; | |
|
276 | } | |
|
277 | return callbacks; | |
|
244 | this.model.save(this.model.changedAttributes(), {patch: true, callbacks: this.widget_manager.callbacks(this)}); | |
|
278 | 245 | }, |
|
279 | 246 | |
|
280 | 247 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now