1 /**
  2  * @author Gillis Haasnoot <gillis.haasnoot@gmail.com>
  3  * @package Banana.Controls
  4  * @summary Label control
  5  */
  6 
  7 goog.provide('Banana.Controls.DataControls.Label');
  8 
  9 goog.require('Banana.Controls.DataControls.DataControl');
 10 
 11 /** @namespace Banana.Controls.Label */
 12 namespace('Banana.Controls').Label = Banana.Controls.DataControl.extend(
 13 /** @lends Banana.Controls.Label.prototype */
 14 {
 15 	/**
 16 	 * Creates a label. Useful to display text only
 17 	 * @constructs
 18 	 * @extends Banana.Controls.DataControl
 19 	 */
 20 	init : function()
 21 	{
 22 		this._super();
 23 		this.addCssClass('BLabel');
 24 		this.tagName = 'label';
 25 	},
 26 	
 27 	/**
 28 	 * overwrite this function to prevent triggering the change event 
 29 	 * We do this to increase performance. we dont need the change event
 30 	 * We also add the data as a control. The reason for this is because the label control will be rendered first
 31 	 * without any data inside. then in the update display, data will be inserted. With many controls this insertion 
 32 	 * will be noticed in the gui rendering. To prevent this we make sure that the control will always render at once with data already inside
 33 	 *  
 34 	 *	@param {mixed} data for the label
 35 	 *	@param {boolean} ignoreEvent when true no datachanged is triggered. This is useful when you are running in a circle or performance issues
 36 	 *	@param {boolean} ignoreDom when true setDomData function is not called. Useful in cases of optimizing performance
 37 	 *  @return {this}
 38 	 */
 39 	setData : function(data,ignoreEvent,ignoreDom)
 40 	{
 41 		this._super(data,true,ignoreDom);
 42 	
 43 		this.addControl(data);
 44 		return this;
 45 	},
 46 	
 47 	/**
 48 	 * Sets tag name of the label. use this if you want to overwrite
 49 	 * the default label tag. for example. when you want to render images inside the label
 50 	 * @param {String} tag
 51 	 * @return {this}
 52 	 */
 53 	setTagName : function(tag)
 54 	{
 55 		this.tagName = tag;
 56 		return this;
 57 	},
 58 	
 59 	/**
 60 	 * @return {String}
 61 	 */
 62 	getTagName : function()
 63 	{
 64 		return this.tagName;
 65 	}
 66 });
 67 
 68 /**
 69  * Sets the control which belongs to the label. The result is that you can click on the label to focus the control
 70  * @param {Banana.Control} control
 71  */
 72 Banana.Controls.Label.prototype.setForControl = function(control)
 73 {
 74 	this.setAttribute('for',control.clientId);
 75 }
 76 
 77 /**
 78  * writes data to dom
 79  * @ignore
 80  * @param {String} data
 81  */
 82 Banana.Controls.Label.prototype.setDomData = function(data)
 83 {
 84 	if (this.isRendered)
 85 	{
 86 		if (data == undefined)
 87 		{
 88 			data = '';
 89 		}
 90 		
 91 		Banana.Util.DomHelper.setTextData(data,this)
 92 	}
 93 };