@ -14,6 +14,7 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
value : "" ,
defaultText : "" ,
allowClear : false ,
status : "success" , // success | warning | error
} ) ;
} ,
@ -28,90 +29,128 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
self . populate ( newValue ) ;
} ) : o . items ;
BI . TextValueCombo . superclass . _init . apply ( this , arguments ) ;
this . trigger = BI . createWidget ( {
} ,
render : function ( ) {
const o = this . options ;
const trigger = {
type : "bi.select_text_trigger" ,
ref : ref => this . trigger = ref ,
cls : "text-value-trigger" ,
items : o . items ,
height : o . height ,
text : o . text ,
value : o . value ,
warningTitle : o . warningTitle ,
title : ( ) => {
if ( this . options . status === "error" ) {
return {
level : "warning" ,
text : o . warningTitle ,
} ;
}
return {
level : "success" ,
} ;
} ,
allowClear : o . allowClear ,
defaultText : o . defaultText ,
listeners : [
{
eventName : BI . SelectTextTrigger . EVENT _CLEAR ,
action : function ( ) {
self . _clear ( ) ;
self . fireEvent ( BI . TextValueCombo . EVENT _CHANGE ) ;
action : ( ) => {
this . _clear ( ) ;
this . fireEvent ( BI . TextValueCombo . EVENT _CHANGE ) ;
}
}
] ,
} ) ;
this . popup = BI . createWidget ( {
} ;
const popup = {
type : "bi.text_value_combo_popup" ,
ref : ref => this . popup = ref ,
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 ( {
items : o . items ,
listeners : [
{
eventName : BI . TextValueComboPopup . EVENT _CHANGE ,
action : ( ... args ) => {
this . setValue ( this . popup . getValue ( ) ) ;
this . combo . hideView ( ) ;
this . fireEvent ( BI . TextValueCombo . EVENT _CHANGE , args ) ;
}
} , {
eventName : BI . Controller . EVENT _CHANGE ,
action : ( ... args ) => {
this . fireEvent ( BI . Controller . EVENT _CHANGE , args ) ;
}
}
]
} ;
return {
type : "bi.combo" ,
ref : ref => this . combo = ref ,
container : o . container ,
direction : o . direction ,
element : this ,
adjustLength : 2 ,
el : this . trigger ,
el : trigger ,
popup : {
el : this . popup ,
el : popup ,
maxHeight : 240 ,
minHeight : 25
}
} ) ;
} ;
} ,
mounted : function ( ) {
const o = this . options ;
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" ) ;
this . combo . setValue ( ) ;
this . setStatus ( "success" ) ;
} ,
_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 ) {
return v === item . value ;
return BI . contains ( vals , item . value ) ;
} ) ;
if ( BI . isNull ( result ) ) {
if ( this . isEnabled ( ) ) {
tipType = "warning" ;
}
this . element . addClass ( "error" ) ;
this . trigger . element . addClass ( "error" ) ;
this . setStatus ( "error" ) ;
} else {
this . element . removeClass ( "error" ) ;
this . trigger . element . removeClass ( "error" ) ;
this . setStatus ( "success" ) ;
}
this . trigger . setTipType ( tipType ) ;
} ,
clear : function ( ) {
this . _clear ( ) ;
} ,
setValue : function ( v ) {
this . trigger . setValue ( v ) ;
this . popup . setValue ( v ) ;
this . combo . setValue ( 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 ( ) {
var value = this . popup . getValue ( ) ;
return BI . isNull ( value ) ? [ ] : ( BI . isArray ( value ) ? value : [ value ] ) ;
@ -119,7 +158,7 @@ BI.TextValueCombo = BI.inherit(BI.Widget, {
populate : function ( items ) {
this . options . items = items ;
this . textI conC ombo. populate ( items ) ;
this . combo . populate ( items ) ;
}
} ) ;
BI . TextValueCombo . EVENT _CHANGE = "EVENT_CHANGE" ;