packages/data/src/lib/resource-form/resource-form.ts
Form for any kind of SDK Resource.
constructor(body: Resource, config: FormConfig
|
||||||||||||||||||
Constructs the form. Can be given an api (Core) and a fitting relation name.
Parameters :
|
Public api |
Type : Core
|
Public relation |
Type : string
|
Public resourceService |
Type : ResourceService
|
Public config |
Type : FormConfig<T>
|
Inherited from
Form
|
Defined in
Form:14
|
The configuration of the form. It is an extension of ItemConfig. |
Public fields |
Type : Field[]
|
Inherited from
Form
|
Defined in
Form:12
|
Array of fields. It will be populated automatically when the form is constructed. |
Public body |
Type : T
|
Inherited from
Form
|
Defined in
Form:6
|
The value body of the item. This can be either a primitive value or an Object. |
Public config |
Type : ItemConfig<T>
|
Inherited from
Form
|
Defined in
Form:8
|
The config of the item. |
Public body |
Type : T
|
Inherited from
Item
|
Defined in
Item:6
|
The value body of the item. This can be either a primitive value or an Object. |
Public config |
Type : ItemConfig<T>
|
Inherited from
Item
|
Defined in
Item:8
|
The config of the item. |
save | ||||||
save(value: Object)
|
||||||
Saves the given value. Run serializers before assigning the new value.
Parameters :
Returns :
Promise<Item<Resource>>
|
createField | |||||||||
createField(property: string, config: FieldConfigProperty)
|
|||||||||
Inherited from
Form
|
|||||||||
Defined in
Form:31
|
|||||||||
creates and adds a single field to the form
Parameters :
Returns :
Field | undefined
|
getField | ||||||
getField(property: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:49
|
||||||
returns the field instance of the given property
Parameters :
Returns :
any
|
getValue | ||||||
getValue(property: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:54
|
||||||
Returns the original value of the property, if any.
Parameters :
Returns :
any
|
isCreating |
isCreating()
|
Inherited from
Form
|
Defined in
Form:75
|
Returns true if the form is currently in create mode (has not a body set)
Returns :
boolean
|
isEditing |
isEditing()
|
Inherited from
Form
|
Defined in
Form:70
|
Returns true if the form is currently in edit mode (has a body set)
Returns :
boolean
|
action | ||||||
action(property, e)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:240
|
||||||
Action method that is meant to be called on a button click or similar. Calls the config#action method with the item and the property name
Parameters :
Returns :
void
|
classes | ||||||
classes(property?: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:140
|
||||||
If no property given: Returns the output of the config.classes method or ''. If property given: Returns the output of the config.fields[property].classes method or ''
Parameters :
Returns :
string
|
clear |
clear()
|
Inherited from
Form
|
Defined in
Form:47
|
deletes the item body
Returns :
void
|
deleteImmutableProperties | ||||||||
deleteImmutableProperties(value: Object)
|
||||||||
Inherited from
Form
|
||||||||
Defined in
Form:191
|
||||||||
Parameters :
Returns :
void
|
display | ||||||
display(property?: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:152
|
||||||
Returns the output of the config.display transformation function with the given property value. If no display function is set, it will just return the property value.
Parameters :
Returns :
any
|
Protected generateConfig |
generateConfig()
|
Inherited from
Form
|
Defined in
Form:17
|
Generates a config from the body by setting view to the properties type.
Returns :
ItemConfig<T>
|
getBody |
getBody()
|
Inherited from
Form
|
Defined in
Form:37
|
Returns the item's body
Returns :
T
|
getConfig |
getConfig()
|
Inherited from
Form
|
Defined in
Form:57
|
Returns the item's config
Returns :
any
|
getProperties |
getProperties()
|
Inherited from
Form
|
Defined in
Form:62
|
Returns an Array of properties possessed by the body.
Returns :
Array<string>
|
group | ||||||
group(property: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:134
|
||||||
Returns the output of the config.group transformation function with the given property value. If no group function is set, it will just return the property value.
Parameters :
Returns :
any
|
hasBody |
hasBody()
|
Inherited from
Form
|
Defined in
Form:42
|
Returns true if the body is defined and not null
Returns :
boolean
|
id |
id()
|
Inherited from
Form
|
Defined in
Form:73
|
Returns the value of the the Item's identifier property.
Returns :
any
|
isImmutableProperty | ||||||
isImmutableProperty(property: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:179
|
||||||
Parameters :
Returns :
boolean
|
pickWriteOnly | ||||||
pickWriteOnly(value)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:165
|
||||||
Returns value with all readOnly properties removed
Parameters :
Returns :
any
|
resolve | ||||||
resolve(property?: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:82
|
||||||
Returns either the whole body (if no property is given) or the value of the given property. This method will traverse the body via the config.resolve function (if given).
Parameters :
Returns :
any
|
resolvePath | ||||||
resolvePath(path: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:109
|
||||||
Resolves the given path on the item object. e.g. "value.config.usePassword" will resolve that object path, if existing.
Parameters :
Returns :
any
|
save | ||||||||
save(value: T)
|
||||||||
Inherited from
Form
|
||||||||
Defined in
Form:222
|
||||||||
Saves the given value. Run serializers before assigning the new value.
Parameters :
Returns :
Promise<Item<T>>
|
serialize | ||||||||||||
serialize(value, put: boolean)
|
||||||||||||
Inherited from
Form
|
||||||||||||
Defined in
Form:200
|
||||||||||||
Transforms the given field's value for serialization when saving.
Parameters :
Returns :
any
|
sort | ||||||
sort(property: string)
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:160
|
||||||
Transforms the given field's value for sorting
Parameters :
Returns :
any
|
Public transform | ||||||||||||||||||||
transform(action: string, property: string, value: any, defaultValue: any)
|
||||||||||||||||||||
Inherited from
Form
|
||||||||||||||||||||
Defined in
Form:117
|
||||||||||||||||||||
The main method for transformation functions like resolve, display and group. If you dont set the third parameter, the current item value will be used. The third parameter can be used to transform a value that is not yet possesed (e.g. to serialize)
Parameters :
Returns :
any
|
useConfig | ||||||
useConfig(config: ItemConfig
|
||||||
Inherited from
Form
|
||||||
Defined in
Form:52
|
||||||
Assigns the given config to the existing via Object.assign
Parameters :
Returns :
void
|
action | ||||||
action(property, e)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:240
|
||||||
Action method that is meant to be called on a button click or similar. Calls the config#action method with the item and the property name
Parameters :
Returns :
void
|
classes | ||||||
classes(property?: string)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:140
|
||||||
If no property given: Returns the output of the config.classes method or ''. If property given: Returns the output of the config.fields[property].classes method or ''
Parameters :
Returns :
string
|
clear |
clear()
|
Inherited from
Item
|
Defined in
Item:47
|
deletes the item body
Returns :
void
|
deleteImmutableProperties | ||||||||
deleteImmutableProperties(value: Object)
|
||||||||
Inherited from
Item
|
||||||||
Defined in
Item:191
|
||||||||
Parameters :
Returns :
void
|
display | ||||||
display(property?: string)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:152
|
||||||
Returns the output of the config.display transformation function with the given property value. If no display function is set, it will just return the property value.
Parameters :
Returns :
any
|
Protected generateConfig |
generateConfig()
|
Inherited from
Item
|
Defined in
Item:17
|
Generates a config from the body by setting view to the properties type.
Returns :
ItemConfig<T>
|
getBody |
getBody()
|
Inherited from
Item
|
Defined in
Item:37
|
Returns the item's body
Returns :
T
|
getConfig |
getConfig()
|
Inherited from
Item
|
Defined in
Item:57
|
Returns the item's config
Returns :
any
|
getProperties |
getProperties()
|
Inherited from
Item
|
Defined in
Item:62
|
Returns an Array of properties possessed by the body.
Returns :
Array<string>
|
group | ||||||
group(property: string)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:134
|
||||||
Returns the output of the config.group transformation function with the given property value. If no group function is set, it will just return the property value.
Parameters :
Returns :
any
|
hasBody |
hasBody()
|
Inherited from
Item
|
Defined in
Item:42
|
Returns true if the body is defined and not null
Returns :
boolean
|
id |
id()
|
Inherited from
Item
|
Defined in
Item:73
|
Returns the value of the the Item's identifier property.
Returns :
any
|
isImmutableProperty | ||||||
isImmutableProperty(property: string)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:179
|
||||||
Parameters :
Returns :
boolean
|
pickWriteOnly | ||||||
pickWriteOnly(value)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:165
|
||||||
Returns value with all readOnly properties removed
Parameters :
Returns :
any
|
resolve | ||||||
resolve(property?: string)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:82
|
||||||
Returns either the whole body (if no property is given) or the value of the given property. This method will traverse the body via the config.resolve function (if given).
Parameters :
Returns :
any
|
resolvePath | ||||||
resolvePath(path: string)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:109
|
||||||
Resolves the given path on the item object. e.g. "value.config.usePassword" will resolve that object path, if existing.
Parameters :
Returns :
any
|
save | ||||||||
save(value: T)
|
||||||||
Inherited from
Item
|
||||||||
Defined in
Item:222
|
||||||||
Saves the given value. Run serializers before assigning the new value.
Parameters :
Returns :
Promise<Item<T>>
|
serialize | ||||||||||||
serialize(value, put: boolean)
|
||||||||||||
Inherited from
Item
|
||||||||||||
Defined in
Item:200
|
||||||||||||
Transforms the given field's value for serialization when saving.
Parameters :
Returns :
any
|
sort | ||||||
sort(property: string)
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:160
|
||||||
Transforms the given field's value for sorting
Parameters :
Returns :
any
|
Public transform | ||||||||||||||||||||
transform(action: string, property: string, value: any, defaultValue: any)
|
||||||||||||||||||||
Inherited from
Item
|
||||||||||||||||||||
Defined in
Item:117
|
||||||||||||||||||||
The main method for transformation functions like resolve, display and group. If you dont set the third parameter, the current item value will be used. The third parameter can be used to transform a value that is not yet possesed (e.g. to serialize)
Parameters :
Returns :
any
|
useConfig | ||||||
useConfig(config: ItemConfig
|
||||||
Inherited from
Item
|
||||||
Defined in
Item:52
|
||||||
Assigns the given config to the existing via Object.assign
Parameters :
Returns :
void
|
import Resource from 'ec.sdk/lib/resources/Resource';
import { Form, FormConfig } from '@ec.components/core';
import { Item } from '@ec.components/core';
import Core from 'ec.sdk/lib/Core';
import { ResourceService } from '../resource-config/resource.service';
/** Form for any kind of SDK Resource. */
export class ResourceForm extends Form<Resource> {
/** Constructs the form. Can be given an api (Core) and a fitting relation name. */
constructor(
body: Resource,
config: FormConfig<Resource> = {},
public api: Core,
public relation: string,
public resourceService: ResourceService,
) {
super(body, config);
}
/** Saves the given value. Run serializers before assigning the new value. */
save(value: Object): Promise<Item<Resource>> {
return this.resourceService
.save(this, value, this.relation, this.api)
.then((resource) => new Item(resource, this.config));
}
}