forked from fanruan/fineui
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.
100 lines
2.9 KiB
100 lines
2.9 KiB
/** |
|
* Created by GUY on 2015/8/10. |
|
*/ |
|
|
|
import { shortcut, Widget, Controller, extend, isEmpty, each, formatEL, clone, createWidget } from "../../core"; |
|
|
|
@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: "bi.text_button", text: "", value: "" }, |
|
items: [], |
|
|
|
popup: { |
|
el: { |
|
type: "bi.button_tree", |
|
chooseType: 0, |
|
layouts: [{ |
|
type: "bi.vertical", |
|
}], |
|
}, |
|
}, |
|
}); |
|
} |
|
|
|
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: "bi.combo", |
|
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); |
|
} |
|
}
|
|
|