/** * @class BI.TextValueCombo * @extend BI.Widget * combo : text + icon, popup : text * 参见场景dashboard布局方式选择 */ BI.TextValueCombo = BI.inherit(BI.Widget, { _defaultConfig: function (config) { return BI.extend(BI.TextValueCombo.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-text-value-combo " + (config.simple ? "bi-border-bottom" : "bi-border bi-border-radius"), height: 24, chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, text: "", value: "", defaultText: "", allowClear: false, }); }, _init: function () { var self = this, o = this.options; BI.isNumeric(o.width) && (o.width -= (o.simple ? 0 : 2)); BI.isNumeric(o.height) && (o.height -= (o.simple ? 1 : 2)); o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) { self.setValue(newValue); }) : o.value; o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { self.populate(newValue); }) : o.items; BI.TextValueCombo.superclass._init.apply(this, arguments); this.trigger = BI.createWidget({ type: "bi.select_text_trigger", cls: "text-value-trigger", items: o.items, height: o.height, text: o.text, value: o.value, warningTitle: o.warningTitle, allowClear: o.allowClear, defaultText: o.defaultText, listeners: [ { eventName: BI.SelectTextTrigger.EVENT_CLEAR, action: function () { self._clear(); self.fireEvent(BI.TextValueCombo.EVENT_CHANGE); } } ], }); this.popup = BI.createWidget({ type: "bi.text_value_combo_popup", chooseType: o.chooseType, value: o.value, items: o.items }); this.popup.on(BI.TextValueComboPopup.EVENT_CHANGE, function () { self.setValue(self.popup.getValue()); self.textIconCombo.hideView(); self.fireEvent(BI.TextValueCombo.EVENT_CHANGE, arguments); }); this.popup.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.textIconCombo = BI.createWidget({ type: "bi.combo", container: o.container, direction: o.direction, element: this, adjustLength: 2, el: this.trigger, popup: { el: this.popup, maxHeight: 240, minHeight: 25 } }); if (BI.isKey(o.value)) { this._checkError(o.value); } }, _clear: function () { this.trigger.setValue(); this.popup.setValue(); this.element.removeClass("error"); this.trigger.element.removeClass("error"); }, _checkError: function (v) { v = BI.isArray(v) ? v[0] : v; var tipType = null; var result = BI.find(this.options.items, function (idx, item) { return v === item.value; }); if (BI.isNull(result)) { if (this.isEnabled()) { tipType = "warning"; } this.element.addClass("error"); this.trigger.element.addClass("error"); } else { this.element.removeClass("error"); this.trigger.element.removeClass("error"); } this.trigger.setTipType(tipType); }, setValue: function (v) { this.trigger.setValue(v); this.popup.setValue(v); this._checkError(v); }, getValue: function () { var value = this.popup.getValue(); return BI.isNull(value) ? [] : (BI.isArray(value) ? value : [value]); }, populate: function (items) { this.options.items = items; this.textIconCombo.populate(items); } }); BI.TextValueCombo.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.text_value_combo", BI.TextValueCombo);