The Design Registry is a repository of Design prototypes and their types. A design holds the structure of a type of data; it describes an object's fields and their corresponding field type.
All the data in your FEF application has a Design that is registered in the Design Registry. Each design has a list of fields; each of which has either a FunctionalType, for primitives and FEF prototypes, or a DesignType, for primary or embedded objects. Lists and maps are considered types of fields, with a flag indicating whether they are a list or map.
The Design that is registered for your data depends on the back end data model. For example, a custom object's design comes directly from the object's design within a platform module. The design of an object and its corresponding fields indicate to FEF how to render each piece of data.
Along with designs as defined by the backend data; designs can also be created solely in FEF to serve as a placeholder for client side information. An example is shown below.
Get Design of Type of Data
In order to get the design of a type of data, use the getDesign method. Below, we get the design of the primary data of your FEF page.
var data = Facade.PageRegistry.getPrimaryData();
var primaryDesign = data.getDesign();
Designs in your design registry are registered by their global object identifier. Here, we get the design of a primary object in our FEF application with the global object identifier $FefRowObjS1.
var rowObjectDesign = Facade.DesignRegistry.get('$FefRowObjS1');
Get/Manipulate Fields of a Design
Here, we get a field in your primary design and change its functional type to picklist.
var data = Facade.PageRegistry.getPrimaryData();
var primaryDesign = data.getDesign();
//Get field named myPicklist and change its type to picklist
primaryDesign.getField('myPicklist')
.setFunctionalType(Facade.Constants.FunctionalType.PICKLIST);
Get all the fields of your design. This will return an array with all of the fields in the design.
var designFields = primaryDesign.getFields()
//Get first field of design
var fieldOne = designFields[0];
Add a field to your design and set its design type to be of type OrganizationalDetail.
primaryDesign.addField('orgField').setDesignType('OrganizationalDetail');
If you want to make your field a list or a map, use the following:
//Set field myField as a list
primaryDesign.getField('myField').setIsList(true);
//Set field myMap as a map
primaryDesign.getField('myMap').setIsMap(true);
Get Properties of a Design Field
We can get the following properties of a field in a design:
var design = Facade.DesignRegistry.get('<objectType>');
var field = design.getField('col1');
//get a fields mask
var mask = field.getFieldMask();
//get fields name
var name = field.getName();
//get if the field is required
var req = field.getIsRequired();
//get party role if its a party
var role = field.getPartyRole();
Register a Client Side Design
The design registry offers the ability to create and define a client side design to hold data to show on your interface but that does not need to be persisted to the server. Here, we will register a design and then register some data in our Data Registry that uses said design.
//Register a new design
var clientDesign = Facade.DesignRegistry.register(
new Facade.Prototypes.Design( undefined, { designType : 'myDesign' } ));
//Add a field that to lookup an organization
clientDesign.addField('organization').setDesignType('OrganizationalDetail');
//Add some other fields to your design
clientDesign.addField('myDate').setFunctionalType(Facade.Constants.FunctionalType.DATETIME);
clientDesign.addField('myInt').setFunctionalType(Facade.Constants.FunctionalType.INTEGER);
clientDesign.addField('myText').setFunctionalType(Facade.Constants.FunctionalType.TEXT);
//Set list of objects of type Employee
clientDesign.addField('myEmployees').setDesignType('employee').setIsList(true);
//NOW - register some data for you application and set its type to myDesign
//so it uses the above registered design
Facade.DataRegistry.register('myClientData' ,
new Facade.Prototypes.Data(undefined , { type : 'myDesign' }));
Add A Virtual Field
Virtual Fields are constructs in FEF that allow a field within a design to have a getter and setter function. The getter function causes the field data to depend on another field within your pathData and the setter function can set another field depending on the value of the virtual field.
The getter function is required for a virtual field, while the setter is optional. If your virtual field does not have a setter function, it will render as read only within your application
In the following example, our virtual field is calculated as the difference between two other dates - the startDate and the targetEndDate. The getter function determines the field value as the difference between the dates; while the setter field will set the targetEndDate to its value plus the value of the startDate.
projectDesign.addVirtualField("targetDuration",
//GETTER FUNCTION
function(){
var startDate = this.get("startDate")
var endDate = this.get("targetEndDate")
if (startDate && endDate) {
return (Date.parse(endDate) - Date.parse(startDate)) / 1000 / 60 / 60 / 24
}
return undefined
},
//SETTER FUNCTION
function(value){
if (isNaN(value)) {
return
}
var startDate = this.get("startDate")
if (startDate) {
var endTime = Date.parse(startDate) + value * 24 * 60 * 60 * 1000
var endDate = new Date(endTime)
this.set("targetEndDate",endDate.getFullYear() + "/" + (endDate.getMonth() + 1 < 10 ? "0" : "") + (endDate.getMonth() + 1) + "/" + (endDate.getDate() < 10 ? "0" : "") + endDate.getDate())
}
})
//Always set a fields functional type
.setFunctionalType(Facade.Constants.FunctionalType.INTEGER)