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.
107 lines
3.4 KiB
107 lines
3.4 KiB
7 years ago
|
/**
|
||
|
* Created by Windy on 2018/2/2.
|
||
|
*/
|
||
|
BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, {
|
||
|
|
||
|
props: {
|
||
|
baseCls: "bi-search-text-value-trigger bi-border",
|
||
|
height: 30
|
||
|
},
|
||
|
|
||
|
render: function () {
|
||
|
var self = this, o = this.options;
|
||
|
return {
|
||
|
type: "bi.htape",
|
||
|
items: [
|
||
|
{
|
||
|
el: {
|
||
|
type: "bi.searcher",
|
||
|
ref: function () {
|
||
|
self.searcher = this;
|
||
|
},
|
||
|
isAutoSearch: false,
|
||
|
el: {
|
||
|
type: "bi.state_editor",
|
||
|
ref: function () {
|
||
|
self.editor = this;
|
||
|
},
|
||
|
text: this._digest(o.value, o.items),
|
||
|
value: o.value,
|
||
|
height: o.height
|
||
|
},
|
||
|
popup: {
|
||
|
type: "bi.search_text_value_combo_popup",
|
||
|
cls: "bi-card",
|
||
|
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE
|
||
|
},
|
||
|
onSearch: function (obj, callback) {
|
||
|
var keyword = obj.keyword;
|
||
|
var finding = BI.Func.getSearchResult(o.items, keyword);
|
||
|
var matched = finding.matched, finded = finding.finded;
|
||
|
callback(finded, matched);
|
||
|
},
|
||
|
listeners: [{
|
||
|
eventName: BI.Searcher.EVENT_CHANGE,
|
||
|
action: function () {
|
||
|
self.fireEvent(BI.SearchTextValueTrigger.EVENT_CHANGE);
|
||
|
}
|
||
|
}]
|
||
|
}
|
||
|
}, {
|
||
|
el: {
|
||
|
type: "bi.layout",
|
||
|
width: 30
|
||
|
},
|
||
|
width: 30
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
},
|
||
|
|
||
|
_setState: function (v) {
|
||
|
this.editor.setState(v);
|
||
|
},
|
||
|
|
||
|
_digest: function(vals, items){
|
||
|
var o = this.options;
|
||
|
vals = BI.isArray(vals) ? vals : [vals];
|
||
|
var result = [];
|
||
|
var formatItems = BI.Tree.transformToArrayFormat(items);
|
||
|
BI.each(formatItems, function (i, item) {
|
||
|
if (BI.deepContains(vals, item.value) && !result.contains(item.text || item.value)) {
|
||
|
result.push(item.text || item.value);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
if (result.length > 0) {
|
||
|
return result.join(",");
|
||
|
} else {
|
||
|
return o.text;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
stopEditing: function () {
|
||
|
this.searcher.stopSearch();
|
||
|
},
|
||
|
|
||
|
getSearcher: function () {
|
||
|
return this.searcher;
|
||
|
},
|
||
|
|
||
|
populate: function (items) {
|
||
|
this.options.items = items;
|
||
|
},
|
||
|
|
||
|
setValue: function (vals) {
|
||
|
this._setState(this._digest(vals, this.options.items));
|
||
|
},
|
||
|
|
||
|
getValue: function () {
|
||
|
return this.searcher.getValue();
|
||
|
}
|
||
|
});
|
||
|
BI.SearchTextValueTrigger.EVENT_SEARCHING = "EVENT_SEARCHING";
|
||
|
BI.SearchTextValueTrigger.EVENT_STOP = "EVENT_STOP";
|
||
|
BI.SearchTextValueTrigger.EVENT_START = "EVENT_START";
|
||
|
BI.SearchTextValueTrigger.EVENT_CHANGE = "EVENT_CHANGE";
|
||
|
BI.shortcut("bi.search_text_value_trigger", BI.SearchTextValueTrigger);
|