##// END OF EJS Templates
Partial updates of css and visible + simplification of widget_container
sylvain.corlay -
Show More
@@ -407,13 +407,15 b' define(["widgets/js/manager",'
407 407 var DOMWidgetView = WidgetView.extend({
408 408 initialize: function (options) {
409 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 410 DOMWidgetView.__super__.initialize.apply(this, arguments);
416 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 421 on_msg: function(msg) {
@@ -438,19 +440,18 b' define(["widgets/js/manager",'
438 440 this._get_selector_element(selector).removeClass(class_list);
439 441 },
440 442
441 update: function () {
442 // Update the contents of this view
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.
443 update_visible: function(model, value) {
444 // Update visibility
446 445 // The very first update seems to happen before the element is
447 446 // finished rendering so we use setTimeout to give the element time
448 447 // to render
449 448 var e = this.$el;
450 var visible = this.model.get('visible');
451 setTimeout(function() {e.toggle(visible);},0);
452
453 var css = this.model.get('_css');
449 setTimeout(function() {e.toggle(value);},0);
450 },
451
452 update_css: function (model, css) {
453 // Update the contents of this view
454 var e = this.$el;
454 455 if (css === undefined) {return;}
455 456 for (var i = 0; i < css.length; i++) {
456 457 // Apply the css traits to all elements that match the selector.
@@ -13,10 +13,9 b' define(['
13 13 this.$el.addClass('widget-container')
14 14 .addClass('vbox');
15 15 this.update_children([], this.model.get('children'));
16 this.model.on('change:children', function(model, value, options) {
16 this.model.on('change:children', function(model, value) {
17 17 this.update_children(model.previous('children'), value);
18 18 }, this);
19 this.update();
20 19 },
21 20
22 21 update_children: function(old_list, new_list) {
@@ -42,14 +41,6 b' define(['
42 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 154 this.popped_out = true;
164 155
165 156 this.update_children([], this.model.get('children'));
166 this.model.on('change:children', function(model, value, options) {
157 this.model.on('change:children', function(model, value) {
167 158 this.update_children(model.previous('children'), value);
168 159 }, this);
169 this.update();
170 160 },
171 161
172 162 hide: function() {
General Comments 0
You need to be logged in to leave comments. Login now