Open a popup as a view is open

The requirement:

I've got a perspective application that is passed an id as an URL parameter.
If this id is -1 it should show a dialog to allow the user to chose a document in a list; if an id>0 is provided, the application should show the document with that id.

My perspective MainView takes a parameter called id, initialized to 0.

In my page configuration I've added the parameter to the "Page URL".

As you can see in the first picture, the parameter has a Change Script attached, that is:

if currentValue.value == "-1":
	system.perspective.openPopup("123abc", "DialogView")

The problem
The first time the user launches the page it works.
But if you click refresh twice the popup disappears.

Cannot use view onStartup event
It seems that events are more related to the server side state of the page. That is, the Change Script on the property happens only when the property gets actually changed, it doesn't start over when the page is refreshed.

So i tried the events onStartp of both the view and the root components. Turns out that those follow the same logic: when the page is created on the server they get fired, then, just hitting refresh they are not fired anymore. Neither changing the id param of the page raises a new onStartup, so this cannot be the solution as well.

Any suggestion?


This is a "weird" area of perspective. I've run into issues here as well...
I'm not sure you can work "with" the refresh, but maybe you can work around it.

The first thing I'd try is to change the id parameter's value at the end of your script. Set it to 0.
Maybe then refreshes will retrigger the value change script.

If this doesn't work, I'm sure people here will think of other things to try.

The most important things to note here are that refreshing a page closes all open Popups, and even though the page content is re-drawn and bindings re-evaluate if the underlying values of the bindings have no changed, then no change scripts will be executed.

So if your page loads the first time with a param value of -1, the Popup will open. Clicking the refresh button of the browser will close the Popup and re-draw the page. But the -1 value is still in place, and so the change script won't execute - which means the Popup won't be re-opened.

As you've found, startup scripts behave the same way; the page already went through its start-up process - we're just re-drawing the page.

Some "solutions", without knowing about all of your requirements:

  1. Place a VERY prominent input component that screams "select a document here", and default your Page/View to displaying empty fields until a document is selected.
  2. Require document selection on a different page entirely, and force navigation to the document selection Page if users arrive on THIS page without having selected a document.
1 Like

If the parameter's value has been changed, would refreshing set it back to the value provided by the url parameter ?
This could be used to force a rerun of the change script.

No, because the URL is just for looks; all of the logic is on the back-end. If a user manually modifies the URL entry and hits Enter, THAT would result in a change of the param value and the binding would be re-evaluated, but users are extremely unlikely to know what that value represents in the grand scheme.

So refreshing a page doesn't use its url at all ?

Oops, I take that back. Yes, if the param has been changed, refreshing the page would revert to what was supplied during the original navigation.

To be clear though, this is not "because it's the value in the URL"; the value is in the URL because it is within the Page Configuration used during navigation, and THIS is what the page will use on refresh.