|
|
|
/**
|
|
|
|
* @class SelectTreeCombo
|
|
|
|
* @extends Widget
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
shortcut,
|
|
|
|
Widget,
|
|
|
|
extend,
|
|
|
|
createWidget,
|
|
|
|
Controller,
|
|
|
|
contains,
|
|
|
|
isArray,
|
|
|
|
toPix,
|
|
|
|
isKey,
|
|
|
|
isEmptyArray,
|
|
|
|
isEmptyString,
|
|
|
|
find,
|
|
|
|
isNull
|
|
|
|
} from "@/core";
|
|
|
|
import { Combo } from "@/base";
|
|
|
|
import { SingleTreeTrigger } from "@/widget/singletree/singletree.trigger";
|
|
|
|
import { SelectTreePopup } from "./selecttree.popup";
|
|
|
|
|
|
|
|
@shortcut()
|
|
|
|
export class SelectTreeCombo extends Widget {
|
|
|
|
static xtype = "bi.select_tree_combo";
|
|
|
|
|
|
|
|
_defaultConfig() {
|
|
|
|
return extend(super._defaultConfig(...arguments), {
|
|
|
|
baseCls: "bi-select-tree-combo bi-border bi-border-radius",
|
|
|
|
height: 24,
|
|
|
|
text: "",
|
|
|
|
items: [],
|
|
|
|
value: "",
|
|
|
|
allowClear: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_init() {
|
|
|
|
const self = this, o = this.options;
|
|
|
|
super._init(...arguments);
|
|
|
|
|
|
|
|
this.trigger = createWidget({
|
|
|
|
type: SingleTreeTrigger.xtype,
|
|
|
|
text: o.text,
|
|
|
|
height: toPix(o.height, 2),
|
|
|
|
items: o.items,
|
|
|
|
value: o.value,
|
|
|
|
allowClear: o.allowClear,
|
|
|
|
warningTitle: o.warningTitle,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.trigger.on(SingleTreeTrigger.EVENT_CLEAR, () => {
|
|
|
|
this._clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.popup = createWidget({
|
|
|
|
type: SelectTreePopup.xtype,
|
|
|
|
items: o.items,
|
|
|
|
value: o.value,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.combo = createWidget({
|
|
|
|
type: Combo.xtype,
|
|
|
|
width: toPix(o.width, 2),
|
|
|
|
height: toPix(o.height, 2),
|
|
|
|
container: o.container,
|
|
|
|
element: this,
|
|
|
|
adjustLength: 2,
|
|
|
|
el: this.trigger,
|
|
|
|
popup: {
|
|
|
|
el: this.popup,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
this.combo.on(Controller.EVENT_CHANGE, function () {
|
|
|
|
self.fireEvent(Controller.EVENT_CHANGE, arguments);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.popup.on(SelectTreePopup.EVENT_CHANGE, () => {
|
|
|
|
self.setValue(self.popup.getValue());
|
|
|
|
self.combo.hideView();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (isKey(o.value)) {
|
|
|
|
this._checkError(o.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_checkError(v) {
|
|
|
|
if (isNull(v) || isEmptyArray(v) || isEmptyString(v)) {
|
|
|
|
this.trigger.options.tipType = "success";
|
|
|
|
this.trigger.element.removeClass("error");
|
|
|
|
this.element.removeClass("error");
|
|
|
|
} else {
|
|
|
|
v = isArray(v) ? v : [v];
|
|
|
|
const result = find(this.options.items, (idx, item) => contains(v, item.value));
|
|
|
|
if (isNull(result)) {
|
|
|
|
this.trigger.setTipType("warning");
|
|
|
|
this.element.removeClass("error").addClass("error");
|
|
|
|
this.trigger.element.removeClass("error").addClass("error");
|
|
|
|
} else {
|
|
|
|
this.trigger.setTipType("success");
|
|
|
|
this.trigger.element.removeClass("error");
|
|
|
|
this.element.removeClass("error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_clear() {
|
|
|
|
this.setValue([]);
|
|
|
|
}
|
|
|
|
|
|
|
|
setValue(v) {
|
|
|
|
v = isArray(v) ? v : [v];
|
|
|
|
this.trigger.setValue(v);
|
|
|
|
this.popup.setValue(v);
|
|
|
|
this._checkError(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
return this.popup.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
populate(items) {
|
|
|
|
this.combo.populate(items);
|
|
|
|
}
|
|
|
|
}
|