|
|
@ -14,6 +14,7 @@ BI.TextValueCombo = BI.inherit(BI.Widget, { |
|
|
|
value: "", |
|
|
|
value: "", |
|
|
|
defaultText: "", |
|
|
|
defaultText: "", |
|
|
|
allowClear: false, |
|
|
|
allowClear: false, |
|
|
|
|
|
|
|
status: "success", // success | warning | error
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -28,98 +29,137 @@ BI.TextValueCombo = BI.inherit(BI.Widget, { |
|
|
|
self.populate(newValue); |
|
|
|
self.populate(newValue); |
|
|
|
}) : o.items; |
|
|
|
}) : o.items; |
|
|
|
BI.TextValueCombo.superclass._init.apply(this, arguments); |
|
|
|
BI.TextValueCombo.superclass._init.apply(this, arguments); |
|
|
|
this.trigger = BI.createWidget({ |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render: function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const o = this.options; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const trigger = { |
|
|
|
type: "bi.select_text_trigger", |
|
|
|
type: "bi.select_text_trigger", |
|
|
|
|
|
|
|
ref: ref => this.trigger = ref, |
|
|
|
cls: "text-value-trigger", |
|
|
|
cls: "text-value-trigger", |
|
|
|
items: o.items, |
|
|
|
items: o.items, |
|
|
|
height: o.height, |
|
|
|
height: o.height, |
|
|
|
text: o.text, |
|
|
|
text: o.text, |
|
|
|
value: o.value, |
|
|
|
value: o.value, |
|
|
|
warningTitle: o.warningTitle, |
|
|
|
title: () => { |
|
|
|
|
|
|
|
if (this.options.status === "error") { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
level: "warning", |
|
|
|
|
|
|
|
text: o.warningTitle, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
level: "success", |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}, |
|
|
|
allowClear: o.allowClear, |
|
|
|
allowClear: o.allowClear, |
|
|
|
defaultText: o.defaultText, |
|
|
|
defaultText: o.defaultText, |
|
|
|
listeners: [ |
|
|
|
listeners: [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
eventName: BI.SelectTextTrigger.EVENT_CLEAR, |
|
|
|
eventName: BI.SelectTextTrigger.EVENT_CLEAR, |
|
|
|
action: function () { |
|
|
|
action: () => { |
|
|
|
self._clear(); |
|
|
|
this._clear(); |
|
|
|
self.fireEvent(BI.TextValueCombo.EVENT_CHANGE); |
|
|
|
this.fireEvent(BI.TextValueCombo.EVENT_CHANGE); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
], |
|
|
|
], |
|
|
|
}); |
|
|
|
}; |
|
|
|
this.popup = BI.createWidget({ |
|
|
|
const popup = { |
|
|
|
type: "bi.text_value_combo_popup", |
|
|
|
type: "bi.text_value_combo_popup", |
|
|
|
|
|
|
|
ref: ref => this.popup = ref, |
|
|
|
chooseType: o.chooseType, |
|
|
|
chooseType: o.chooseType, |
|
|
|
value: o.value, |
|
|
|
value: o.value, |
|
|
|
items: o.items |
|
|
|
items: o.items, |
|
|
|
}); |
|
|
|
listeners: [ |
|
|
|
this.popup.on(BI.TextValueComboPopup.EVENT_CHANGE, function () { |
|
|
|
{ |
|
|
|
self.setValue(self.popup.getValue()); |
|
|
|
eventName: BI.TextValueComboPopup.EVENT_CHANGE, |
|
|
|
self.textIconCombo.hideView(); |
|
|
|
action: (...args) => { |
|
|
|
self.fireEvent(BI.TextValueCombo.EVENT_CHANGE, arguments); |
|
|
|
this.setValue(this.popup.getValue()); |
|
|
|
}); |
|
|
|
this.combo.hideView(); |
|
|
|
this.popup.on(BI.Controller.EVENT_CHANGE, function () { |
|
|
|
this.fireEvent(BI.TextValueCombo.EVENT_CHANGE, ...args); |
|
|
|
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, { |
|
|
|
this.textIconCombo = BI.createWidget({ |
|
|
|
eventName: BI.Controller.EVENT_CHANGE, |
|
|
|
|
|
|
|
action: (...args) => { |
|
|
|
|
|
|
|
this.fireEvent(BI.Controller.EVENT_CHANGE, ...args); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
type: "bi.combo", |
|
|
|
type: "bi.combo", |
|
|
|
|
|
|
|
ref: ref => this.combo = ref, |
|
|
|
container: o.container, |
|
|
|
container: o.container, |
|
|
|
direction: o.direction, |
|
|
|
direction: o.direction, |
|
|
|
element: this, |
|
|
|
|
|
|
|
adjustLength: 2, |
|
|
|
adjustLength: 2, |
|
|
|
el: this.trigger, |
|
|
|
el: trigger, |
|
|
|
popup: { |
|
|
|
popup: { |
|
|
|
el: this.popup, |
|
|
|
el: popup, |
|
|
|
|
|
|
|
value: o.value, |
|
|
|
maxHeight: 240, |
|
|
|
maxHeight: 240, |
|
|
|
minHeight: 25 |
|
|
|
minHeight: 25 |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mounted: function () { |
|
|
|
|
|
|
|
const o = this.options; |
|
|
|
if (BI.isKey(o.value)) { |
|
|
|
if (BI.isKey(o.value)) { |
|
|
|
this._checkError(o.value); |
|
|
|
this._checkError(o.value); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_clear: function () { |
|
|
|
_clear: function () { |
|
|
|
this.trigger.setValue(); |
|
|
|
this.combo.setValue(); |
|
|
|
this.popup.setValue(); |
|
|
|
this.setStatus("success"); |
|
|
|
this.element.removeClass("error"); |
|
|
|
|
|
|
|
this.trigger.element.removeClass("error"); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
_checkError: function (v) { |
|
|
|
_checkError: function (v) { |
|
|
|
v = BI.isArray(v) ? v[0] : v; |
|
|
|
|
|
|
|
var tipType = null; |
|
|
|
if (BI.isNull(v)) { |
|
|
|
|
|
|
|
this.setStatus("success"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var vals = BI.isArray(v) ? v : [v]; |
|
|
|
|
|
|
|
|
|
|
|
var result = BI.find(this.options.items, function (idx, item) { |
|
|
|
var result = BI.find(this.options.items, function (idx, item) { |
|
|
|
return v === item.value; |
|
|
|
return BI.contains(vals, item.value); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (BI.isNull(result)) { |
|
|
|
if (BI.isNull(result)) { |
|
|
|
if (this.isEnabled()) { |
|
|
|
this.setStatus("error"); |
|
|
|
tipType = "warning"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.element.addClass("error"); |
|
|
|
|
|
|
|
this.trigger.element.addClass("error"); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.element.removeClass("error"); |
|
|
|
this.setStatus("success"); |
|
|
|
this.trigger.element.removeClass("error"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
this.trigger.setTipType(tipType); |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clear: function () { |
|
|
|
|
|
|
|
this._clear(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
setValue: function (v) { |
|
|
|
setValue: function (v) { |
|
|
|
this.trigger.setValue(v); |
|
|
|
this.combo.setValue(v); |
|
|
|
this.popup.setValue(v); |
|
|
|
|
|
|
|
this._checkError(v); |
|
|
|
this._checkError(v); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setStatus: function (status) { |
|
|
|
|
|
|
|
this.element.removeClass(`bi-status-${this.options.status}`); |
|
|
|
|
|
|
|
this.element.addClass(`bi-status-${status}`); |
|
|
|
|
|
|
|
this.options.status = status; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getValue: function () { |
|
|
|
getValue: function () { |
|
|
|
var value = this.popup.getValue(); |
|
|
|
var value = this.combo.getValue(); |
|
|
|
return BI.isNull(value) ? [] : (BI.isArray(value) ? value : [value]); |
|
|
|
return BI.isNull(value) ? [] : (BI.isArray(value) ? value : [value]); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
populate: function (items) { |
|
|
|
populate: function (items) { |
|
|
|
this.options.items = items; |
|
|
|
this.options.items = items; |
|
|
|
this.textIconCombo.populate(items); |
|
|
|
this.combo.populate(items); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
BI.TextValueCombo.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
BI.TextValueCombo.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|