Show More
@@ -407,13 +407,15 b' define(["widgets/js/manager",' | |||||
407 | var DOMWidgetView = WidgetView.extend({ |
|
407 | var DOMWidgetView = WidgetView.extend({ | |
408 | initialize: function (options) { |
|
408 | initialize: function (options) { | |
409 | // Public constructor |
|
409 | // Public constructor | |
410 |
|
||||
411 | // In the future we may want to make changes more granular |
|
|||
412 | // (e.g., trigger on visible:change). |
|
|||
413 | this.model.on('change', this.update, this); |
|
|||
414 | this.model.on('msg:custom', this.on_msg, this); |
|
|||
415 | DOMWidgetView.__super__.initialize.apply(this, arguments); |
|
410 | DOMWidgetView.__super__.initialize.apply(this, arguments); | |
416 | this.on('displayed', this.show, this); |
|
411 | this.on('displayed', this.show, this); | |
|
412 | ||||
|
413 | this.model.on('msg:custom', this.on_msg, this); | |||
|
414 | this.model.on('change:visible', this.update_visible, this); | |||
|
415 | this.model.on('change:_css', this.update_css, this); | |||
|
416 | ||||
|
417 | this.update_visible(this.model, this.model.get("visible")); | |||
|
418 | this.update_css(this.model, this.model.get("_css")); | |||
417 | }, |
|
419 | }, | |
418 |
|
420 | |||
419 | on_msg: function(msg) { |
|
421 | on_msg: function(msg) { | |
@@ -438,19 +440,18 b' define(["widgets/js/manager",' | |||||
438 | this._get_selector_element(selector).removeClass(class_list); |
|
440 | this._get_selector_element(selector).removeClass(class_list); | |
439 | }, |
|
441 | }, | |
440 |
|
442 | |||
441 |
update: function |
|
443 | update_visible: function(model, value) { | |
442 |
// Update |
|
444 | // Update visibility | |
443 | // |
|
|||
444 | // Called when the model is changed. The model may have been |
|
|||
445 | // changed by another view or by a state update from the back-end. |
|
|||
446 | // The very first update seems to happen before the element is |
|
445 | // The very first update seems to happen before the element is | |
447 | // finished rendering so we use setTimeout to give the element time |
|
446 | // finished rendering so we use setTimeout to give the element time | |
448 | // to render |
|
447 | // to render | |
449 | var e = this.$el; |
|
448 | var e = this.$el; | |
450 | var visible = this.model.get('visible'); |
|
449 | setTimeout(function() {e.toggle(value);},0); | |
451 | setTimeout(function() {e.toggle(visible);},0); |
|
450 | }, | |
452 |
|
451 | |||
453 | var css = this.model.get('_css'); |
|
452 | update_css: function (model, css) { | |
|
453 | // Update the contents of this view | |||
|
454 | var e = this.$el; | |||
454 | if (css === undefined) {return;} |
|
455 | if (css === undefined) {return;} | |
455 | for (var i = 0; i < css.length; i++) { |
|
456 | for (var i = 0; i < css.length; i++) { | |
456 | // Apply the css traits to all elements that match the selector. |
|
457 | // Apply the css traits to all elements that match the selector. |
@@ -13,10 +13,9 b' define([' | |||||
13 | this.$el.addClass('widget-container') |
|
13 | this.$el.addClass('widget-container') | |
14 | .addClass('vbox'); |
|
14 | .addClass('vbox'); | |
15 | this.update_children([], this.model.get('children')); |
|
15 | this.update_children([], this.model.get('children')); | |
16 |
this.model.on('change:children', function(model, value |
|
16 | this.model.on('change:children', function(model, value) { | |
17 | this.update_children(model.previous('children'), value); |
|
17 | this.update_children(model.previous('children'), value); | |
18 | }, this); |
|
18 | }, this); | |
19 | this.update(); |
|
|||
20 | }, |
|
19 | }, | |
21 |
|
20 | |||
22 | update_children: function(old_list, new_list) { |
|
21 | update_children: function(old_list, new_list) { | |
@@ -42,14 +41,6 b' define([' | |||||
42 | view.trigger('displayed'); |
|
41 | view.trigger('displayed'); | |
43 | }); |
|
42 | }); | |
44 | }, |
|
43 | }, | |
45 |
|
||||
46 | update: function(){ |
|
|||
47 | // Update the contents of this view |
|
|||
48 | // |
|
|||
49 | // Called when the model is changed. The model may have been |
|
|||
50 | // changed by another view or by a state update from the back-end. |
|
|||
51 | return ContainerView.__super__.update.apply(this); |
|
|||
52 | }, |
|
|||
53 | }); |
|
44 | }); | |
54 |
|
45 | |||
55 |
|
46 | |||
@@ -163,10 +154,9 b' define([' | |||||
163 | this.popped_out = true; |
|
154 | this.popped_out = true; | |
164 |
|
155 | |||
165 | this.update_children([], this.model.get('children')); |
|
156 | this.update_children([], this.model.get('children')); | |
166 |
this.model.on('change:children', function(model, value |
|
157 | this.model.on('change:children', function(model, value) { | |
167 | this.update_children(model.previous('children'), value); |
|
158 | this.update_children(model.previous('children'), value); | |
168 | }, this); |
|
159 | }, this); | |
169 | this.update(); |
|
|||
170 | }, |
|
160 | }, | |
171 |
|
161 | |||
172 | hide: function() { |
|
162 | hide: function() { |
General Comments 0
You need to be logged in to leave comments.
Login now