net/sf/jsm/table/jsmTr.js
Summary
No overview generated for 'net/sf/jsm/table/jsmTr.js'
Class Summary
|
JsmTr |
A table row
|
function JsmTr() {
this.id=new Date().getTime() + "" + Math.random();
logger.info("Created JsmTr with id: " + this.id);
this.table = null;
this.idx=-1;
this.editMode=false;
this.onClickFunctionName = "jsmOnTableRowClick";
this._cells = new Array();
for(var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] == 'object') this.addCell(arguments[i]);
}
this._actionCells = new Array();
this._dirty=false;
}
JsmTr.extendClass(JsmObject);
JsmTr.prototype.className="JsmTr";
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;
}
JsmTr.prototype.getTable = function() {
return this.table;
}
JsmTr.prototype.isEditMode = function() {
return this.editMode;
}
JsmTr.prototype.setEditMode = function(editMode) {
this.editMode = editMode;
return this;
}
JsmTr.prototype.getIndex = function() {
return this.idx;
}
JsmTr.prototype.setOnClick = function(functionName) {
this.onClickFunctionName = functionName;
return this;
}
JsmTr.prototype.getOnClick = function() {
return this.onClickFunctionName;
}
JsmTr.prototype.getCells = function() {
return this._cells;
}
JsmTr.prototype.getCell = function(columnIdxOrName) {
var columnIdx = isNaN(columnIdxOrName)?this.table.getColumnIdx(columnIdxOrName):columnIdxOrName;
return this._cells[columnIdx];
}
JsmTr.prototype.addCell = function(td) {
this._cells.push(td)
td.tr=this;
td.idx=this._cells.length-1;
return this;
}
JsmTr.prototype._addActionCell = function(cell) {
this._actionCells.push(cell)
cell.tr=this;
return this;
}
JsmTr.prototype.getActionCell = function(columnIdx) {
return this._actionCells[columnIdx];
}
JsmTr.prototype.getNode = function(specialClassName) {
var tr = document.createElement("tr");
tr.setAttribute("id", this.id);
tr.model=this;
this.addAttributesToViewComponent(tr);
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);
if ((this.getMetaData('jsmRowType') == 'header') && !this.handledGlobalActionCells) {
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;
}
if ((this.getMetaData('jsmRowType') == 'footer') && !this.handledGlobalActionCells) {
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;
}
if (!(this.getMetaData('jsmRowType') == 'header' || this.getMetaData('jsmRowType') == 'footer') && !this.handledRowActionCells) {
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;
}
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')));
}
}
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));
}
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;
}
JsmTr.prototype.setDirty = function(dirty, propagateToParent) {
logger.debug("Reset the dirty flag for row: " + this);
propagateToParent = jsm.noud(propagateToParent)?true:propagateToParent;
this._dirty = dirty;
if (!dirty) {
var tds = this.getCells();
for (var tdIdx=0;tdIdx<tds.length;tdIdx++) {
var td = tds[tdIdx];
td.setDirty(dirty, false);
}
}
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;
}
JsmTr.prototype.isDirty = function() {
return this._dirty;
}
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 + "'";
}
first=false;
}
}
retVal+="}"
return retVal;
}
JsmTr.prototype.getSortColumnValue = function() {
return this._cells[this.table.getSortColumn()].value;
}
Documentation generated by
JSDoc on Tue Sep 26 08:42:57 2006