Passing data to/from an embedded view is as simple as using the input/output parameters of the view. Let's assume you want to use an embedded view because of your concerns about how messaging would effect performance on your gateway.
In this example above, I adapted a confirmation dialog to work as both a popup and an embedded view.
Parameters to the view:
The payload_id
and popup
inputs would not have to be included if you don't intend to use the view as a popup. Also, note that output
is in/out.
Yes button script:
def runAction(self, event):
if self.view.params.popup:
system.perspective.sendMessage("Confirm", payload = {"payloadID":self.view.params.payload_id, "confirm":True})
system.perspective.closePopup('')
else:
self.view.params.output = True
No button script:
def runAction(self, event):
if self.view.params.popup:
system.perspective.sendMessage("Confirm", payload = {"payloadID":self.view.params.payload_id, "confirm":False})
system.perspective.closePopup('')
else:
self.view.params.output = False
Other bindings are pretty self-explanatory.
Now you can add the view as an embedded view to your tank barcode view. (make sure you un-check the popup input if you're using it).
On your submit button, just set the Confirm embedded view's output to null:
def runAction(self, event):
self.getSibling("Confirm").props.params.output = None
Clicking yes/no on the embedded view will update the output value accordingly.
Bind the embedded view's visible property to the output property:
isNull({this.props.params.output})
Add a change script to the output property to do your action when the output is true:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
if currentValue:
#do stuff
With this setup you end up with this functionality:
When the Submit button is pressed, the Confirm embedded view output property is set to null (None
), which triggers the visibility of the embedded view via the binding on the visible
meta property. Once visible, the embedded view is able to write to itβs output
property when yes or no is pressed. Any time the output
property changes value, the value change script runs to determine if action needs to be taken.