jsm

net/sf/jsm/table/jsmTd.js

Summary

No overview generated for 'net/sf/jsm/table/jsmTd.js'


Class Summary
JsmTd A table data cell

  
/**
 * A table data cell
 * @extends JsmCell
 * @class A table data cell
 * @param value Optional: The value can be a string or an object with a getNode() method
 * @param title Optional: The title 
 * @constructor
 */      
  function JsmTd(value, title) {
    /** @ignore */  
  	this.id=new Date().getTime() + "" + Math.random();   
  	logger.info("Created JsmTd with id: " + this.id);  	
  	/** Indicates if the value of this cell has been changed 
  	* @type boolean
  	* @private
  	*/     	
  	this._dirty=false;	
    /** @ignore */       
    this.value = jsm.noud(value)?"":value;
    /** @ignore */       
    this.title = jsm.noud(title)?value:title;       	   	
  }
  JsmTd.extendClass(JsmCell);
  /** @ignore */    
  JsmTd.prototype.className="JsmTd";
  
  /** Sets the dirty flag; if set to true will propagate this to the parent row; if set to false will check if 
  * other the other cells of parent row are also clean and propagate this to the parent row
  * @param {boolean} dirty
  * @param {boolean} propagateToParent Should the change be propagated to the parent row 
  * @return this
  */   
  JsmTd.prototype.setDirty = function(dirty, propagateToParent) {
    logger.debug("Reset the dirty flag for cell: " + this);    
  	propagateToParent = jsm.noud(propagateToParent)?true:propagateToParent;
  	this._dirty = dirty;
  	//propagate dirty-flag to parent row
  	if (!jsm.noud(this.tr) && propagateToParent) {
	  	if (dirty) {
	  		this.tr.setDirty(dirty);
	  	} else {
	  		var allTdsClean = true;
			var tds = this.tr.getCells();
	  		for (var tdIdx=0;tdIdx<tds.length;tdIdx++) {
			  	var td = tds[tdIdx];
			  	if (td.isDirty()) {
			  		allTdsClean=false;
			  		break;
			  	}
		  	} 
		  	this.tr.setDirty(!allTdsClean); 		
	  	}
  	}	
  	return this;
  }
  
  /** 
  * @return {boolean} Value of the dirty flag
  */      
  JsmTd.prototype.isDirty = function() {
  	return this._dirty;
  }  
  
  /** Get the node object; the model (this) will be attached to the node as property 'model'
  * @param specialClassName The name of the special style class  
  * @param jsmRowType The value of the meta data 'jsmRowType' of the td's row   
  * @return The created node object
  */       
  JsmTd.prototype.getNode = function(specialClassName, jsmRowType) {
  	var td = document.createElement("td"); 
  	td.setAttribute("id", this.id);  
  	td.model=this;  		 
  	this.addAttributesToViewComponent(td); 
  	//add default class 'jsmEven' or 'jsmOdd'
  	if (jsm.noud(this.getAttribute('className'))) {
		td.className=specialClassName;
  	} else {
		td.className=this.getAttribute('className') + ' ' + specialClassName;  	
  	}	
  	td.onclick=_jsmOnClickEventDelegate;
  	td.onmousedown=_jsmOnMouseDownEventDelegate;
  	this.setAttribute("onmousedown", "if (!e) e=window.event; jsm.resizeColumn=" + this.getIndex() + "; jsm.resize=true; jsm.resizeStartX=e.screenX;");
	td.onmouseup=_jsmOnMouseUpEventDelegate;
  	this.setAttribute("onmouseup", "jsm.resize=false; jsm.resizeColumn=-1; jsm.resizeOriginalWidth=-1;");		
  	td.setAttribute("title", this.title);
  	//add content
  	if (this.tr.isEditMode() && !jsm.noud(this.tr.table._columnIdx2Widget[this.idx])) {
		logger.debug('JsmTd: getNode: Row ' + this.tr.idx + ' is in edit mode');  	
	  	var theWidget = this.tr.table._columnIdx2Widget[this.idx];
	  	theWidget.init(this);
	  	var theNode = theWidget.getNode(); 	  	
		jsmHangOntoSelectedWidgetNodes(theNode); 		
  		td.appendChild(theNode);	   		
  	} else {
	  	logger.debug('JsmTd: getNode: typeof: ' + typeof this.value);
	  	if (typeof this.value == 'string') {
		  	if (this.value.indexOf('%{') == 0) {
		  		var expression = this.value.substring(2, this.value.length-1);
		  		td.innerHTML=eval(expression);
		  	} else {
			  	td.innerHTML = this.value;  	
		  	}		  	
	  	}
	  	if (typeof this.value == 'object') {
	  		var theNode = this.value.getNode();
	  		jsmHangOntoSelectedWidgetNodes(theNode);
		  	td.appendChild(theNode);
	  	} 
  	} 	
  	return td;
  }  
  
  

jsm

Documentation generated by JSDoc on Tue Sep 26 08:42:57 2006