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