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.

138 lines
3.6 KiB

8 years ago
/**
* 布局容器类
* @class BI.Layout
* @extends BI.Widget
*
* @cfg {JSON} options 配置属性
* @cfg {Boolean} [options.scrollable=false] 子组件超出容器边界之后是否会出现滚动条
* @cfg {Boolean} [options.scrollx=false] 子组件超出容器边界之后是否会出现横向滚动条
* @cfg {Boolean} [options.scrolly=false] 子组件超出容器边界之后是否会出现纵向滚动条
*/
BI.Layout = BI.inherit(BI.Widget, {
8 years ago
props: function () {
return {
8 years ago
scrollable: null, //true, false, null
scrollx: false, //true, false
scrolly: false, //true, false
items: []
8 years ago
};
8 years ago
},
8 years ago
created: function () {
8 years ago
this._init4Margin();
this._init4Scroll();
},
_init4Margin: function () {
if (this.options.top) {
this.element.css('top', this.options.top);
}
if (this.options.left) {
this.element.css('left', this.options.left);
}
if (this.options.bottom) {
this.element.css('bottom', this.options.bottom);
}
if (this.options.right) {
this.element.css('right', this.options.right);
}
},
_init4Scroll: function () {
switch (this.options.scrollable) {
case true:
this.element.css("overflow", "auto");
break;
case false:
this.element.css("overflow", "hidden");
break;
default :
break;
}
if (this.options.scrollx) {
this.element.css({
"overflow-x": "auto",
"overflow-y": "hidden"
});
}
if (this.options.scrolly) {
this.element.css({
"overflow-x": "hidden",
"overflow-y": "auto"
});
}
},
_addElement: function (i, item) {
var o = this.options;
var w;
8 years ago
if (!this.hasWidget(this.getName() + "-" + i)) {
8 years ago
w = BI.createWidget(item);
8 years ago
this.addWidget(this.getName() + "-" + i, w);
8 years ago
} else {
8 years ago
w = this.getWidgetByName(this.getName() + "-" + i);
8 years ago
}
return w;
},
stroke: function (items) {
var self = this;
BI.each(items, function (i, item) {
if (!!item) {
self._addElement(i, item);
}
});
},
populate: function (items) {
var self = this;
this.options.items = items || [];
8 years ago
this.stroke(items);
8 years ago
},
resize: function () {
},
/**
* 添加一个子组件到容器中
* @param {JSON/BI.Widget} item 子组件
*/
addItem: function (item) {
var w = this._addElement(this.options.items.length, item);
8 years ago
w._mount();
8 years ago
this.options.items.push(item);
w.element.appendTo(this.element);
return w;
},
addItems: function (items) {
var self = this;
BI.each(items, function (i, item) {
self.addItem(item);
})
},
8 years ago
getValue: function () {
8 years ago
var value = [];
8 years ago
BI.each(this._children, function (i, wi) {
var v = wi.getValue();
8 years ago
v = BI.isArray(v) ? v : [v];
value = value.concat(v);
});
return value;
},
8 years ago
setValue: function (v) {
BI.each(this._children, function (i, wi) {
8 years ago
wi.setValue(v);
})
},
8 years ago
setText: function (v) {
BI.each(this._children, function (i, wi) {
8 years ago
wi.setText(v);
})
}
});
$.shortcut('bi.layout', BI.Layout);