fineui是帆软报表和BI产品线所使用的前端框架。
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.

108 lines
3.1 KiB

8 years ago
/**
* 选择字段trigger
*
* Created by GUY on 2015/9/15.
* @class BI.SelectTextTrigger
* @extends BI.Trigger
*/
BI.SelectTextTrigger = BI.inherit(BI.Trigger, {
_defaultConfig: function () {
return BI.extend(BI.SelectTextTrigger.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-select-text-trigger",
3 years ago
height: 24,
allowClear: false,
valueFormatter: BI.emptyFn,
defaultText: "",
8 years ago
});
},
_init: function () {
BI.SelectTextTrigger.superclass._init.apply(this, arguments);
var self = this, o = this.options;
var text = this._digest(o.value, o.items);
8 years ago
this.trigger = BI.createWidget({
type: "bi.text_trigger",
8 years ago
element: this,
7 years ago
height: o.height,
readonly: o.readonly,
text: text,
defaultText: o.defaultText,
3 years ago
textHgap: o.textHgap,
textVgap: o.textVgap,
textLgap: o.textLgap,
textRgap: o.textRgap,
textTgap: o.textTgap,
textBgap: o.textBgap,
tipType: o.tipType,
title: null,
allowClear: o.allowClear,
listeners: [
{
eventName: BI.TextTrigger.EVENT_CLEAR,
action: function () {
self.setText("");
self.fireEvent(BI.SelectTextTrigger.EVENT_CLEAR);
}
}
]
8 years ago
});
},
_digest: function (val, items) {
8 years ago
var o = this.options;
val = BI.isArray(val) ? val.slice() : [val];
8 years ago
var result = [];
// 提升valueFormatter的优先级
if (o.valueFormatter !== BI.emptyFn && BI.isFunction(o.valueFormatter)) {
BI.each(val, function (index, v) {
result.push(o.valueFormatter(v));
});
return result.join(",");
}
7 years ago
var formatItems = BI.Tree.transformToArrayFormat(items);
BI.each(formatItems, function (i, item) {
if (BI.contains(val, item.value) && !BI.contains(result, item.text || item.value)) {
8 years ago
result.push(item.text || item.value);
BI.remove(val, item.value);
8 years ago
}
});
if (result.length > 0 && val.length === 0) {
return result.join(",");
8 years ago
} else {
return BI.isFunction(o.text) ? o.text() : o.text;
8 years ago
}
},
setText: function (text) {
this.options.text = text;
this.trigger.setText(text);
},
setValue: function (val) {
var formatText = this._digest(val, this.options.items);
this.trigger.setText(formatText);
7 years ago
},
setTipType: function (v) {
this.options.tipType = v;
this.trigger.setTipType(v);
},
getTextor: function () {
return this.trigger.getTextor();
},
8 years ago
populate: function (items) {
this.options.items = items;
}
});
BI.SelectTextTrigger.EVENT_CLEAR = "EVENT_CLEAR";
BI.shortcut("bi.select_text_trigger", BI.SelectTextTrigger);