fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.7 KiB

8 years ago
/**
* td布局
* @class BI.TdLayout
* @extends BI.Layout
*/
BI.TdLayout = BI.inherit(BI.Layout, {
8 years ago
props: function () {
return BI.extend(BI.TdLayout.superclass.props.apply(this, arguments), {
8 years ago
baseCls: "bi-td-layout",
columnSize: [200, 200, 200],
hgap: 0,
vgap: 0,
items: [[
{
7 years ago
el: {text: "label1"}
8 years ago
},
{
7 years ago
el: {text: "label2"}
8 years ago
},
{
7 years ago
el: {text: "label3"}
8 years ago
}
]]
});
},
8 years ago
render: function () {
BI.TdLayout.superclass.render.apply(this, arguments);
7 years ago
this.$table = $("<table>").attr({cellspacing: 0, cellpadding: 0}).css({
position: "relative",
width: "100%",
height: "100%",
8 years ago
"border-spacing": "0px",
7 years ago
border: "none",
8 years ago
"border-collapse": "separate"
8 years ago
});
8 years ago
this.rows = 0;
this.populate(this.options.items);
},
_addElement: function (idx, arr) {
var o = this.options;
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);
}
}
var tr = BI.createWidget({
type: "bi.default",
tagName: "tr"
7 years ago
});
8 years ago
for (var i = 0; i < arr.length; i++) {
7 years ago
var w = BI.createWidget(arr[i]);
7 years ago
w.element.css({position: "relative", top: "0", left: "0", margin: "0px auto"});
8 years ago
if (arr[i].lgap) {
w.element.css({"margin-left": arr[i].lgap + "px"});
}
if (arr[i].rgap) {
w.element.css({"margin-right": arr[i].rgap + "px"});
}
if (arr[i].tgap) {
w.element.css({"margin-top": arr[i].tgap + "px"});
}
if (arr[i].bgap) {
w.element.css({"margin-bottom": arr[i].bgap + "px"});
}
8 years ago
first(w, this.rows++, i);
var td = BI.createWidget({
7 years ago
type: "bi.default",
8 years ago
attributes: {
width: o.columnSize[i] <= 1 ? (o.columnSize[i] * 100 + "%") : o.columnSize[i]
},
7 years ago
tagName: "td",
8 years ago
items: [w]
7 years ago
});
8 years ago
td.element.css({
7 years ago
position: "relative",
8 years ago
"vertical-align": "middle",
7 years ago
margin: "0",
padding: "0",
border: "none"
8 years ago
});
tr.addItem(td);
}
8 years ago
this.addWidget(this.getName() + idx, tr);
8 years ago
return tr;
},
8 years ago
_mountChildren: function () {
8 years ago
var self = this;
var frag = document.createDocumentFragment();
var hasChild = false;
BI.each(this._children, function (i, widget) {
if (widget.element !== self.element) {
frag.appendChild(widget.element[0]);
hasChild = true;
}
});
if (hasChild === true) {
this.$table.append(frag);
this.element.append(this.$table);
}
},
8 years ago
resize: function () {
// console.log("td布局不需要resize");
},
addItem: function (arr) {
if (!BI.isArray(arr)) {
8 years ago
throw new Error("item must be array");
8 years ago
}
return BI.TdLayout.superclass.addItem.apply(this, arguments);
},
populate: function (items) {
BI.TdLayout.superclass.populate.apply(this, arguments);
8 years ago
this._mount();
8 years ago
}
});
7 years ago
BI.shortcut("bi.td", BI.TdLayout);