##// END OF EJS Templates
Fixed context errors and a couple of typos to get the tests working again
Jonathan Frederic -
Show More
@@ -38,8 +38,8 b''
38
38
39 // Register already-registered widget model types with the comm manager.
39 // Register already-registered widget model types with the comm manager.
40 var that = this;
40 var that = this;
41 _.each(WidgetManager._model_types, function(value, key) {
41 _.each(WidgetManager._model_types, function(model_type, model_name) {
42 that.comm_manager.register_target(value, $.proxy(that._handle_comm_open, that));
42 that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that));
43 });
43 });
44 };
44 };
45
45
@@ -86,12 +86,13 b' function(WidgetManager, Underscore, Backbone){'
86
86
87 apply_update: function (state) {
87 apply_update: function (state) {
88 // Handle when a widget is updated via the python side.
88 // Handle when a widget is updated via the python side.
89 var that = this;
89 _.each(state, function(value, key) {
90 _.each(state, function(value, key) {
90 this.key_value_lock = [key, value];
91 that.key_value_lock = [key, value];
91 try {
92 try {
92 this.set(key, this._unpack_models(value));
93 that.set(key, that._unpack_models(value));
93 } finally {
94 } finally {
94 this.key_value_lock = null;
95 that.key_value_lock = null;
95 }
96 }
96 });
97 });
97 },
98 },
@@ -154,7 +155,7 b' function(WidgetManager, Underscore, Backbone){'
154 }
155 }
155
156
156 // Only sync if there are attributes to send to the back-end.
157 // Only sync if there are attributes to send to the back-end.
157 if (attr.length > 0) {
158 if (_.size(attrs) > 0) {
158 var callbacks = options.callbacks || {};
159 var callbacks = options.callbacks || {};
159 if (this.pending_msgs >= this.msg_throttle) {
160 if (this.pending_msgs >= this.msg_throttle) {
160 // The throttle has been exceeded, buffer the current msg so
161 // The throttle has been exceeded, buffer the current msg so
@@ -203,8 +204,9 b' function(WidgetManager, Underscore, Backbone){'
203 return value.id;
204 return value.id;
204 } else if (value instanceof Object) {
205 } else if (value instanceof Object) {
205 var packed = {};
206 var packed = {};
207 var that = this;
206 _.each(value, function(sub_value, key) {
208 _.each(value, function(sub_value, key) {
207 packed[key] = this._pack_models(sub_value);
209 packed[key] = that._pack_models(sub_value);
208 });
210 });
209 return packed;
211 return packed;
210 } else {
212 } else {
@@ -216,8 +218,9 b' function(WidgetManager, Underscore, Backbone){'
216 // Replace model ids with models recursively.
218 // Replace model ids with models recursively.
217 if (value instanceof Object) {
219 if (value instanceof Object) {
218 var unpacked = {};
220 var unpacked = {};
221 var that = this;
219 _.each(value, function(sub_value, key) {
222 _.each(value, function(sub_value, key) {
220 unpacked[key] = this._unpack_models(sub_value);
223 unpacked[key] = that._unpack_models(sub_value);
221 });
224 });
222 return unpacked;
225 return unpacked;
223 } else {
226 } else {
@@ -366,9 +369,10 b' function(WidgetManager, Underscore, Backbone){'
366
369
367 var css = this.model.get('_css');
370 var css = this.model.get('_css');
368 if (css === undefined) {return;}
371 if (css === undefined) {return;}
372 var that = this;
369 _.each(css, function(css_traits, selector){
373 _.each(css, function(css_traits, selector){
370 // Apply the css traits to all elements that match the selector.
374 // Apply the css traits to all elements that match the selector.
371 var elements = this._get_selector_element(selector);
375 var elements = that._get_selector_element(selector);
372 if (elements.length > 0) {
376 if (elements.length > 0) {
373 _.each(css_traits, function(css_value, css_key){
377 _.each(css_traits, function(css_value, css_key){
374 elements.css(css_key, css_value);
378 elements.css(css_key, css_value);
@@ -50,10 +50,11 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
50 // JQuery slider option keys. These keys happen to have a
50 // JQuery slider option keys. These keys happen to have a
51 // one-to-one mapping with the corrosponding keys of the model.
51 // one-to-one mapping with the corrosponding keys of the model.
52 var jquery_slider_keys = ['step', 'max', 'min', 'disabled'];
52 var jquery_slider_keys = ['step', 'max', 'min', 'disabled'];
53 var that = this;
53 _.each(jquery_slider_keys, function(key, i) {
54 _.each(jquery_slider_keys, function(key, i) {
54 var model_value = this.model.get(key);
55 var model_value = that.model.get(key);
55 if (model_value !== undefined) {
56 if (model_value !== undefined) {
56 this.$slider.slider("option", key, model_value);
57 that.$slider.slider("option", key, model_value);
57 }
58 }
58 });
59 });
59
60
@@ -49,10 +49,11 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
49 // JQuery slider option keys. These keys happen to have a
49 // JQuery slider option keys. These keys happen to have a
50 // one-to-one mapping with the corrosponding keys of the model.
50 // one-to-one mapping with the corrosponding keys of the model.
51 var jquery_slider_keys = ['step', 'max', 'min', 'disabled'];
51 var jquery_slider_keys = ['step', 'max', 'min', 'disabled'];
52 var that = this;
52 _.each(jquery_slider_keys, function(key, i) {
53 _.each(jquery_slider_keys, function(key, i) {
53 var model_value = this.model.get(key);
54 var model_value = that.model.get(key);
54 if (model_value !== undefined) {
55 if (model_value !== undefined) {
55 this.$slider.slider("option", key, model_value);
56 that.$slider.slider("option", key, model_value);
56 }
57 }
57 });
58 });
58
59
@@ -67,10 +67,11 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
67 var items = this.model.get('values');
67 var items = this.model.get('values');
68 var $replace_droplist = $('<ul />')
68 var $replace_droplist = $('<ul />')
69 .addClass('dropdown-menu');
69 .addClass('dropdown-menu');
70 var that = this;
70 _.each(items, function(item, i) {
71 _.each(items, function(item, i) {
71 var item_button = $('<a href="#"/>')
72 var item_button = $('<a href="#"/>')
72 .text(item)
73 .text(item)
73 .on('click', $.proxy(this.handle_click, this));
74 .on('click', $.proxy(that.handle_click, that));
74 $replace_droplist.append($('<li />').append(item_button));
75 $replace_droplist.append($('<li />').append(item_button));
75 });
76 });
76
77
@@ -140,20 +141,21 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
140 // Add missing items to the DOM.
141 // Add missing items to the DOM.
141 var items = this.model.get('values');
142 var items = this.model.get('values');
142 var disabled = this.model.get('disabled');
143 var disabled = this.model.get('disabled');
144 var that = this;
143 _.each(items, function(item, index) {
145 _.each(items, function(item, index) {
144 var item_query = ' :input[value="' + item + '"]';
146 var item_query = ' :input[value="' + item + '"]';
145 if (this.$el.find(item_query).length === 0) {
147 if (that.$el.find(item_query).length === 0) {
146 var $label = $('<label />')
148 var $label = $('<label />')
147 .addClass('radio')
149 .addClass('radio')
148 .text(item)
150 .text(item)
149 .appendTo(this.$container);
151 .appendTo(that.$container);
150
152
151 $('<input />')
153 $('<input />')
152 .attr('type', 'radio')
154 .attr('type', 'radio')
153 .addClass(this.model)
155 .addClass(that.model)
154 .val(item)
156 .val(item)
155 .prependTo($label)
157 .prependTo($label)
156 .on('click', $.proxy(this.handle_click, this));
158 .on('click', $.proxy(that.handle_click, that));
157 }
159 }
158
160
159 var $item_element = this.$container.find(item_query);
161 var $item_element = this.$container.find(item_query);
@@ -230,15 +232,16 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
230 // Add missing items to the DOM.
232 // Add missing items to the DOM.
231 var items = this.model.get('values');
233 var items = this.model.get('values');
232 var disabled = this.model.get('disabled');
234 var disabled = this.model.get('disabled');
235 var that = this;
233 _.each(items, function(item, index) {
236 _.each(items, function(item, index) {
234 var item_query = ' :contains("' + item + '")';
237 var item_query = ' :contains("' + item + '")';
235 if (this.$buttongroup.find(item_query).length === 0) {
238 if (that.$buttongroup.find(item_query).length === 0) {
236 $('<button />')
239 $('<button />')
237 .attr('type', 'button')
240 .attr('type', 'button')
238 .addClass('btn')
241 .addClass('btn')
239 .text(item)
242 .text(item)
240 .appendTo(this.$buttongroup)
243 .appendTo(that.$buttongroup)
241 .on('click', $.proxy(this.handle_click, this));
244 .on('click', $.proxy(that.handle_click, that));
242 }
245 }
243
246
244 var $item_element = this.$buttongroup.find(item_query);
247 var $item_element = this.$buttongroup.find(item_query);
@@ -314,14 +317,15 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
314 if (options === undefined || options.updated_view != this) {
317 if (options === undefined || options.updated_view != this) {
315 // Add missing items to the DOM.
318 // Add missing items to the DOM.
316 var items = this.model.get('values');
319 var items = this.model.get('values');
320 var that = this;
317 _.each(items, function(item, index) {
321 _.each(items, function(item, index) {
318 var item_query = ' :contains("' + item + '")';
322 var item_query = ' :contains("' + item + '")';
319 if (this.$listbox.find(item_query).length === 0) {
323 if (that.$listbox.find(item_query).length === 0) {
320 $('<option />')
324 $('<option />')
321 .text(item)
325 .text(item)
322 .attr('value', item)
326 .attr('value', item)
323 .appendTo(this.$listbox)
327 .appendTo(that.$listbox)
324 .on('click', $.proxy(this.handle_click, this));
328 .on('click', $.proxy(that.handle_click, that));
325 }
329 }
326 });
330 });
327
331
@@ -39,8 +39,9 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
39 if (options === undefined || options.updated_view != this) {
39 if (options === undefined || options.updated_view != this) {
40 // Set tab titles
40 // Set tab titles
41 var titles = this.model.get('_titles');
41 var titles = this.model.get('_titles');
42 var that = this;
42 _.each(titles, function(title, page_index) {
43 _.each(titles, function(title, page_index) {
43 var accordian = this.containers[page_index];
44 var accordian = that.containers[page_index];
44 if (accordian !== undefined) {
45 if (accordian !== undefined) {
45 accordian
46 accordian
46 .find('.accordion-heading')
47 .find('.accordion-heading')
@@ -216,8 +217,9 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
216 if (options === undefined || options.updated_view != this) {
217 if (options === undefined || options.updated_view != this) {
217 // Set tab titles
218 // Set tab titles
218 var titles = this.model.get('_titles');
219 var titles = this.model.get('_titles');
220 var that = this;
219 _.each(titles, function(title, page_index) {
221 _.each(titles, function(title, page_index) {
220 var tab_text = this.containers[page_index];
222 var tab_text = that.containers[page_index];
221 if (tab_text !== undefined) {
223 if (tab_text !== undefined) {
222 tab_text.text(title);
224 tab_text.text(title);
223 }
225 }
@@ -80,7 +80,12 b' class CallbackDispatcher(LoggingConfigurable):'
80 """Gets the number of arguments in a callback"""
80 """Gets the number of arguments in a callback"""
81 if callable(callback):
81 if callable(callback):
82 argspec = inspect.getargspec(callback)
82 argspec = inspect.getargspec(callback)
83 nargs = len(argspec[1]) # Only count vargs!
83 if argspec[0] is None:
84 nargs = 0
85 elif argspec[3] is None:
86 nargs = len(argspec[0]) # Only count vargs!
87 else:
88 nargs = len(argspec[0]) - len(argspec[3]) # Subtract number of defaults.
84
89
85 # Bound methods have an additional 'self' argument
90 # Bound methods have an additional 'self' argument
86 if isinstance(callback, types.MethodType):
91 if isinstance(callback, types.MethodType):
General Comments 0
You need to be logged in to leave comments. Login now