##// END OF EJS Templates
Completely remove cell from model and view.
Jonathan Frederic -
Show More
@@ -77,11 +77,12
77 console.log("Could not determine where the display" +
77 console.log("Could not determine where the display" +
78 " message was from. Widget will not be displayed");
78 " message was from. Widget will not be displayed");
79 } else {
79 } else {
80 var view = this.create_view(model, msg.content.data.view_name, cell);
80 var view = this.create_view(model, msg.content.data.view_name);
81 if (view !== undefined
81 if (view !== undefined
82 && cell.widget_subarea !== undefined
82 && cell.widget_subarea !== undefined
83 && cell.widget_subarea !== null) {
83 && cell.widget_subarea !== null) {
84
84
85 view.cell = cell;
85 cell.widget_area.show();
86 cell.widget_area.show();
86 cell.widget_subarea.append(view.$el);
87 cell.widget_subarea.append(view.$el);
87 }
88 }
@@ -91,7 +92,11
91 }
92 }
92
93
93 <<<<<<< HEAD
94 <<<<<<< HEAD
95 <<<<<<< HEAD
94 WidgetManager.prototype.create_view = function(model, view_name, cell) {
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 view_name = view_name || model.get('default_view_name');
100 view_name = view_name || model.get('default_view_name');
96 =======
101 =======
97 WidgetManager.prototype.create_view = function(model, view_name, cell, options) {
102 WidgetManager.prototype.create_view = function(model, view_name, cell, options) {
@@ -99,7 +104,7
99 >>>>>>> Add widget view options in creating child views
104 >>>>>>> Add widget view options in creating child views
100 var ViewType = this.widget_view_types[view_name];
105 var ViewType = this.widget_view_types[view_name];
101 if (ViewType !== undefined && ViewType !== null) {
106 if (ViewType !== undefined && ViewType !== null) {
102 var view = new ViewType({model: model, widget_manager: this, cell: cell, options: options});
107 var view = new ViewType({model: model, widget_manager: this, options: options});
103 view.render();
108 view.render();
104 model.views.push(view);
109 model.views.push(view);
105 model.on('destroy', view.remove, view);
110 model.on('destroy', view.remove, view);
@@ -183,6 +188,42
183 return null;
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 WidgetManager.prototype.get_model = function (model_id) {
228 WidgetManager.prototype.get_model = function (model_id) {
188 var model = this._model_instances[model_id];
229 var model = this._model_instances[model_id];
@@ -172,7 +172,6 function(widget_manager, underscore, backbone){
172 this.model.on('change',this.update,this);
172 this.model.on('change',this.update,this);
173 this.widget_manager = options.widget_manager;
173 this.widget_manager = options.widget_manager;
174 this.comm_manager = options.widget_manager.comm_manager;
174 this.comm_manager = options.widget_manager.comm_manager;
175 this.cell = options.cell;
176 this.options = options.options;
175 this.options = options.options;
177 this.child_views = [];
176 this.child_views = [];
178 this.model.views.push(this);
177 this.model.views.push(this);
@@ -196,7 +195,11 function(widget_manager, underscore, backbone){
196 >>>>>>> Updated comm id comments in view to model id
195 >>>>>>> Updated comm id comments in view to model id
197 // if the view name is not given, it defaults to the model's default view attribute
196 // if the view name is not given, it defaults to the model's default view attribute
198 var child_model = this.widget_manager.get_model(model_id);
197 var child_model = this.widget_manager.get_model(model_id);
198 <<<<<<< HEAD
199 var child_view = this.widget_manager.create_view(child_model, view_name, this.cell);
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 this.child_views[model_id] = child_view;
203 this.child_views[model_id] = child_view;
201 =======
204 =======
202 child_view: function(comm_id, view_name, options) {
205 child_view: function(comm_id, view_name, options) {
@@ -234,47 +237,11 function(widget_manager, underscore, backbone){
234 // render the view. By default, this is only called the first time the view is created
237 // render the view. By default, this is only called the first time the view is created
235 },
238 },
236 send: function (content) {
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 touch: function () {
243 touch: function () {
241 this.model.save(this.model.changedAttributes(), {patch: true, callbacks: this._callbacks()});
244 this.model.save(this.model.changedAttributes(), {patch: true, callbacks: this.widget_manager.callbacks(this)});
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;
278 },
245 },
279
246
280 });
247 });
General Comments 0
You need to be logged in to leave comments. Login now