onClick event options binding?

I have a view I'm embedding in a few different places in a project. In a site overview page, it can be clicked to open a popup with available controls. In a system overview page, I want to use the same embedded view, but disable to onClick event. is there a way to bind the enable option? or is there another way to accomplish this so I don't have to make a second copy of this view without the onClick event?

The only way forward is to use a script action to open the popup; the script can have whatever arbitrary logic you want as a predicate.

I haven't used a script action before. Are you suggesting that I fire a script when the onClick event happens? I then check if the view is being accessed from the site overview page or the other location before actually launching the popup using the script?

Instead of a 'Popup' action, add a 'Script' action.

Your condition/predicate for whether to actually do anything is "am I on the overview page or not", so your script will be something like:

if self.view.id.partition("@")[0] != "Path/To/SystemOverview":
	system.perspective.openPopup(...)

You'll have to translate the popup action settings you have defined to system.perspective.openPopup.

1 Like

Ok great. That's not too hard to implement. Thank you for your help, Paul.

I'm not seeing documentation about the partition part of that code snipet you sent. Can you explain what the self.view.id.partition("@")[0] does?

So, given:

  1. self
  2. view
  3. id
  4. partition
  5. [0]

  1. In an action script on something in Perspective, self identifies the component or whatever other thing is firing the script.
  2. All Perspective components have built-in helper functions, getView(), getSession(), etc. Jython lets you call those getter methods automatically as property references; so .view is the same as getView() but less characters.
  3. View objects in particular have a getId()/id property: Perspective Component Methods | Ignition User Manual that returns a string like path/to/view@mountPath.
  4. You only care about the path to the view, not the 'mount path', so you can use Python's built in partition instance method on the string to split it into three parts: the part before the split, the split itself, and the part after.
  5. But we only care about the part before the split, so we use index access [0] to retrieve that 0th element of the list.
2 Likes

This is super helpful and I'm learning a lot. However, it's not quite giving me what I need. To check out what i'm getting back, I set up a string tag and filled it with the results of the self.view.id.partition("@")[0] function. It's returning the path to the embedded view, not the view that's displayed on the page. How do I get the view that's displayed on the page?

I was able to solve the problem with

if self.page.props.path != "/": #checks if current page is system home URL. Returns true when NOT system home URL.
	system.perspective.openPopup(...) #opens controls popup

I can add additional exclusions with or statements if I need to use this embedded view in other locations.

1 Like

It's complicated for embedded views, because they live much more in isolation (on the backend, where your scripts are actually being run) than they do on the frontend where they're nested inside each other.