Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Goal

Make it easier to implement dialogs in Admincentral where the fields can be dynamically changed, based on other fields.

For example make these easy, fast, clear, powerful to implement:

Concept

1. Introduce

Concept

Introduce the ability to supply logical expressions which can use the values of other fields in order to determine the state on a field.

Expressions might be javascript, or some other an expression language like MVEL.

Maybe expressions are indicated by parenthesis.

Code Block
( isWizard & ( hasSpellSlots | hasWand))

...

hasWand)

For example, these properties could use expressions: enabled, visible, required, label, buttonLabel, options


2. Provide ways to augment fields, potentially with Java, that do not require creating brand new fieldTypes. Creating fieldTypes is harder, slower & less transparent then augmenting a fieldType with some custom behaviour.


Question

Is there a nice way that, for any thing that can take an inline expression, it could also take an external javascript function, or a java class?

Would we need to add additional properties like enabledClass, visibleClass....?

Features

User, Group and Role aware

Expressions would also have access to some context such as the current user group and role, so that some fields would only be visible or enabled to certain user roles. 

Code Block
fields:
	html:
		fieldType: code
		visible: ( context.hasRole('developer'))  #or something like that!

Dynamically Enabled

The enabled property can take a logical expression as well as a simple boolean value.

Code Block
fields:
	isBarbarian:
		fieldType: checkbox
		type: Boolean
	isElf
		fieldType: checkbox
		type: Boolean
    barbarianElfHatType:
		fieldType: text
		enabled: ( isBarbarian & isElf )
        description: What type of hat is your elven barbarian wearing?

Image Added

Dynamically

...

Visible

A field is only present visible on a form, that is - visible and also being stored to the persistance layer - if the  "presentvisible" expression evaluates to true.

Could also be called "present" instead of "visible".

Code Block
fields:
	barbarianElfHatType:
		fieldType: text
		presentvisible: ( isBarbarian & isElf )

...

Code Block
fields:
	clericSpells:
		fieldType: text
		validators:
            onlyClericOrWizard:
              class: info....ExpressionValidator
              expression: (!(clericSpells!="" & wizardSpells!=""))
			  errorMessage: Only Cleric OR Wizard spells allowed, not both.


Image Added

Dynamic Label & Dynamic Button Labels

Use expression, Javascript or Java, to determine which hardcoded string is displayed, or which i18n key is retrieved.

For example this can be used with a Static field, to provide a label that reacts to things selected in other controls.

"This combination of herbs soothes your mind and promotes concentration".

Code Block
fields:
	herbMessage:
		fieldType: static
		label: (info....DynamicHerbMessages)

Dynamic Options

Populate the options of a selectbox, set of radiobuttons, or twincolumn select or link field (with chooser), based on the value of other fields.

We provide some out-of-the-box modes where no custom coding is required, but also make it easier for developers to fulfil this use case with a minimum of coding for more custom use cases.


Dynamic Select

dynamicSelect:

...

A select field which populates based on an optionModel and parametes which can come from other fields

optionModel:

Developer provides a Java class or a JS class Javascript function which takes the values of the fields specifed in "optionModelArguments" as arguments, and returns an array of label & value pairs to populate the options field with.

Options list is empty until the "optionModelArguments" fields have values.


Code Block
fields:
	heroTypecountry:
		fieldType: select
		optionspath: /
			- wizard
			- cleric
			- fighter
			- thief
	levelrepository: countries

    state:
		fieldType: selectdynamicSelect
		options:optionModelArguments
			- 1
country							- 2
			- 3#references 'country' field.
			- 4optionModel: org.dandelion......StatesPerCountry

    spellspostalCode:
		fieldType: dynamicOptionsdynamicSelect
		optionModelArguments
			- heroType
state											- level#references 'state' field.
		optionModel: org.dandelion......AvailableSpells
        description: Choose from your available spells, after choosing your heroType and level.PostalCodesPerState

Image Added

Node Chooser

Out-of-the-box field fields based on a heirarchy of nodes. (Not necessarily Probably JCR bound.)

introduce two new dynamic field types:

dynamicLinkdynamicNodeLink:

A link field which gets its workspace from another field.dynamicNodeOptions

dynamicNodeSelect:

A selectbox which gets its options based on a parentNode from another field.

By default it only returns the immediate children.


Code Block
fields:
	myWorkspace:
		fieldType: workspace

	myParentNode:	#lists items based on the workspace chosen in 'myWorkspace' field.
		fieldType: dynamicLinkdynamicNodeLink
		workspace: myWorkspace
		nodeTypes:
			- mgnl:folder

    assets:         #lists items based on the node chosen in 'myParentNode' field.
		fieldType: dynamicNodeOptionsdynamicNodeSelect
		parentNode: myParentNode
        includeAllDecendants: true
		nodeTypes:
			- mgnl:asset


Question: Can we make this ContentType-centric instead of JCR-centric so that it is usable OOTB on external content sources?

REST Item Chooser

Out-of-the-box fields based on a getting items via REST from external content sources.

(Maybe we dont need new field types, we can just leverage what is supplied in EasyREST epic. See comment: 

Jira
serverMagnolia - Issue tracker
serverId500b06a6-e204-3125-b989-2d75b973d05f
keyMGNLUI-5020
, but we would need to add the dynamic side.)

introduce two new dynamic field types:

dynamicRESTLink:

A link field which uses a REST client to populate it's chooser. 

Importantly, the field can use expressions to specify OTHER FIELDS as parameters to the REST client, or as the restClient or the restCall to use, dynamically.


dynamicRESTSelect:

A selectbox which uses a REST client to populate its options.

By default it only returns the immediate children.

Importantly, the field can use expressions to specify OTHER FIELDS as parameters to the REST client, or as the restClient or the restCall to use, dynamically.


Code Block
fields:
	ecommerceSystem:
		fieldType: select
		options:
			- elasticPath
			- shopify

	category:
		fieldType: dynamicRESTSelect
		datasource: 
            $type: jsonDatasource
            restClient: (ecommerceSystem) #dynamic based on value in 'ecommerceSystem' field.
            restCall: categories

    assets:
		fieldType: dynamicRESTLink
		datasource: 
            $type: jsonDatasource
            restClient: (ecommerceSystem) #dynamic based on value in 'ecommerceSystem' field.
            restCall: products
			restCallParameters:
				- category: (category) #dynamic based on value in 'category' field.

Image Added

Java Improvements

In addition to the above improvements, we want to make it easier to implement sophisticated use cases in Java.

  • Make fields available to each other in Java - so that customers are not forced to make a composite field anytime they want to program fields that interact with one another.

Notes

Take a look at linked tickets on: 

Jira
serverMagnolia - Issue tracker
serverId500b06a6-e204-3125-b989-2d75b973d05f
keyMGNLUI-2542

...