Show More
@@ -155,7 +155,7 b' function(widget_manager, underscore, backbone){' | |||||
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | var data = {method: 'backbone', sync_method: method, sync_data: send_json}; |
|
157 | var data = {method: 'backbone', sync_method: method, sync_data: send_json}; | |
158 |
this.comm.send(data, this. |
|
158 | this.comm.send(data, this.callbacks); | |
159 | this.pending_msgs++; |
|
159 | this.pending_msgs++; | |
160 | } |
|
160 | } | |
161 | } |
|
161 | } | |
@@ -166,20 +166,46 b' function(widget_manager, underscore, backbone){' | |||||
166 | return model_json; |
|
166 | return model_json; | |
167 | }, |
|
167 | }, | |
168 |
|
168 | |||
169 | // Build a callback dict. |
|
169 | }); | |
170 | cell_callbacks: function (cell) { |
|
170 | ||
|
171 | ||||
|
172 | //-------------------------------------------------------------------- | |||
|
173 | // WidgetView class | |||
|
174 | //-------------------------------------------------------------------- | |||
|
175 | var BaseWidgetView = Backbone.View.extend({ | |||
|
176 | initialize: function(options) { | |||
|
177 | this.model.on('change',this.update,this); | |||
|
178 | this.widget_manager = options.widget_manager; | |||
|
179 | this.comm_manager = options.widget_manager.comm_manager; | |||
|
180 | this.cell = options.cell; | |||
|
181 | }, | |||
|
182 | ||||
|
183 | update: function(){ | |||
|
184 | // update thyself to be consistent with this.model | |||
|
185 | }, | |||
|
186 | ||||
|
187 | child_view: function(comm_id, view_name) { | |||
|
188 | var child_model = this.comm_manager.comms[comm_id].model; | |||
|
189 | var child_view = this.widget_manager.create_view(child_model, view_name, this.cell); | |||
|
190 | return child_view; | |||
|
191 | }, | |||
|
192 | ||||
|
193 | render: function(){ | |||
|
194 | // render thyself | |||
|
195 | }, | |||
|
196 | send: function (content) { | |||
|
197 | this.model.send(content, this.cell_callbacks(this.cell)); | |||
|
198 | }, | |||
|
199 | ||||
|
200 | touch: function () { | |||
|
201 | this.model.callbacks = this.cell_callbacks(); | |||
|
202 | this.model.save(this.model.changedAttributes(), {patch: true}); | |||
|
203 | }, | |||
|
204 | ||||
|
205 | cell_callbacks: function () { | |||
|
206 | // callback handlers specific to this view's cell | |||
171 | var callbacks = {}; |
|
207 | var callbacks = {}; | |
172 | if (cell === undefined) { |
|
208 | var cell = this.cell; | |
173 | // Used the last modified view as the sender of the message. This |
|
|||
174 | // will insure that any python code triggered by the sent message |
|
|||
175 | // can create and display widgets and output. |
|
|||
176 | if (this.last_modified_view !== undefined && |
|
|||
177 | this.last_modified_view.cell !== undefined) { |
|
|||
178 | cell = this.last_modified_view.cell; |
|
|||
179 | } else { |
|
|||
180 | cell = null; |
|
|||
181 | } |
|
|||
182 | } |
|
|||
183 | if (cell !== null) { |
|
209 | if (cell !== null) { | |
184 |
|
210 | |||
185 | // Try to get output handlers |
|
211 | // Try to get output handlers | |
@@ -198,7 +224,7 b' function(widget_manager, underscore, backbone){' | |||||
198 | clear_output : handle_clear_output, |
|
224 | clear_output : handle_clear_output, | |
199 |
|
225 | |||
200 | status : function (msg) { |
|
226 | status : function (msg) { | |
201 |
that._handle_status(msg, that.cell_callbacks( |
|
227 | that._handle_status(msg, that.cell_callbacks()); | |
202 | }, |
|
228 | }, | |
203 |
|
229 | |||
204 | // Special function only registered by widget messages. |
|
230 | // Special function only registered by widget messages. | |
@@ -212,41 +238,7 b' function(widget_manager, underscore, backbone){' | |||||
212 | } |
|
238 | } | |
213 | return callbacks; |
|
239 | return callbacks; | |
214 | }, |
|
240 | }, | |
215 | }); |
|
|||
216 |
|
241 | |||
217 |
|
||||
218 | //-------------------------------------------------------------------- |
|
|||
219 | // WidgetView class |
|
|||
220 | //-------------------------------------------------------------------- |
|
|||
221 | var BaseWidgetView = Backbone.View.extend({ |
|
|||
222 | initialize: function(options) { |
|
|||
223 | this.model.on('change',this.update,this); |
|
|||
224 | this.widget_manager = options.widget_manager; |
|
|||
225 | this.comm_manager = options.widget_manager.comm_manager; |
|
|||
226 | this.cell = options.cell |
|
|||
227 | }, |
|
|||
228 |
|
||||
229 | update: function(){ |
|
|||
230 | // update thyself to be consistent with this.model |
|
|||
231 | }, |
|
|||
232 |
|
||||
233 | child_view: function(comm_id, view_name) { |
|
|||
234 | var child_model = this.comm_manager.comms[comm_id].model; |
|
|||
235 | var child_view = this.widget_manager.create_view(child_model, view_name, this.cell); |
|
|||
236 | return child_view; |
|
|||
237 | }, |
|
|||
238 |
|
||||
239 | render: function(){ |
|
|||
240 | // render thyself |
|
|||
241 | }, |
|
|||
242 | send: function (content) { |
|
|||
243 | this.model.send(content, this.model.cell_callbacks(this.cell)); |
|
|||
244 | }, |
|
|||
245 |
|
||||
246 | touch: function () { |
|
|||
247 | this.model.last_modified_view = this; |
|
|||
248 | this.model.save(this.model.changedAttributes(), {patch: true}); |
|
|||
249 | }, |
|
|||
250 | }); |
|
242 | }); | |
251 |
|
243 | |||
252 | var WidgetView = BaseWidgetView.extend({ |
|
244 | var WidgetView = BaseWidgetView.extend({ |
General Comments 0
You need to be logged in to leave comments.
Login now