/** * @class BI.SingleTreeCombo * @extends BI.Widget */ BI.SingleTreeCombo = BI.inherit(BI.Widget, { _defaultConfig: function (config) { return BI.extend(BI.SingleTreeCombo.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-single-tree-combo " + (config.simple ? "bi-border-bottom" : "bi-border bi-border-radius"), trigger: {}, height: 24, text: "", items: [], value: "", allowClear: false, }); }, _init: function () { var self = this, o = this.options; BI.SingleTreeCombo.superclass._init.apply(this, arguments); this.trigger = BI.createWidget(BI.extend({ type: "bi.single_tree_trigger", text: o.text, defaultText: o.defaultText, height: BI.pixFormat(o.height, 2), items: o.items, value: o.value, allowClear: o.allowClear, warningTitle: o.warningTitle, }, o.trigger)); this.trigger.on(BI.SingleTreeTrigger.EVENT_CLEAR, function () { self._clear(); }); this.popup = BI.createWidget({ type: "bi.single_level_tree", items: o.items, value: o.value }); this.combo = BI.createWidget({ type: "bi.combo", width: BI.pixFormat(o.width, 2), height: BI.pixFormat(o.height, 2), container: o.container, element: this, adjustLength: 2, el: this.trigger, popup: { el: this.popup } }); this.combo.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { self.fireEvent(BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW, arguments); }); this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { self.setValue(self.popup.getValue()); self.combo.hideView(); self.fireEvent(BI.SingleTreeCombo.EVENT_CHANGE); }); if (BI.isKey(o.value)) { this._checkError(o.value); } }, _checkError: function (v) { if (BI.isNull(v) || BI.isEmptyArray(v) || BI.isEmptyString(v)) { this.trigger.options.tipType = "success"; this.trigger.element.removeClass("error"); this.element.removeClass("error"); } else { v = BI.isArray(v) ? v : [v]; var result = BI.find(this.options.items, function (idx, item) { return BI.contains(v, item.value); }); if (BI.isNull(result)) { this.trigger.setTipType("warning"); this.element.removeClass("error").addClass("error"); this.trigger.element.removeClass("error").addClass("error"); } else { this.trigger.setTipType("success"); this.trigger.element.removeClass("error"); this.element.removeClass("error"); } } }, _clear: function () { this.setValue([]); }, populate: function (items) { this.combo.populate(items); }, setValue: function (v) { v = BI.isArray(v) ? v : [v]; this.trigger.setValue(v); this.popup.setValue(v); this._checkError(v); }, getValue: function () { return this.popup.getValue(); } }); BI.SingleTreeCombo.EVENT_CHANGE = "EVENT_CHANGE"; BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.shortcut("bi.single_tree_combo", BI.SingleTreeCombo);