1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary Label decorator 5 */ 6 7 goog.provide('Banana.Controls.Decorators.LabelDecorator'); 8 9 /** @namespace Banana.Controls.Decorators.LabelDecorator */ 10 namespace('Banana.Controls.Decorators').LabelDecorator = Banana.Controls.Decorators.Decorator.extend( 11 /** @lends Banana.Controls.Decorators.LabelDecorator.prototype */ 12 { 13 /** 14 * decorates a custom control with a label 15 * 16 * @param {Banana.UiControl} customControl 17 * @constructs 18 * @extends Banana.Controls.Decorators.Decorator 19 */ 20 init : function(customControl) 21 { 22 this._super(customControl); 23 24 this.customControl = customControl; 25 this.customControl.addCssClass('BLabelDecoratedControl'); 26 this.addCssClass('BLabelDecorator'); 27 this.label = new Banana.Controls.Label().addCssClass('BLabelDecoratorLabel'); 28 this.position = 'left'; 29 this.addControl(this.label); 30 this.addControl(customControl); 31 32 //when custom control becomes visible or invisible so does this control 33 customControl.bind('onSetVisible',this.getProxy(this.onSetVisible)); 34 }, 35 36 /** 37 * Invoked when setVisible is called 38 * @param {Event} event 39 * @param {Mixed} data 40 */ 41 onSetVisible : function(event,data) 42 { 43 this.setVisible(data); 44 }, 45 46 /** 47 * @override 48 */ 49 updateDisplay : function() 50 { 51 this._super(); 52 this.label.setForControl(this.customControl); 53 }, 54 55 /** 56 * Sets style on label 57 * @param {Object} css 58 */ 59 setLabelCss : function(css) 60 { 61 this.label.setCss(css); 62 return this; 63 }, 64 65 /** 66 * sets data which will be set on the label 67 * 68 * @param {String} d 69 * @return {this} 70 */ 71 setData : function(d) 72 { 73 this.label.setData(d); 74 return this; 75 }, 76 77 /** 78 * returns data text of label; 79 * 80 * @return {String} 81 */ 82 getData : function() 83 { 84 return this.label.getData(); 85 } 86 87 });