fineui是帆软报表和BI产品线所使用的前端框架。

137 lines
4.8 KiB

8 years ago
/**
* 分隔容器的控件按照宽度和高度所占比平分整个容器
*
* @class BI.DivisionLayout
* @extends BI.Layout
*/
BI.DivisionLayout = BI.inherit(BI.Layout, {
8 years ago
props: function () {
return BI.extend(BI.DivisionLayout.superclass.props.apply(this, arguments), {
4 years ago
baseCls: "bi-division",
8 years ago
columns: null,
rows: null,
items: []
});
},
8 years ago
render: function () {
BI.DivisionLayout.superclass.render.apply(this, arguments);
8 years ago
this.populate(this.options.items);
},
addItem: function (item) {
// do nothing
throw new Error("不能添加子组件");
8 years ago
},
7 years ago
stroke: function (items) {
8 years ago
var o = this.options;
var rows = o.rows || o.items.length, columns = o.columns || ((o.items[0] && o.items[0].length) | 0);
var map = BI.makeArray(rows), widths = {}, heights = {};
6 years ago
7 years ago
function firstElement (item, row, col) {
8 years ago
if (row === 0) {
7 years ago
item.addClass("first-row");
8 years ago
}
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");
}
7 years ago
function firstObject (item, row, col) {
8 years ago
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";
}
7 years ago
function first (item, row, col) {
8 years ago
if (item instanceof BI.Widget) {
firstElement(item.element, row, col);
} else if (item.el instanceof BI.Widget) {
firstElement(item.el.element, row, col);
} else if (item.el) {
7 years ago
firstObject(item.el, row, col);
8 years ago
} else {
firstObject(item, row, col);
}
}
6 years ago
8 years ago
BI.each(map, function (i) {
map[i] = BI.makeArray(columns);
});
BI.each(items, function (i, item) {
if (BI.isArray(item)) {
BI.each(item, function (j, el) {
widths[i] = (widths[i] || 0) + item.width;
heights[j] = (heights[j] || 0) + item.height;
map[i][j] = el;
});
return;
}
widths[item.row] = (widths[item.row] || 0) + item.width;
heights[item.column] = (heights[item.column] || 0) + item.height;
map[item.row][item.column] = item;
});
for (var i = 0; i < rows; i++) {
var totalW = 0;
for (var j = 0; j < columns; j++) {
if (!map[i][j]) {
throw new Error("item(" + i + "" + j + ") 必须", map);
8 years ago
}
if (!this.hasWidget(this._getChildName(i + "_" + j))) {
5 years ago
var w = BI._lazyCreateWidget(map[i][j]);
this.addWidget(this._getChildName(i + "_" + j), w);
8 years ago
} else {
w = this.getWidgetByName(this._getChildName(i + "_" + j));
8 years ago
}
var left = totalW * 100 / widths[i];
7 years ago
w.element.css({position: "absolute", left: left + "%"});
8 years ago
if (j > 0) {
var lastW = this.getWidgetByName(this._getChildName(i + "_" + (j - 1)));
7 years ago
lastW.element.css({right: (100 - left) + "%"});
8 years ago
}
if (j == o.columns - 1) {
7 years ago
w.element.css({right: "0%"});
8 years ago
}
first(w, i, j);
totalW += map[i][j].width;
}
}
for (var j = 0; j < o.columns; j++) {
var totalH = 0;
for (var i = 0; i < o.rows; i++) {
var w = this.getWidgetByName(this._getChildName(i + "_" + j));
8 years ago
var top = totalH * 100 / heights[j];
7 years ago
w.element.css({top: top + "%"});
8 years ago
if (i > 0) {
var lastW = this.getWidgetByName(this._getChildName((i - 1) + "_" + j));
7 years ago
lastW.element.css({bottom: (100 - top) + "%"});
8 years ago
}
if (i == o.rows - 1) {
7 years ago
w.element.css({bottom: "0%"});
8 years ago
}
totalH += map[i][j].height;
}
}
},
4 years ago
update: function (opt) {
return this.forceUpdate(opt);
6 years ago
},
8 years ago
populate: function (items) {
BI.DivisionLayout.superclass.populate.apply(this, arguments);
8 years ago
this._mount();
8 years ago
}
});
5 years ago
BI.shortcut("bi.division", BI.DivisionLayout);