|
|
@ -16,7 +16,7 @@ BI.TableLayout = BI.inherit(BI.Layout, { |
|
|
|
// rowSize: 30, // or [30,30,30]
|
|
|
|
// rowSize: 30, // or [30,30,30]
|
|
|
|
hgap: 0, |
|
|
|
hgap: 0, |
|
|
|
vgap: 0, |
|
|
|
vgap: 0, |
|
|
|
items: [] |
|
|
|
items: [], |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
render: function () { |
|
|
|
render: function () { |
|
|
@ -45,57 +45,43 @@ BI.TableLayout = BI.inherit(BI.Layout, { |
|
|
|
return self._optimiseGap(size); |
|
|
|
return self._optimiseGap(size); |
|
|
|
}).join(" ") : BI.range(o.items.length).fill(this._optimiseGap(o.rowSize)).join(" "), |
|
|
|
}).join(" ") : BI.range(o.items.length).fill(this._optimiseGap(o.rowSize)).join(" "), |
|
|
|
"grid-row-gap": this._optimiseGap(o.vgap), |
|
|
|
"grid-row-gap": this._optimiseGap(o.vgap), |
|
|
|
"grid-column-gap": this._optimiseGap(o.hgap) |
|
|
|
"grid-column-gap": this._optimiseGap(o.hgap), |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
type: "bi.default", |
|
|
|
type: "bi.default", |
|
|
|
ref: function (_ref) { |
|
|
|
ref: function (_ref) { |
|
|
|
self.layout = _ref; |
|
|
|
self.layout = _ref; |
|
|
|
}, |
|
|
|
}, |
|
|
|
items: this._formatItems(items) |
|
|
|
items: this._formatItems(items), |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_formatItems: function (items) { |
|
|
|
_formatItems: function (items) { |
|
|
|
var o = this.options; |
|
|
|
var o = this.options, self = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function firstElement (item, cls) { |
|
|
|
|
|
|
|
item.addClass(cls); |
|
|
|
|
|
|
|
|
|
|
|
function firstElement (item, row, col) { |
|
|
|
|
|
|
|
if (row === 0) { |
|
|
|
|
|
|
|
item.addClass("first-row"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (col === 0) { |
|
|
|
|
|
|
|
item.addClass("first-col"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
item.addClass(BI.isOdd(row + 1) ? "odd-row" : "even-row"); |
|
|
|
|
|
|
|
item.addClass(BI.isOdd(col + 1) ? "odd-col" : "even-col"); |
|
|
|
|
|
|
|
item.addClass("center-element"); |
|
|
|
|
|
|
|
return item; |
|
|
|
return item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function firstObject (item, row, col) { |
|
|
|
function firstObject (item, cls) { |
|
|
|
var cls = ""; |
|
|
|
item.cls = (item.cls || "") + cls; |
|
|
|
if (row === 0) { |
|
|
|
|
|
|
|
cls += " first-row"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (col === 0) { |
|
|
|
|
|
|
|
cls += " first-col"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
BI.isOdd(row + 1) ? (cls += " odd-row") : (cls += " even-row"); |
|
|
|
|
|
|
|
BI.isOdd(col + 1) ? (cls += " odd-col") : (cls += " even-col"); |
|
|
|
|
|
|
|
item.cls = (item.cls || "") + cls + " center-element"; |
|
|
|
|
|
|
|
return item; |
|
|
|
return item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function first (item, row, col) { |
|
|
|
function first (item, cls) { |
|
|
|
if (item instanceof BI.Widget) { |
|
|
|
if (item instanceof BI.Widget) { |
|
|
|
return firstElement(item.element, row, col); |
|
|
|
return firstElement(item.element, cls); |
|
|
|
} else if (item.el instanceof BI.Widget) { |
|
|
|
} else if (item.el instanceof BI.Widget) { |
|
|
|
return firstElement(item.el.element, row, col); |
|
|
|
return firstElement(item.el.element, cls); |
|
|
|
} else if (item.el) { |
|
|
|
} else if (item.el) { |
|
|
|
return firstObject(item.el, row, col); |
|
|
|
return firstObject(item.el, cls); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return firstObject(item, row, col); |
|
|
|
return firstObject(item, cls); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -105,18 +91,20 @@ BI.TableLayout = BI.inherit(BI.Layout, { |
|
|
|
columnSize: ["fill"], |
|
|
|
columnSize: ["fill"], |
|
|
|
horizontalAlign: o.horizontalAlign, |
|
|
|
horizontalAlign: o.horizontalAlign, |
|
|
|
verticalAlign: o.verticalAlign, |
|
|
|
verticalAlign: o.verticalAlign, |
|
|
|
items: [BI.formatEL(item)] |
|
|
|
items: [BI.formatEL(item)], |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return BI.reduce(items, function (row, result, i) { |
|
|
|
return BI.reduce(items, function (rowItems, result, rowIndex) { |
|
|
|
return result.concat(BI.map(row, function (j, item) { |
|
|
|
return result.concat(BI.map(rowItems, function (colIndex, item) { |
|
|
|
|
|
|
|
var cls = self.getRowColumnCls(rowIndex, colIndex, items.length - 1, rowItems.length - 1); |
|
|
|
if (BI.isEmpty(item)) { |
|
|
|
if (BI.isEmpty(item)) { |
|
|
|
return first(wrapLayout({ |
|
|
|
return first(wrapLayout({ |
|
|
|
type: "bi.layout" |
|
|
|
type: "bi.layout", |
|
|
|
}), i, j); |
|
|
|
}), cls); |
|
|
|
} |
|
|
|
} |
|
|
|
return first(wrapLayout(item), i, j); |
|
|
|
|
|
|
|
|
|
|
|
return first(wrapLayout(item), cls); |
|
|
|
})); |
|
|
|
})); |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -127,6 +115,6 @@ BI.TableLayout = BI.inherit(BI.Layout, { |
|
|
|
|
|
|
|
|
|
|
|
populate: function (items) { |
|
|
|
populate: function (items) { |
|
|
|
this.layout.populate(this._formatItems(items)); |
|
|
|
this.layout.populate(this._formatItems(items)); |
|
|
|
} |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI.shortcut("bi.table", BI.TableLayout); |
|
|
|
BI.shortcut("bi.table", BI.TableLayout); |
|
|
|