|
|
|
import { TextButton } from "../single";
|
|
|
|
import { ButtonTree } from "./tree.button";
|
|
|
|
import {
|
|
|
|
VerticalLayout,
|
|
|
|
shortcut,
|
|
|
|
Widget,
|
|
|
|
Controller,
|
|
|
|
extend,
|
|
|
|
isEmpty,
|
|
|
|
each,
|
|
|
|
formatEL,
|
|
|
|
clone,
|
|
|
|
createWidget
|
|
|
|
} from "@/core";
|
|
|
|
import { Combo } from "./combo";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by GUY on 2015/8/10.
|
|
|
|
*/
|
|
|
|
|
|
|
|
@shortcut()
|
|
|
|
export class ComboGroup extends Widget {
|
|
|
|
static xtype = "bi.combo_group";
|
|
|
|
|
|
|
|
static EVENT_CHANGE = "EVENT_CHANGE";
|
|
|
|
|
|
|
|
_defaultConfig() {
|
|
|
|
return extend(super._defaultConfig(...arguments), {
|
|
|
|
baseCls: "bi-combo-group bi-list-item",
|
|
|
|
|
|
|
|
// 以下这些属性对每一个combo都是公用的
|
|
|
|
trigger: "click,hover",
|
|
|
|
direction: "right",
|
|
|
|
adjustLength: 0,
|
|
|
|
isDefaultInit: false,
|
|
|
|
isNeedAdjustHeight: false,
|
|
|
|
isNeedAdjustWidth: false,
|
|
|
|
|
|
|
|
el: { type: TextButton.xtype, text: "", value: "" },
|
|
|
|
items: [],
|
|
|
|
|
|
|
|
popup: {
|
|
|
|
el: {
|
|
|
|
type: ButtonTree.xtype,
|
|
|
|
chooseType: 0,
|
|
|
|
layouts: [
|
|
|
|
{
|
|
|
|
type: VerticalLayout.xtype,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this._populate(this.options.el);
|
|
|
|
}
|
|
|
|
|
|
|
|
_populate(item) {
|
|
|
|
const {
|
|
|
|
items,
|
|
|
|
action,
|
|
|
|
height,
|
|
|
|
direction,
|
|
|
|
isDefaultInit,
|
|
|
|
isNeedAdjustHeight,
|
|
|
|
isNeedAdjustWidth,
|
|
|
|
adjustLength,
|
|
|
|
popup,
|
|
|
|
container,
|
|
|
|
trigger,
|
|
|
|
} = this.options;
|
|
|
|
const children = items;
|
|
|
|
if (isEmpty(children)) {
|
|
|
|
throw new Error("ComboGroup构造错误");
|
|
|
|
}
|
|
|
|
each(children, (i, ch) => {
|
|
|
|
const son = formatEL(ch).el.children;
|
|
|
|
ch = formatEL(ch).el;
|
|
|
|
if (!isEmpty(son)) {
|
|
|
|
ch.el = clone(ch);
|
|
|
|
ch.items = son;
|
|
|
|
ch.type = "bi.combo_group";
|
|
|
|
ch.action = action;
|
|
|
|
ch.height = height;
|
|
|
|
ch.direction = direction;
|
|
|
|
ch.isDefaultInit = isDefaultInit;
|
|
|
|
ch.isNeedAdjustHeight = isNeedAdjustHeight;
|
|
|
|
ch.isNeedAdjustWidth = isNeedAdjustWidth;
|
|
|
|
ch.adjustLength = adjustLength;
|
|
|
|
ch.popup = popup;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.combo = createWidget({
|
|
|
|
type: Combo.xtype,
|
|
|
|
element: this,
|
|
|
|
container,
|
|
|
|
height,
|
|
|
|
trigger,
|
|
|
|
direction,
|
|
|
|
isDefaultInit,
|
|
|
|
isNeedAdjustWidth,
|
|
|
|
isNeedAdjustHeight,
|
|
|
|
adjustLength,
|
|
|
|
el: item,
|
|
|
|
popup: extend({}, popup, {
|
|
|
|
el: extend(
|
|
|
|
{
|
|
|
|
items: children,
|
|
|
|
},
|
|
|
|
popup.el
|
|
|
|
),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
this.combo.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => {
|
|
|
|
this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args);
|
|
|
|
if (type === BI.Events.CLICK) {
|
|
|
|
this.fireEvent(ComboGroup.EVENT_CHANGE, obj);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
return this.combo.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
setValue(v) {
|
|
|
|
this.combo.setValue(v);
|
|
|
|
}
|
|
|
|
}
|