|
|
|
import { shortcut, extend, emptyFn, createWidget, HTapeLayout, AbsoluteLayout } from "@/core";
|
|
|
|
import { Trigger, Text } from "@/base";
|
|
|
|
import { SingleSelectSearcher } from "./trigger";
|
|
|
|
|
|
|
|
@shortcut()
|
|
|
|
export class SingleSelectTrigger extends Trigger {
|
|
|
|
static xtype = "bi.single_select_trigger";
|
|
|
|
|
|
|
|
constants = { height: 14, rgap: 4, lgap: 4 };
|
|
|
|
|
|
|
|
static EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK";
|
|
|
|
static EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK";
|
|
|
|
static EVENT_CHANGE = "EVENT_CHANGE";
|
|
|
|
static EVENT_START = "EVENT_START";
|
|
|
|
static EVENT_STOP = "EVENT_STOP";
|
|
|
|
static EVENT_PAUSE = "EVENT_PAUSE";
|
|
|
|
static EVENT_SEARCHING = "EVENT_SEARCHING";
|
|
|
|
static EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW";
|
|
|
|
static EVENT_FOCUS = "EVENT_FOCUS";
|
|
|
|
static EVENT_BLUR = "EVENT_BLUR";
|
|
|
|
|
|
|
|
_defaultConfig() {
|
|
|
|
return extend(super._defaultConfig(...arguments), {
|
|
|
|
baseCls: "bi-single-select-trigger",
|
|
|
|
allowNoSelect: false,
|
|
|
|
itemsCreator: emptyFn,
|
|
|
|
valueFormatter: emptyFn,
|
|
|
|
searcher: {},
|
|
|
|
switcher: {},
|
|
|
|
|
|
|
|
adapter: null,
|
|
|
|
masker: {},
|
|
|
|
allowEdit: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_init() {
|
|
|
|
super._init(...arguments);
|
|
|
|
|
|
|
|
const o = this.options;
|
|
|
|
|
|
|
|
this.searcher = createWidget(o.searcher, {
|
|
|
|
type: SingleSelectSearcher.xtype,
|
|
|
|
watermark: o.watermark,
|
|
|
|
allowNoSelect: o.allowNoSelect,
|
|
|
|
text: o.text,
|
|
|
|
height: o.height,
|
|
|
|
itemsCreator: o.itemsCreator,
|
|
|
|
valueFormatter: o.valueFormatter,
|
|
|
|
popup: {},
|
|
|
|
adapter: o.adapter,
|
|
|
|
masker: o.masker,
|
|
|
|
value: o.value,
|
|
|
|
});
|
|
|
|
this.searcher.on(SingleSelectSearcher.EVENT_START, () => {
|
|
|
|
this.fireEvent(SingleSelectTrigger.EVENT_START);
|
|
|
|
});
|
|
|
|
this.searcher.on(SingleSelectSearcher.EVENT_PAUSE, () => {
|
|
|
|
this.fireEvent(SingleSelectTrigger.EVENT_PAUSE);
|
|
|
|
});
|
|
|
|
this.searcher.on(SingleSelectSearcher.EVENT_SEARCHING, (...args) => {
|
|
|
|
this.fireEvent(SingleSelectTrigger.EVENT_SEARCHING, ...args);
|
|
|
|
});
|
|
|
|
this.searcher.on(SingleSelectSearcher.EVENT_STOP, () => {
|
|
|
|
this.fireEvent(SingleSelectTrigger.EVENT_STOP);
|
|
|
|
});
|
|
|
|
this.searcher.on(SingleSelectSearcher.EVENT_CHANGE, (...args) => {
|
|
|
|
this.fireEvent(SingleSelectTrigger.EVENT_CHANGE, ...args);
|
|
|
|
});
|
|
|
|
this.searcher.on(SingleSelectSearcher.EVENT_FOCUS, () => {
|
|
|
|
this.fireEvent(SingleSelectTrigger.EVENT_FOCUS);
|
|
|
|
});
|
|
|
|
this.searcher.on(SingleSelectSearcher.EVENT_BLUR, (...args) => {
|
|
|
|
this.fireEvent(SingleSelectTrigger.EVENT_BLUR, ...args);
|
|
|
|
});
|
|
|
|
|
|
|
|
createWidget({
|
|
|
|
type: HTapeLayout.xtype,
|
|
|
|
element: this,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
el: this.searcher,
|
|
|
|
width: "fill",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
el: createWidget(),
|
|
|
|
width: 24,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
!o.allowEdit &&
|
|
|
|
createWidget({
|
|
|
|
type: AbsoluteLayout.xtype,
|
|
|
|
element: this,
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
el: {
|
|
|
|
type: Text.xtype,
|
|
|
|
title: () => this.searcher.getState(),
|
|
|
|
},
|
|
|
|
left: 0,
|
|
|
|
right: 24,
|
|
|
|
top: 0,
|
|
|
|
bottom: 0,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getSearcher() {
|
|
|
|
return this.searcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
stopEditing() {
|
|
|
|
this.searcher.stopSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
setAdapter(adapter) {
|
|
|
|
this.searcher.setAdapter(adapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
setValue(v) {
|
|
|
|
this.searcher.setValue(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
getKey() {
|
|
|
|
return this.searcher.getKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
return this.searcher.getValue();
|
|
|
|
}
|
|
|
|
}
|