Before Edit Action Handler¶
This callback is optional. It is called before user actions are completed, so it provides the opportunity for the application to alter or cancel an action before it is applied to the object model and reflected in the flow editor display.
beforeEditActionHandler¶
beforeEditActionHandler(data, command)
This callback is provided with two parameters: data
and command
.
- data parameter - this is the same as the data object described for
editActionHandler
(see above) - command parameter - typically this will be null but for
undo
operations (that is where data.editType === “undo”) this will be the command that is about to be undone. Forredo
operations (that is where data.editType === “redo”) this will be the command that is about to be redone.
This callback must return either the data object that was passed in or null. beforeEditActionHandler
will behave as follows based on what is returned:
- If the data object is returned unmodified: the action will be performed as normal.
- If the data object is returned modified: the action will be performed based on the modified data object. This means your application can alter the behavior of the action that will be performed. For example, you could intercept a
createNode
command and change the label for the new node in the nodeTemplate to something different. Then when the node is created the new label will be used. It is recommended you be very very careful when updating this object since there is no error checking in Common Canvas to ensure you modified the object correctly. - If
null
is returned: the action will be cancelled and not performed on the internal object model nor willeditActionHandler
be called.
If you need to do any asynchronous activity in the beforeEditActionHandler callback you can:
- Return null from the callback - which will cancel the current action
- Do your asynchronous activity. While this is happening, the user ought to be prevented from modifying the canvas so you should display some sort of progress indicator or modal dialog to inform the user that some activity is occurring.
- Then call
CanvasController.editActionHandler(data)
passing in thedata
object as a parameter with the modified properties. This will then execute the action as before. Note: This means thebeforeEditActionHandler
will be called a second time so be sure you put in a check to make sure you don’t get into a loop.