Show More
@@ -42,8 +42,8 b' define(["components/underscore/underscore-min",' | |||
|
42 | 42 | comm.model = this; |
|
43 | 43 | |
|
44 | 44 | // Hook comm messages up to model. |
|
45 | comm.on_close($.proxy(this.handle_comm_closed, this)); | |
|
46 | comm.on_msg($.proxy(this.handle_comm_msg, this)); | |
|
45 | comm.on_close($.proxy(this._handle_comm_closed, this)); | |
|
46 | comm.on_msg($.proxy(this._handle_comm_msg, this)); | |
|
47 | 47 | |
|
48 | 48 | return Backbone.Model.apply(this); |
|
49 | 49 | }, |
@@ -65,7 +65,64 b' define(["components/underscore/underscore-min",' | |||
|
65 | 65 | }, |
|
66 | 66 | |
|
67 | 67 | |
|
68 | handle_status: function (cell, msg) { | |
|
68 | // Handle when a widget is closed. | |
|
69 | _handle_comm_closed: function (msg) { | |
|
70 | for (var cell in this.views) { | |
|
71 | var views = this.views[cell]; | |
|
72 | for (var view_index in views) { | |
|
73 | var view = views[view_index]; | |
|
74 | view.remove(); | |
|
75 | } | |
|
76 | } | |
|
77 | }, | |
|
78 | ||
|
79 | ||
|
80 | // Handle incomming comm msg. | |
|
81 | _handle_comm_msg: function (msg) { | |
|
82 | var method = msg.content.data.method; | |
|
83 | switch (method){ | |
|
84 | case 'display': | |
|
85 | ||
|
86 | // Try to get the cell index. | |
|
87 | var cell = this._get_msg_cell(msg.parent_header.msg_id); | |
|
88 | if (cell == null) { | |
|
89 | console.log("Could not determine where the display" + | |
|
90 | " message was from. Widget will not be displayed") | |
|
91 | } else { | |
|
92 | this._display_view(msg.content.data.view_name, | |
|
93 | msg.content.data.parent, | |
|
94 | cell); | |
|
95 | } | |
|
96 | break; | |
|
97 | case 'update': | |
|
98 | this._handle_update(msg.content.data.state); | |
|
99 | break; | |
|
100 | } | |
|
101 | }, | |
|
102 | ||
|
103 | ||
|
104 | // Handle when a widget is updated via the python side. | |
|
105 | _handle_update: function (state) { | |
|
106 | this.updating = true; | |
|
107 | try { | |
|
108 | for (var key in state) { | |
|
109 | if (state.hasOwnProperty(key)) { | |
|
110 | if (key == "_css"){ | |
|
111 | this.css = state[key]; | |
|
112 | } else { | |
|
113 | this.set(key, state[key]); | |
|
114 | } | |
|
115 | } | |
|
116 | } | |
|
117 | this.id = this.comm.comm_id; | |
|
118 | this.save(); | |
|
119 | } finally { | |
|
120 | this.updating = false; | |
|
121 | } | |
|
122 | }, | |
|
123 | ||
|
124 | ||
|
125 | _handle_status: function (cell, msg) { | |
|
69 | 126 | //execution_state : ('busy', 'idle', 'starting') |
|
70 | 127 | if (msg.content.execution_state=='idle') { |
|
71 | 128 | |
@@ -90,7 +147,7 b' define(["components/underscore/underscore-min",' | |||
|
90 | 147 | |
|
91 | 148 | |
|
92 | 149 | // Custom syncronization logic. |
|
93 | handle_sync: function (method, options) { | |
|
150 | _handle_sync: function (method, options) { | |
|
94 | 151 | var model_json = this.toJSON(); |
|
95 | 152 | |
|
96 | 153 | // Only send updated state if the state hasn't been changed |
@@ -142,65 +199,8 b' define(["components/underscore/underscore-min",' | |||
|
142 | 199 | }, |
|
143 | 200 | |
|
144 | 201 | |
|
145 | // Handle incomming comm msg. | |
|
146 | handle_comm_msg: function (msg) { | |
|
147 | var method = msg.content.data.method; | |
|
148 | switch (method){ | |
|
149 | case 'display': | |
|
150 | ||
|
151 | // Try to get the cell index. | |
|
152 | var cell = this._get_msg_cell(msg.parent_header.msg_id); | |
|
153 | if (cell == null) { | |
|
154 | console.log("Could not determine where the display" + | |
|
155 | " message was from. Widget will not be displayed") | |
|
156 | } else { | |
|
157 | this.display_view(msg.content.data.view_name, | |
|
158 | msg.content.data.parent, | |
|
159 | cell); | |
|
160 | } | |
|
161 | break; | |
|
162 | case 'update': | |
|
163 | this.handle_update(msg.content.data.state); | |
|
164 | break; | |
|
165 | } | |
|
166 | }, | |
|
167 | ||
|
168 | ||
|
169 | // Handle when a widget is updated via the python side. | |
|
170 | handle_update: function (state) { | |
|
171 | this.updating = true; | |
|
172 | try { | |
|
173 | for (var key in state) { | |
|
174 | if (state.hasOwnProperty(key)) { | |
|
175 | if (key == "_css"){ | |
|
176 | this.css = state[key]; | |
|
177 | } else { | |
|
178 | this.set(key, state[key]); | |
|
179 | } | |
|
180 | } | |
|
181 | } | |
|
182 | this.id = this.comm.comm_id; | |
|
183 | this.save(); | |
|
184 | } finally { | |
|
185 | this.updating = false; | |
|
186 | } | |
|
187 | }, | |
|
188 | ||
|
189 | ||
|
190 | // Handle when a widget is closed. | |
|
191 | handle_comm_closed: function (msg) { | |
|
192 | for (var cell in this.views) { | |
|
193 | var views = this.views[cell]; | |
|
194 | for (var view_index in views) { | |
|
195 | var view = views[view_index]; | |
|
196 | view.remove(); | |
|
197 | } | |
|
198 | } | |
|
199 | }, | |
|
200 | ||
|
201 | ||
|
202 | 202 | // Create view that represents the model. |
|
203 | display_view: function (view_name, parent_comm_id, cell) { | |
|
203 | _display_view: function (view_name, parent_comm_id, cell) { | |
|
204 | 204 | var new_views = []; |
|
205 | 205 | |
|
206 | 206 | var displayed = false; |
@@ -279,7 +279,7 b' define(["components/underscore/underscore-min",' | |||
|
279 | 279 | output : $.proxy(cell.output_area.handle_output, cell.output_area), |
|
280 | 280 | clear_output : $.proxy(cell.output_area.handle_clear_output, cell.output_area), |
|
281 | 281 | status : function(msg){ |
|
282 | that.handle_status(cell, msg); | |
|
282 | that._handle_status(cell, msg); | |
|
283 | 283 | }, |
|
284 | 284 | get_cell : function() { |
|
285 | 285 | if (that.last_modified_view != undefined && |
@@ -356,7 +356,7 b' define(["components/underscore/underscore-min",' | |||
|
356 | 356 | if (this.model.css.hasOwnProperty(selector)) { |
|
357 | 357 | |
|
358 | 358 | // Apply the css traits to all elements that match the selector. |
|
359 | var elements = this.get_selector_element(selector); | |
|
359 | var elements = this._get_selector_element(selector); | |
|
360 | 360 | if (elements.length > 0) { |
|
361 | 361 | var css_traits = this.model.css[selector]; |
|
362 | 362 | for (var css_key in css_traits) { |
@@ -374,7 +374,7 b' define(["components/underscore/underscore-min",' | |||
|
374 | 374 | var add_class_calls = add_class[0]; |
|
375 | 375 | if (add_class_calls > this._add_class_calls) { |
|
376 | 376 | this._add_class_calls = add_class_calls; |
|
377 | var elements = this.get_selector_element(add_class[1]); | |
|
377 | var elements = this._get_selector_element(add_class[1]); | |
|
378 | 378 | if (elements.length > 0) { |
|
379 | 379 | elements.addClass(add_class[2]); |
|
380 | 380 | } |
@@ -386,7 +386,7 b' define(["components/underscore/underscore-min",' | |||
|
386 | 386 | var remove_class_calls = remove_class[0]; |
|
387 | 387 | if (remove_class_calls > this._remove_class_calls) { |
|
388 | 388 | this._remove_class_calls = remove_class_calls; |
|
389 | var elements = this.get_selector_element(remove_class[1]); | |
|
389 | var elements = this._get_selector_element(remove_class[1]); | |
|
390 | 390 | if (elements.length > 0) { |
|
391 | 391 | elements.removeClass(remove_class[2]); |
|
392 | 392 | } |
@@ -394,7 +394,7 b' define(["components/underscore/underscore-min",' | |||
|
394 | 394 | } |
|
395 | 395 | }, |
|
396 | 396 | |
|
397 | get_selector_element: function(selector) { | |
|
397 | _get_selector_element: function(selector) { | |
|
398 | 398 | // Get the elements via the css selector. If the selector is |
|
399 | 399 | // blank, apply the style to the $el_to_style element. If |
|
400 | 400 | // the $el_to_style element is not defined, use apply the |
@@ -422,7 +422,7 b' define(["components/underscore/underscore-min",' | |||
|
422 | 422 | |
|
423 | 423 | var that = this; |
|
424 | 424 | Backbone.sync = function(method, model, options, error) { |
|
425 | var result = model.handle_sync(method, options); | |
|
425 | var result = model._handle_sync(method, options); | |
|
426 | 426 | if (options.success) { |
|
427 | 427 | options.success(result); |
|
428 | 428 | } |
General Comments 0
You need to be logged in to leave comments.
Login now