import * as XrmMock from "../xrm-mock/index" ; import Ui from "./ui" ; export type CreateMethods = "createBoolean" | "createDate" | "createLookup" | "createNumber" | "createOptionSet" | "createString" ; export default class Control { public createBoolean ( components ) ; public createBoolean ( attribute , name ? , visible ? , disabled ? , label ? ) ; public createBoolean ( attributeOrComponents , name ? , visible = true , disabled = false , label ? ) { const components = this . createStandardComponent ( attributeOrComponents , name , visible , disabled , label ) as XrmMock . IBooleanControlComponents ; return this . addControl ( new XrmMock . BooleanControlMock ( components ) ) ; } public createDate ( components ) ; public createDate ( attribute , name ? , visible ? , disabled ? , label ? ) ; public createDate ( attributeOrComponents , name ? , visible = true , disabled = false , label ? ) { const components = this . createStandardComponent ( attributeOrComponents , name , visible , disabled , label ) as XrmMock . IDateControlComponents ; return this . addControl ( new XrmMock . DateControlMock ( components ) ) ; } public createGrid ( components ) ; public createGrid ( name ? , visible ? , label ? ) ; public createGrid ( nameOrComponents , visible = true , label ? ) { const components = ( nameOrComponents as XrmMock . IGridControlComponents ) . name ? nameOrComponents as XrmMock . IGridControlComponents : { label , name : nameOrComponents as string , visible } ; return this . addControl ( new XrmMock . GridControlMock ( components ) ) ; } public createLookup ( components ) ; public createLookup ( attribute , name ? , visible ? , disabled ? , label ? ) ; public createLookup ( attributeOrComponents , name ? , visible = true , disabled = false , label ? ) { const components = this . createStandardComponent ( attributeOrComponents , name , visible , disabled , label ) as XrmMock . ILookupControlComponents ; return this . addControl ( new XrmMock . LookupControlMock ( components ) ) ; } public createNumber ( components ) ; public createNumber ( attribute , name ? , visible ? , disabled ? , label ? ) ; public createNumber ( attributeOrComponents , name ? , visible = true , disabled = false , label ? ) { const components = this . createStandardComponent ( attributeOrComponents , name , visible , disabled , label ) as XrmMock . INumberControlComponents ; return this . addControl ( new XrmMock . NumberControlMock ( components ) ) ; } public createOptionSet ( components ) ; public createOptionSet ( attribute , name ? , visible ? , disabled ? , label ? ) ; public createOptionSet ( attributeOrComponents , name ? , visible = true , disabled = false , label ? ) { const components = this . createStandardComponent ( attributeOrComponents , name , visible , disabled , label ) as XrmMock . IOptionSetControlComponents ; return this . addControl ( new XrmMock . OptionSetControlMock ( components ) ) ; } public createString ( components ) ; public createString ( attribute , name ? , visible ? , disabled ? , label ? ) ; public createString ( attributeOrComponents , name ? , visible ? , disabled ? , label ? ) { const components = this . createStandardComponent ( attributeOrComponents , name , visible , disabled , label ) as XrmMock . IStringControlComponents ; return this . addControl ( new XrmMock . StringControlMock ( components ) ) ; } private addControl < T extends Xrm . Controls . Control > ( control ) { ( Xrm . Page . ui . controls as XrmMock . ItemCollectionMock < Xrm . Controls . Control > ) . push ( control ) ; return control ; } private createStandardComponent < TControl extends XrmMock . StandardControlMock < TControl , TAttribute , TValue > , TAttribute extends XrmMock . AttributeMock < TControl , TValue > , TValue extends XrmMock . AttributeReturnType , TComponent extends XrmMock . IStandardControlComponents < TControl , TAttribute , TValue > > ( attributeOrComponents , name ? , visible ? , disabled ? , label ? ) { const att = attributeOrComponents as TAttribute ; return att . controls && att . eventHandlers ? { attribute : attributeOrComponents as TAttribute , disabled , label : label || name , name , visible , } as any : attributeOrComponents as TComponent ; } }