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.
113 lines
3.1 KiB
113 lines
3.1 KiB
import { |
|
shortcut, |
|
Widget, |
|
extend, |
|
isFunction, |
|
createWidget, |
|
toPix, |
|
Controller, |
|
isKey, |
|
isNull, |
|
isArray |
|
} from "@/core"; |
|
import { ButtonGroup, Combo } from "@/base"; |
|
import { TextValueCheckComboPopup } from "./popup.textvaluecheck"; |
|
import { SelectTextTrigger } from "../../trigger"; |
|
|
|
@shortcut() |
|
export class TextValueCheckCombo extends Widget { |
|
static xtype = "bi.text_value_check_combo"; |
|
|
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
_defaultConfig(config) { |
|
return extend(super._defaultConfig(...arguments), { |
|
baseCls: |
|
`bi-text-value-check-combo ${ |
|
config.simple ? "bi-border-bottom" : "bi-border"}`, |
|
width: 100, |
|
height: 24, |
|
chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, |
|
value: "", |
|
}); |
|
} |
|
|
|
_init() { |
|
const o = this.options; |
|
o.value = isFunction(o.value) |
|
? this.__watch(o.value, (context, newValue) => { |
|
this.setValue(newValue); |
|
}) |
|
: o.value; |
|
o.items = isFunction(o.items) |
|
? this.__watch(o.items, (context, newValue) => { |
|
this.populate(newValue); |
|
}) |
|
: o.items; |
|
super._init(...arguments); |
|
this.trigger = createWidget({ |
|
type: SelectTextTrigger.xtype, |
|
cls: "text-value-trigger", |
|
items: o.items, |
|
height: toPix(o.height, 2), |
|
text: o.text, |
|
value: o.value, |
|
}); |
|
this.popup = createWidget({ |
|
type: TextValueCheckComboPopup.xtype, |
|
chooseType: o.chooseType, |
|
items: o.items, |
|
value: o.value, |
|
}); |
|
this.popup.on(TextValueCheckComboPopup.EVENT_CHANGE, () => { |
|
this.setValue(this.popup.getValue()); |
|
this.textIconCheckCombo.hideView(); |
|
this.fireEvent(TextValueCheckCombo.EVENT_CHANGE); |
|
}); |
|
this.popup.on(Controller.EVENT_CHANGE, ...args => { |
|
this.fireEvent(Controller.EVENT_CHANGE, ...args); |
|
}); |
|
this.textIconCheckCombo = createWidget({ |
|
type: Combo.xtype, |
|
container: o.container, |
|
direction: o.direction, |
|
element: this, |
|
width: toPix(o.width, 2), |
|
height: toPix(o.height, 2), |
|
adjustLength: 2, |
|
el: this.trigger, |
|
popup: { |
|
el: this.popup, |
|
maxHeight: 300, |
|
}, |
|
}); |
|
|
|
if (isKey(o.value)) { |
|
this.setValue(o.value); |
|
} |
|
} |
|
|
|
setTitle(title) { |
|
this.trigger.setTitle(title); |
|
} |
|
|
|
setValue(v) { |
|
this.trigger.setValue(v); |
|
this.popup.setValue(v); |
|
} |
|
|
|
setWarningTitle(title) { |
|
this.trigger.setWarningTitle(title); |
|
} |
|
|
|
getValue() { |
|
const value = this.popup.getValue(); |
|
|
|
return isNull(value) ? [] : isArray(value) ? value : [value]; |
|
} |
|
|
|
populate(items) { |
|
this.options.items = items; |
|
this.textIconCheckCombo.populate(items); |
|
} |
|
}
|
|
|