source: [view]
if(!this._initialized){
return;
}
var children = this.getChildren();
var childIds = {};
var _this = this;
function addCustomClass(node, type, count) {
if(_this.customClass != "") {
var clazz = _this.customClass+ "-" + (type || node.tagName.toLowerCase());
dojo.addClass(node, clazz);
if(arguments.length > 2) {
dojo.addClass(node, clazz + "-" + count);
}
}
}
// Find any new children that have been added since the last layout() call
dojo.forEach(this._children, dojo.hitch(this, function(child){
childIds[child.id] = child;
}));
dojo.forEach(children, dojo.hitch(this, function(child, index){
if(!childIds[child.id]) {
// Add pre-existing children to the start of the array
this._children.push(child);
}
}));
// Create the table. It fills the width of it's container.
var table = dojo.create("table", {
"width": "100%",
"class": "tableContainer-table tableContainer-table-" + this.orientation,
"cellspacing" : this.spacing
},
this.domNode);
var tbody = dojo.create("tbody");
table.appendChild(tbody);
addCustomClass(table, "table", this.orientation);
var width = Math.floor(100 / this.cols) + "%";
var labelRow = dojo.create("tr", {}, tbody);
var childRow = (!this.showLabels || this.orientation == "horiz")
? labelRow : dojo.create("tr", {}, tbody);
var maxCols = this.cols * (this.showLabels ? 2 : 1);
var numCols = 0;
// Iterate over the children, adding them to the table.
dojo.forEach(this._children, dojo.hitch(this, function(child, index){
var colspan = child.colspan || 1;
if(colspan > 1) {
colspan = this.showLabels ?
Math.min(maxCols - 1, colspan * 2 -1): Math.min(maxCols, colspan);
}
// Create a new row if we need one
if(numCols + colspan - 1 + (this.showLabels ? 1 : 0)>= maxCols) {
numCols = 0;
labelRow = dojo.create("tr", {}, tbody);
childRow = this.orientation == "horiz" ? labelRow : dojo.create("tr", {}, tbody);
}
var labelCell;
// If labels should be visible, add them
if(this.showLabels) {
labelCell = dojo.create("td", {"class": "tableContainer-labelCell"}, labelRow);
// If the widget should take up both the label and value,
// then just set the class on it.
if(child.spanLabel) {
dojo.attr(labelCell, this.orientation == "vert" ? "rowspan" : "colspan", 2);
}
else {
// Add the custom label class to the label cell
addCustomClass(labelCell, "labelCell");
var labelProps = {"for": child.get("id")};
var label = dojo.create("label", labelProps, labelCell);
if(Number(this.labelWidth) > -1 ||
String(this.labelWidth).indexOf("%") > -1) {
// Set the width of the label cell with either a pixel or percentage value
dojo.style(labelCell, "width",
String(this.labelWidth).indexOf("%") < 0
? this.labelWidth + "px" : this.labelWidth);
}
label.innerHTML = child.get("label") || child.get("title");
}
}
var childCell;
if(child.spanLabel && labelCell) {
childCell = labelCell;
} else {
childCell = dojo.create("td", {
"class" : "tableContainer-valueCell"
}, childRow);
}
if(colspan > 1) {
dojo.attr(childCell, "colspan", colspan);
}
// Add the widget cell's custom class, if one exists.
addCustomClass(childCell, "valueCell", index);
childCell.appendChild(child.domNode);
numCols += colspan + (this.showLabels ? 1 : 0);
}));
if(this.table) {
this.table.parentNode.removeChild(this.table);
}
// Refresh the layout of any child widgets, allowing them to resize
// to their new parent.
dojo.forEach(children, function(child){
if(typeof child.layout == "function") {
child.layout();
}
});
this.table = table;
this.resize();