Best-Practice for closing 'This Popup'?

Ignition 8.1.20, Perspective:
I'm curious what the best practice is for closing the respective popup which contains a 'Close Popup' button? ...if a popupId is not known? ...if the 'Close Popup' button exists within an Embedded View of that popup?

Per insight from link below, we are using a script action within onActionPerformed of a Button object.

def runAction(self, event):
	system.perspective.closePopup('')

Is it desirable to name the popup Id during closing? If so, is there a clean method of grabbing the popup's Id property?

Perhaps another question would be: What is the specific action that is performed when the built-in "X" is pressed (located in title bar, when 'Show close button' is selected on popup creation)?

I forgot to mention, there is an issue with the aforementioned script we are using, whereby the 'Active Popup' closes instead of the parent popup containing the button.
This issue rears its ugly head only when multiple popups are open, and when the user clicks quickly on the close button of an inactive popup.

The native X button of the Popup does not care about the ID - that's the browser operating on HTML components without regard for their content. If you want Perspective to operate on a Popup, you really need to provide the ID of the Popup. I recommend that every time you open a Popup you do so one of two ways:

  1. Using a Script Action or Popup Action, pass the identifier used for the Popup as a param to the View. Then from within the View, any Button should reference that id param of the View. If you need to have your "close" button in an Embedded View of this View, then you need to continue passing the param down the chain. This is the best approach because No View is responsible for hanging onto some ID that might be changed elsewhere.
popup_id = "ASDF"
system.perspective.openPopup(id=popup_id, view="MyView", params={"id": popup_id})
  1. Hard-code the Popup ID into the View being used. This is a bad approach, but it will work until you change the ID in one location or the other.

Are there any updates planned that will enable a popupclose(self) feature?
I have implemented the workaround of passing the popup id into the popup as a parameter however I am getting problems when people implement standard popupclose('') in my project.

I nice solution would be to add to the popup component a property naming the specific popup id.

No, because Views (and by extension their children) have no idea they are even in a Popup. Views are - for the most part - not very intelligent and only know about the Page they exist on because they understand they must exist on a Page and therefore have access to page properties. There's no such guarantee any View belong to a Popup, or a Docked View.

Even if we opted to create a new function along the lines of system.perspective.closeWhateverPopupILiveIn(), There could be instances where it's invoked by a component that doesn't live in a page. Is the function idempotent when invoked within a View which is not in a Popup? The abstraction I mentioned earlier where Popups don't know much about how they fit in the grander scheme holds true for Embedded Views as well, and so how would this function work nested one, two, or N levels deep inside a View?

There is no Popup "component", but I'll assume you just meant to the Popup concept or mechanism. How would the View rendered for the Popup access this "injected" property? We'd have to have some sort of mechanism for the Popup to expose its ID to the View which will be rendered within. Something like... you guessed it: View params.

1 Like