Show More
@@ -274,4 +274,82 b' define(["notebook/js/widget"], function(widget_manager){' | |||||
274 | }); |
|
274 | }); | |
275 |
|
275 | |||
276 | widget_manager.register_widget_view('ToggleButtonsView', ToggleButtonsView); |
|
276 | widget_manager.register_widget_view('ToggleButtonsView', ToggleButtonsView); | |
|
277 | ||||
|
278 | var ListBoxView = IPython.WidgetView.extend({ | |||
|
279 | ||||
|
280 | // Called when view is rendered. | |||
|
281 | render : function(){ | |||
|
282 | this.$el | |||
|
283 | .addClass('widget-hbox') | |||
|
284 | .html(''); | |||
|
285 | this.$label = $('<div />') | |||
|
286 | .appendTo(this.$el) | |||
|
287 | .addClass('widget-hlabel') | |||
|
288 | .hide(); | |||
|
289 | this.$listbox = $('<select />') | |||
|
290 | .addClass('widget-listbox') | |||
|
291 | .attr('size', 6) | |||
|
292 | .appendTo(this.$el); | |||
|
293 | this.$el_to_style = this.$listbox; // Set default element to style | |||
|
294 | this.update(); | |||
|
295 | }, | |||
|
296 | ||||
|
297 | // Handles: Backend -> Frontend Sync | |||
|
298 | // Frontent -> Frontend Sync | |||
|
299 | update : function(){ | |||
|
300 | ||||
|
301 | // Add missing items to the DOM. | |||
|
302 | var items = this.model.get('values'); | |||
|
303 | for (var index in items) { | |||
|
304 | var item_query = ' :contains("' + items[index] + '")'; | |||
|
305 | if (this.$listbox.find(item_query).length == 0) { | |||
|
306 | ||||
|
307 | var that = this; | |||
|
308 | $('<option />') | |||
|
309 | .html(items[index]) | |||
|
310 | .attr('value', items[index]) | |||
|
311 | .appendTo(this.$listbox) | |||
|
312 | .on('click', function(e){ | |||
|
313 | that.model.set('value', $(e.target).html(), this); | |||
|
314 | that.model.update_other_views(that); | |||
|
315 | }); | |||
|
316 | } | |||
|
317 | } | |||
|
318 | ||||
|
319 | // Select the correct element | |||
|
320 | this.$listbox.val(this.model.get('value')); | |||
|
321 | ||||
|
322 | // Disable listbox if needed | |||
|
323 | var disabled = this.model.get('disabled'); | |||
|
324 | this.$listbox.prop('disabled', disabled); | |||
|
325 | ||||
|
326 | // Remove items that no longer exist. | |||
|
327 | this.$listbox.find('option').each(function(i, obj) { | |||
|
328 | var value = $(obj).html(); | |||
|
329 | var found = false; | |||
|
330 | for (var index in items) { | |||
|
331 | if (items[index] == value) { | |||
|
332 | found = true; | |||
|
333 | break; | |||
|
334 | } | |||
|
335 | } | |||
|
336 | ||||
|
337 | if (!found) { | |||
|
338 | $(obj).remove(); | |||
|
339 | } | |||
|
340 | }); | |||
|
341 | ||||
|
342 | var description = this.model.get('description'); | |||
|
343 | if (description.length == 0) { | |||
|
344 | this.$label.hide(); | |||
|
345 | } else { | |||
|
346 | this.$label.html(description); | |||
|
347 | this.$label.show(); | |||
|
348 | } | |||
|
349 | return IPython.WidgetView.prototype.update.call(this); | |||
|
350 | }, | |||
|
351 | ||||
|
352 | }); | |||
|
353 | ||||
|
354 | widget_manager.register_widget_view('ListBoxView', ListBoxView); | |||
277 | }); |
|
355 | }); |
@@ -149,6 +149,12 b' The widget area typically looks something like this:' | |||||
149 | margin-bottom: 0px; |
|
149 | margin-bottom: 0px; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
|
152 | /* Listbox */ | |||
|
153 | .widget-listbox { | |||
|
154 | width: 364px; | |||
|
155 | margin-bottom: 0px; | |||
|
156 | } | |||
|
157 | ||||
152 | /* Single Line Textbox - used for IntTextView and FloatTextView */ |
|
158 | /* Single Line Textbox - used for IntTextView and FloatTextView */ | |
153 | .widget-numeric-text { |
|
159 | .widget-numeric-text { | |
154 | width: 150px; |
|
160 | width: 150px; |
@@ -311,6 +311,7 b'' | |||||
311 | "| SelectionWidget | ToggleButtonsView |\n", |
|
311 | "| SelectionWidget | ToggleButtonsView |\n", | |
312 | "| | RadioButtonsView |\n", |
|
312 | "| | RadioButtonsView |\n", | |
313 | "| | *DropdownView* |\n", |
|
313 | "| | *DropdownView* |\n", | |
|
314 | "| | ListBoxView |\n", | |||
314 | "| StringWidget | LabelView |\n", |
|
315 | "| StringWidget | LabelView |\n", | |
315 | "| | TextAreaView |\n", |
|
316 | "| | TextAreaView |\n", | |
316 | "| | *TextBoxView* |\n" |
|
317 | "| | *TextBoxView* |\n" |
General Comments 0
You need to be logged in to leave comments.
Login now