import { shortcut, Widget, extend, emptyFn, createWidget, isNotNull, isNumber, size, each, last } from "@/core"; import { MultiSelectEditor } from "../../multiselect/trigger/editor.multiselect"; import { MultiSelectSearcher } from "../../multiselect/trigger/searcher.multiselect"; import { Searcher } from "@/base"; import { SimpleStateEditor } from "@/case"; import { MultiTreeSearchPane } from "multi.tree.search.pane"; @shortcut() export class MultiListTreeSearcher extends Widget { static xtype = "bi.multi_list_tree_searcher"; static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; static EVENT_CHANGE = "EVENT_CHANGE"; static EVENT_START = "EVENT_START"; static EVENT_STOP = "EVENT_STOP"; static EVENT_PAUSE = "EVENT_PAUSE"; _defaultConfig() { return extend(super._defaultConfig(...arguments), { baseCls: "bi-multi-list-tree-searcher", itemsCreator: emptyFn, valueFormatter(v) { return v; }, popup: {}, adapter: null, masker: {}, }); } _init() { super._init(...arguments); const self = this, o = this.options; this.editor = createWidget({ type: MultiSelectEditor.xtype, height: o.height, text: o.text, defaultText: o.defaultText, watermark: o.watermark, el: { type: SimpleStateEditor.xtype, height: o.height, }, listeners: [ { eventName: MultiSelectEditor.EVENT_FOCUS, action() { self.fireEvent(MultiSelectSearcher.EVENT_FOCUS); }, }, { eventName: MultiSelectEditor.EVENT_BLUR, action() { self.fireEvent(MultiSelectSearcher.EVENT_BLUR); }, } ], }); this.searcher = createWidget({ type: Searcher.xtype, element: this, isAutoSearch: false, isAutoSync: false, onSearch(op, callback) { callback({ keyword: self.editor.getValue(), }); }, el: this.editor, popup: extend( { type: MultiTreeSearchPane.xtype, keywordGetter() { return self.editor.getValue(); }, itemsCreator(op, callback) { op.keyword = self.editor.getValue(); o.itemsCreator(op, callback); }, value: o.value, }, o.popup ), adapter: o.adapter, masker: o.masker, }); this.searcher.on(Searcher.EVENT_START, () => { self.fireEvent(MultiListTreeSearcher.EVENT_START); }); this.searcher.on(Searcher.EVENT_PAUSE, () => { self.fireEvent(MultiListTreeSearcher.EVENT_PAUSE); }); this.searcher.on(Searcher.EVENT_STOP, () => { self.fireEvent(MultiListTreeSearcher.EVENT_STOP); }); this.searcher.on(Searcher.EVENT_CHANGE, function () { self.fireEvent(MultiListTreeSearcher.EVENT_CHANGE, arguments); }); if (isNotNull(o.value)) { this.setState(o.value); } } adjustView() { this.searcher.adjustView(); } setAdapter(adapter) { this.searcher.setAdapter(adapter); } isSearching() { return this.searcher.isSearching(); } stopSearch() { this.searcher.stopSearch(); } getKeyword() { return this.editor.getValue(); } hasMatched() { return this.searcher.hasMatched(); } hasChecked() { return this.searcher.getView() && this.searcher.getView().hasChecked(); } setState(ob) { const o = this.options; ob || (ob = {}); ob.value || (ob.value = []); let count = 0; if (isNumber(ob)) { this.editor.setState(ob); } else if (size(ob.value) === 0) { this.editor.setState(BI.Selection.None); } else { let text = ""; each(ob.value, (idx, path) => { const childValue = last(path); text += path === "null" ? "" : `${o.valueFormatter(`${childValue}`) || childValue }; `; count++; }); if (count > 20) { this.editor.setState(BI.Selection.Multi); } else { this.editor.setState(text); } } } getState() { return this.editor.getState(); } setValue(ob) { this.setState(ob); this.searcher.setValue(ob); } getKey() { return this.editor.getValue(); } getValue() { return this.searcher.getValue(); } populate(items) { this.searcher.populate(...arguments); } focus() { this.editor.focus(); } blur() { this.editor.blur(); } setWaterMark(v) { this.editor.setWaterMark(v); } }