GetWithDynamicActionsHelper Class
`
handlebars
{!-- Without custom "path" keyword (default keyword "path" will be used) --}
{{flexberry-tree
nodes=(get-with-dynamic-actions this "treeNodes"
hierarchyPropertyName="nodes"
dynamicActions=(array
(hash
on="headerClick"
actionName="onTreenodeHeaderClick"
actionArguments=(array "{% path %}")
)
(hash
on="checkboxChange"
actionName="onTreenodeCheckboxChange"
actionArguments=(array "{% path %}.checkboxValue")
)
)
)
}}
{{!-- With custom "path" keyword --}}
{{flexberry-tree
nodes=(get-with-dynamic-actions this "treeNodes"
hierarchyPropertyName="nodes"
pathKeyword="nodePath"
dynamicActions=(array
(hash
on="headerClick"
actionName="onTreenodeHeaderClick"
actionArguments=(array "{% nodePath %}")
)
(hash
on="checkboxChange"
actionName="onTreenodeCheckboxChange"
actionArguments=(array "{% nodePath %}.checkboxValue")
)
)
)
}}
`
controllers/my-form.js
`
javascript
import Controller from '@ember/controller';
import TreeNodeObject from 'ember-flexberry/objects/flexberry-treenode';
export default Controller.extend({
treeNodes: A(
FlexberryTreenodeObject.create({
caption: 'Node 1 (with child nodes)',
hasCheckbox: true,
checkboxValue: false,
iconClass: 'map icon',
nodes: A([
caption: 'Node 1.1 (leaf node)',
hasCheckbox: true,
checkboxValue: false,
iconClass: 'apple icon',
nodes: null
)
}),
FlexberryTreenodeObject.create({
caption: 'Node 2 (leaf node)',
hasCheckbox: true,
checkboxValue: false,
iconClass: 'compass icon',
nodes: null
})
]),
actions: {
onTreenodeHeaderClick(...args) {
let treeNodePath = args[0];
let treeNodeHeaderClickActionEventObject = args[args.length - 1];
console.log('Clicked tree node\'s properties:', this.get(treeNodePath));
console.log('Clicked tree node\'s \'headerClick\' action event object:', treeNodeHeaderClickActionEventObject);
},
onTreenodeCheckboxChange(...args) {
let treeNodeCheckboxValuePath = args[0];
let treeNodeCheckboxChangeActionEventObject = args[args.length - 1];
// Change tree node's 'checkboxValue' property.
this.set(treeNodeCheckboxValuePath, treeNodeCheckboxChangeActionEventObject.newValue);
}
}
});
`
addon/helpers/get-with-dynamic-actions.js:74
Get with dynamic actions helper. Retrieves property with the specified name from the specified object (exactly as standard get helper does), and additionally binds dynamic actions for retrieved property's nested object/objects (even if retrieved property has hierarchical structure).
Helper must be used with those component's, which consumes their inner structure as JSON-object or EmberObject and there is no way to attach action handlers for their nested component's explicitly in hbs-markup.
Item Index
Methods
Methods
_addHierarchyPropertyObserver
-
propertyPath
Adds observer for given hierarchy property, which will force helper to recompute on any changes in the specified hierarchy property.
Parameters:
-
propertyPath
StringPath to observable property.
_bindDynamicActions
-
propertyValue
-
propertyPath
-
Name
-
Specified
Binds given dynamic actions to every object in the specified hierarchy.
_removeHierarchyPropertiesObservers
-
options
Removes all previously attached to hierarchy properties observers.
_renamePropertyPath
-
observerPropertyPath
-
len
Renames property path of observers.
_sort
-
hierarchyPropertiesObservers
Sort array with hierarchy properties observers.
Parameters:
-
hierarchyPropertiesObservers
ArrayArray with hierarchy properties observers.
compute
-
args
-
[hash] Object containing [helper's named arguments]
-
[hash.hierarchyPropertyName]
-
[hash.dynamicActions]
Overridden Helper compute method. Executes helper's logic, returns helper's value.
Parameters:
-
args
Any-
0
ObjectProperty owner, object containing property which must be retrieved & returned from helper (after dynamic action binding). Will be also used as action handlers context (if context wasn't specified explicitly in dynamic action bindings).
-
1
StringName of those property which must be retrieved from owner & returned from helper (after dynamic actions binding). Owner's property (behind this name) must be an object or array of objects.
-
-
[hash] Object containing [helper's named arguments]
Object -
[hash.hierarchyPropertyName]
Object optionalName of nested property (inside retrieved one), through which child object/objects (objects hierarchy) will be available.
-
[hash.dynamicActions]
DynamicActionObject[] optionalDynamic actions, which will be binded to object/objects retrieved from the owner (and to all nested child objects).
Properties
_dynamicActions
DynamicActionObject[]
private
Dynamic actions, which will be binded to object/objects retrieved from the owner (and to all nested child objects).
_hierarchyPropertiesObservers
Object[]
private
Array with objects containing names of hierarchy properties and observer handlers related to them. Each object in array has following structure: { propertyPath: '...', observerHandler: function() { ... } }.
Default: null
_hierarchyPropertyName
String
private
Name of nested property (inside retrieved one), through which child object/objects (objects hierarchy) is/are available.
_rootPropertyName
String
private
Name of those property which must be retrieved from owner & returned from helper (after dynamic actions binding).