jsm

net/sf/jsm/table/jsmTr.js

Summary

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


Class Summary
JsmTr A table row

  
/**
 * A table row
 * @extends JsmObject
 * @class A table row
 * @param cells Optional: Accepts JsmTd or JsmTh objects as arguments for which it will call addCell()
 * @constructor
 */     
  function JsmTr() {
    /** @ignore */   
  	this.id=new Date().getTime() + "" + Math.random();  
  	logger.info("Created JsmTr with id: " + this.id);  	
    /** The table this row is attached to; null if not yet assigned
    * @type JsmTable
    */         	
  	this.table = null; //the table object this row is attached to; null if not yet assigned
    /** The row index
    * @type int
    */         	  	
  	this.idx=-1;  //the row index is zero based
    /** Indicates if this row is in edit mode
    * @type boolean
    */  
    this.editMode=false; 
    /** The name of the function to call on click on a row; defaults to 'jsmOnTableRowClick'
    * @type String
    */            	  	
    this.onClickFunctionName = "jsmOnTableRowClick"; 
    /** Array of cells
    * @private
    * @type Array
    */    	  		
  	this._cells = new Array(); 	 
  	for(var i = 0; i < arguments.length; i++) {
  		if (typeof arguments[i] == 'object') this.addCell(arguments[i]);
  	}
    /** Array of actionCells
    * @private
    * @type Array
    */    	  		
  	this._actionCells = new Array();   	
  	/** Indicates that at least one cell of this row is dirty
  	* @type boolean
  	* @private
  	*/     	
  	this._dirty=false;	  	
  }
  JsmTr.extendClass(JsmObject);
  /** @ignore */    
  JsmTr.prototype.className="JsmTr";
  
  /** @ignore */     
  JsmTr.prototype.toString = function() {
  	var retVal = "[";
  	for (var tdIdx=0;tdIdx<this._cells.length;tdIdx++) {
  		retVal=retVal+this._cells[tdIdx];	
  	}
  	retVal=retVal+"]\n"
  	return retVal;
  }       
 
   /** 
  * @return {JsmTable} The table this row is attached to
  */      
  JsmTr.prototype.getTable = function() {
  	return this.table;  	
  }  
  
  /** Is this row in edit mode
  * @return {boolean} 
  */      
  JsmTr.prototype.isEditMode = function() {
  	return this.editMode;  	
  } 
  
  /** Set the edit mode flag of this row
  * @param {boolean}  editMode
  * @return this
  */      
  JsmTr.prototype.setEditMode = function(editMode) {
  	this.editMode = editMode;  	
  	return this;
  }    
  
  
  /** Return the row index
  * @return {int} The row index of this row; -1 if not attached to a table 
  */      
  JsmTr.prototype.getIndex = function() {
  	return this.idx;  	
  }       
  
  /** Sets the name of the function to call on click on a row.
  * Will be called instead of default function: jsmOnTableRowClick(table, rowIdx).
  * The parameters table, rowIdx will be the arguments of the function.
  * @param {String} functionName
  * @return this
  */       
  JsmTr.prototype.setOnClick = function(functionName) {
  	this.onClickFunctionName = functionName;
  	return this;
  }  
  
  /** 
  * @return {String} The name of the function to call on click on a row.
  */     
  JsmTr.prototype.getOnClick = function() {
  	return this.onClickFunctionName;
  }    
  
  /** Return the cells of the row
  * @return {Array}
  */    
  JsmTr.prototype.getCells = function() {
  	return this._cells;  	
  } 

  /** Return the cell
  * @param columnIdxOrName The column idx or name
  * @return {JsmTd} 
  */      
  JsmTr.prototype.getCell = function(columnIdxOrName) {
    var columnIdx = isNaN(columnIdxOrName)?this.table.getColumnIdx(columnIdxOrName):columnIdxOrName;
  	return this._cells[columnIdx];  	
  }      
  
  /** Add the cell
  * @param {JsmTd} td 
  * @return this
  */        
  JsmTr.prototype.addCell = function(td) {
  	this._cells.push(td)
  	td.tr=this;
  	td.idx=this._cells.length-1;
  	return this;
  }
  
  /** Add an action cell
  * @param {JsmCell} cell 
  * @private  
  * @return this
  */        
  JsmTr.prototype._addActionCell = function(cell) {
  	this._actionCells.push(cell)
  	cell.tr=this;
  	return this;
  }  
  
  /** Return the action cell
  * @param {int} columnIdx The column idx
  * @return {JsmActionCell} 
  */      
  JsmTr.prototype.getActionCell = function(columnIdx) {
  	return this._actionCells[columnIdx];  	
  }  
  
  /** 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
  * @return The created node object
  */  
  JsmTr.prototype.getNode = function(specialClassName) {
	  	var tr = document.createElement("tr");
	  	tr.setAttribute("id", this.id);
	  	tr.model=this;  	
	  	this.addAttributesToViewComponent(tr); 
	  	//add default class 'jsmEven' or 'jsmOdd' or 'jsmFooter' or 'jsmHeader'
	  	if (this.getMetaData('jsmRowType') == 'header') {specialClassName='jsmHeader';}
	  	if (this.getMetaData('jsmRowType') == 'footer') {specialClassName='jsmFooter';}	  	
	  	
	  	if (jsm.noud(this.getAttribute('className'))) {  	
			tr.className=(specialClassName);
	  	} else {
			tr.className=this.getAttribute('className') + ' ' + specialClassName;  	
	  	}	
	  	tr.onclick=_jsmOnClickEventDelegate;
	  	
	  	var actionCellCount = this.table._headerActionCells.length > this.table._rowActionCells.length?(this.table._headerActionCells.length>this.table._headerActionCells.length?this.table._headerActionCells.length:this.table._footerActionCells.length):(this.table._rowActionCells.length>this.table._footerActionCells.length?this.table._rowActionCells.length:this.table._footerActionCells.length);
		//handle HEADER ACTION CELLS 
		if ((this.getMetaData('jsmRowType') == 'header') && !this.handledGlobalActionCells) {
		  	//fill up with empty Ths if there are more rowActionCells
		  	for (i=this.table._headerActionCells.length;i<actionCellCount;i++) {		  	
				this._addActionCell(new JsmTh(" "));	  			  	
		  	}			
			for (var headerActionCellIdx=0;headerActionCellIdx<this.table._headerActionCells.length;headerActionCellIdx++) {
				var th = this.table._headerActionCells[headerActionCellIdx];
				this._addActionCell(th);
		  	}	
			this.handledGlobalActionCells=true;
		}
		
		//handle FOOTER ACTION CELLS 
		if ((this.getMetaData('jsmRowType') == 'footer') && !this.handledGlobalActionCells) {
		  	//fill up with empty Tds if there are more rowActionCells
		  	for (var i=this.table._footerActionCells.length;i<actionCellCount;i++) {		  	
				this._addActionCell(new JsmTd(" "));	  			  	
		  	}			
			for (var footerActionCellIdx=0;footerActionCellIdx<this.table._footerActionCells.length;footerActionCellIdx++) {
				var td = this.table._footerActionCells[footerActionCellIdx];
				this._addActionCell(td);
		  	}	
			this.handledGlobalActionCells=true;
		}				
		
		//handle ROW ACTION CELLS (if this is a data row)
		if (!(this.getMetaData('jsmRowType') == 'header' || this.getMetaData('jsmRowType') == 'footer') && !this.handledRowActionCells) {
		  	//fill up with empty Tds if there is more global action Tds
		  	for (var i=this.table._rowActionCells.length;i<actionCellCount;i++) {
				this._addActionCell(new JsmTd(" "));	  			  	
		  	}			
			for (var rowActionCellIdx=0;rowActionCellIdx<this.table._rowActionCells.length;rowActionCellIdx++) {
				var td = this.table._rowActionCells[rowActionCellIdx].clone();
				this._addActionCell(td);
		  	}				  	
			this.handledRowActionCells=true;
		}							  	

		//action cells
		if (this.table.getActionCellSide()=='left') {
		  	for (var tdIdx=0;tdIdx<this._actionCells.length;tdIdx++) {
		  		var cell = this._actionCells[tdIdx];
			  	logger.debug("jsmTr: getNode: Call init() for actionCell: " + cell);
				try {cell.init(this.table, this.idx, tdIdx)}catch(e){};
			  	tr.appendChild(cell.getNode(specialClassName, this.getMetaData('jsmRowType')));
		  	} 
	  	}

	  	//normal cells
	  	for (var tdIdx=0;tdIdx<this._cells.length;tdIdx++) {
	  		var cell = this._cells[tdIdx];		  	
		  	logger.debug("jsmTr: getNode: cell: " + cell);	 	  	 		
		  	tr.appendChild(cell.getNode(specialClassName));  		
	  	} 
	  	
		//action cells
		if (this.table.getActionCellSide()!='left') {
		  	for (var tdIdx=0;tdIdx<this._actionCells.length;tdIdx++) {
		  		var cell = this._actionCells[tdIdx];
			  	logger.debug("jsmTr: getNode: Call init() for actionCell: " + cell);
				try {cell.init(this.table, this.idx, tdIdx)}catch(e){};
			  	tr.appendChild(cell.getNode(specialClassName, this.getMetaData('jsmRowType')));
		  	} 
	  	}	  	
	  	
	  	return tr;
  }
  
  /** Sets the dirty flag; if set to true will propagate this to the parent table; if set to false will check if 
  * other the other rows of parent table are also clean and propagate this to the parent table; if set to false 
  * will propagate this to the child cells
  * @param {boolean} dirty
  * @param {boolean} propagateToParent Should the change be propagated to the parent table   
  * @return this
  */   
  JsmTr.prototype.setDirty = function(dirty, propagateToParent) {
    logger.debug("Reset the dirty flag for row: " + this);  
  	propagateToParent = jsm.noud(propagateToParent)?true:propagateToParent;    
  	this._dirty = dirty;
  	//propagate cleanness of row to cells
  	if (!dirty) { 
	  var tds = this.getCells();
	  for (var tdIdx=0;tdIdx<tds.length;tdIdx++) {
	  	var td = tds[tdIdx];
	  	td.setDirty(dirty, false);
	  } 
	} 
  	//propagate dirty-flag to parent table
  	if (!jsm.noud(this.table) && propagateToParent) {
	  	if (dirty) {
	  		this.table.setDirty(dirty);
	  	} else {
	  		var allRowsClean = true;
		  	var rows = this.table.getRows();
		  	for (var rowIdx=0;rowIdx<rows.length;rowIdx++) {
		  		var row = rows[rowIdx];
		  		if (row.isDirty()) {
			  		allRowsClean=false;
			  		break;
			  	}
		  	} 
		  	this.table.setDirty(!allRowsClean); 		
	  	}
  	}	 
	return this;  
  }
  
  /** 
  * @return {boolean} Value of the dirty flag
  */      
  JsmTr.prototype.isDirty = function() {
  	return this._dirty;
  }
  
  /** 
  * Creates and returns a JSON expression of cell values. The key will be the meta data
  * 'META_DATA_NAME_PROPERTY_PATH'  or the column name if the meta data is not specified.<br>
  * The value will be the meta data 'META_DATA_NAME_VALUE' or the value if the meta data is not specified.
  * @param onlyDirty {boolean} (Optional) Will only include data from cells marked as dirty
  * @return {String} The JSON representation of this rows data
  */      
  JsmTr.prototype.getJSONized = function(onlyDirty) {
  	var retVal = "{";
  	var first = true;  	  	
  	for(var i = 0;i<this._cells.length;i++) {
  		var cell = this._cells[i];
  		if (!onlyDirty || cell.isDirty()) {
  			var key = this.table.getPropertyPath(cell.getIndex());
  			if (jsm.noud(key)) key = this.table.getColumnName(i);
  			key = key.replace(/'/g, "\\'");
  			var value = cell.getMetaData(this.META_DATA_NAME_VALUE);
  			if (jsm.noud(value)) value = cell.getValue();  			  			
	  		retVal+=(first?"'":",'") + key + "':";
	  		if (value.match(/^\[.*\]$/)) {
	  			retVal+=value;//it is json-array
	  		} else {
		  		value = value.replace(/'/g, "\\'");
		  		retVal+="'" + value + "'";//it is a string
	  		}
	  		first=false;
	  	}
  	}
  	retVal+="}"
  	return retVal;
  }  
  
  /** Returns the value of the current sort column
  * @return {String} The value of the current sort column
  */
  JsmTr.prototype.getSortColumnValue = function() {
	  return this._cells[this.table.getSortColumn()].value;
  }     

jsm

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