import { IAppModel } from "../components/helper_interfaces" ; import { SFieldDescribe } from "./sfieldDescribe" ; import { AppUtils } from "../components/appUtils" ; import { RESOURCES } from "../components/resources" ; import { CONSTANTS } from "../components/statics" ; export class FieldItem implements IAppModel { name : string ; get cleanName ( ) { return this . name . split ( CONSTANTS . REFERENCE_FIELD_OBJECT_SEPARATOR ) [ 0 ] ; } get referencedObjectType ( ) { return this . sFieldDescribe && this . sFieldDescribe . isPolymorphic && this . name . split ( CONSTANTS . REFERENCE_FIELD_OBJECT_SEPARATOR ) [ 1 ] || this . sFieldDescribe && ! this . sFieldDescribe . isPolymorphic && this . sFieldDescribe . referencedObjectType || RESOURCES . NotSet ; } get label ( ) : string { let label = this . cleanName ; if ( ! this . isMultiselect ) { if ( this . sFieldDescribe && this . sFieldDescribe . lookup ) { label += `<br/>[*${ this . referencedObjectType }]` ; } } else { label = "** " + label + " **" ; } return label ; } errorMessage : string = '' ; selected : boolean ; isMultiselect : boolean ; isExcludedItem : boolean ; constructor ( init ? ) { if ( init ) { this . initialize ( init ) ; } } sFieldDescribe ? : SFieldDescribe ; get category ( ) : string { if ( this . isExcludedItem ) { return RESOURCES . ListCategory_AllFields ; } if ( this . isMultiselect ) { return RESOURCES . ListCategory_Multiselect ; } if ( ! this . isValid ( ) || ! this . sFieldDescribe ) { return RESOURCES . ListCategory_Errors ; } let category = [ ] ; if ( this . sFieldDescribe . custom ) category . push ( RESOURCES . ListCategory_Custom ) ; else category . push ( RESOURCES . ListCategory_Standard ) ; if ( this . sFieldDescribe . autoNumber ) category . push ( RESOURCES . ListCategory_Autonumber ) ; else if ( this . sFieldDescribe . isFormula ) category . push ( RESOURCES . ListCategory_Formula ) ; else if ( this . sFieldDescribe . isMasterDetail ) category . push ( RESOURCES . ListCategory_MasterDetail ) ; else if ( this . sFieldDescribe . lookup && ! this . sFieldDescribe . isMasterDetail ) category . push ( RESOURCES . ListCategory_Lookup ) ; return category . join ( RESOURCES . ListCategory_Separator ) ; } initialize ( init ) { if ( init ) { AppUtils . objectAssignSafe ( this , init ) ; } } isValid ( ) { return ! this . errorMessage && this . selected || this . isMultiselect || ! this . selected ; } }