This repository has been archived by the owner on Feb 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
cdo.form_and_model_generators
Pavel Vlasov edited this page Feb 22, 2015
·
16 revisions
org.nasdanika.cdo
bundle provides several classes for generating Bootstrap/AngularJS forms and models from EClass and EOperation metadata
and annotations:
-
FormGeneratorBase - Abstract base class. It has a number of protected methods which can be overriden by subclasses to fine-tune form
generation. Default method implementations use metadata such as feature/parameter name and type and annotations to generate forms.
- EClassFormGenerator - Generates HTML/Bootstrap form from EClass metadata and annotations.
- EOperationFormGenerator - Generates HTML/Bootstrap form from EOperation metadata and annotations.
-
AngularJsFormGeneratorBase - Abstract base class for generating forms and models to work with AngularJS.
- AngularJsEClassFormGenerator - Generates HTML/Bootstrap AngularJS form and model from EClass metadata and annotations.
- AngularJsEObjectFormGenerator - Generates HTML/Bootstrap AngularJS form and model from EObject metadata and annotations.
Annotations used by the generators are:
-
org.nasdanika.cdo.web.html.form-control
for EClass features - attributes and references (by default controls are not generated for references) and for EOperation parameters. This annotation supports the following details keys:-
attribute:<attribute name>
- Allows to specify control attribute. -
group-attribute:<attribute name>
- Allows to specify group attribute. -
control-id
- Control ID, defaults to<feature|parameter name>_control
. -
default
- Default value. If not set then attribute default value is used for attributes. -
help-text
- Help text. No default. In AngularJS generators help text is used to display control-level validation messages.-
inline
- Inline checkbox control if set to true.
-
-
input-type
- One of InputType values. Default value is computed from feature/parameter type bygetInputType()
methods which can be overriden. -
label
- Control label. Defaults to feature/parameter name split by camel case with the first word capitalized and the rest uncapitalized. E.g. a label foruserName
parameter or feature would be "User name". -
placeholder
- Control placeholder for controls which support placeholders. Default is the same as for label. -
private
- Iftrue
then feature/parameter is not included into the generated form. -
required
- Marks the generated control as required if set totrue
. -
style:<style name>
- Allows to customize control style. E.g.style:background
->yellow
-
group-style:<style name>
- Allows to customize group style. -
validator
- Control validator used by AngularJS generators. The value of thevalidator
details key shall be a JavaScript function body returning validation message or a promise for a validation message. If the return value is falsey, e.g. undefined or an empty string, then validation is successful, otherwise the return value is displayed as a control-level error message. The function body has access to the control value throughvalue
parameter and to the whole model throughthis
.
-
-
org.nasdanika.cdo.web.html.form
for EClasses and EOperations. This annotation supports the following details keys:-
model
- Object declarations to add to the model definition, e.g. helper functions. -
validator
is used by AngularJS generators in generation ofvalidate()
model function. The value of thevalidator
details key shall be a JavaScript function body returning validation message or a promise for a validation message. If the return value is falsey, e.g. undefined or an empty string, then validation is successful, otherwise the return value is displayed as a form-level error message. The function body has access to the model data throughvalue
parameter and to the whole model throughthis
.
-
AngularJS generators have generateModel()
method which returns JavaScript object definition with the following entries:
-
data
- an object which is either empty or contains default values for features/parameters. Form controls are bound to this object's entries. For existing object replace the generateddata
entry with the JavaScript API object. -
validationResults
- an empty object to hold validation messages for controls. -
validate()
- a function which invokes validators for controls and the form and returns a promise of boolean value. If the promise is resolved withtrue
then the form is valid. -
apply(target)
- this function is generated byAngularJsEOperationFormGenerator
. It invokes the target passing model data as arguments in the order in which they are defined in the ECore model. Iftarget
is an object with<operation name>
function, then that function is invoked, otherwisetarget
assumed to be a function to be invoked. -
validateAndApply(target)
- this function is generated byAngularJsEOperationFormGenerator
. It invokesvalidate()
. If validation is successful, then it invokesapply(target)
.validateAndApply
returns a promise resolved with return value ofapply()
or rejected with{ validationFailed: true }
if validation failed, or{ targetInvocationError: <target rejection reason> }
. This function expectstarget
function to return a promise, which is the case for JavaScript API functions generated for model objects' EOperations.