3 Replies Latest reply on May 21, 2015 5:21 PM by John Snyders-Oracle

    Apex 5 declarative modals and post-close actions on source page

    Nathan Rooney-Oracle

      Hi, I have a question on the interaction between the source page and the new apex 5 declarative modals.

       

      Let's say that I have a report region on my source page that displays a set of data and I have a modal dialog page with a form to add data to the underlying table.  When I create a new entry via the modal I'd like to refresh the report region on the source page and trigger an alert stating that a new row was added after the modal has closed.

       

      What's the proper way to handle this communication between the pages?  The source page currently needs to be refreshed to display the newly added rows, but I'd prefer to handle this through a partial-page refresh.

       

      It looks like I can create a dynamic action to fire on the source page on a dialog closed event, but to handle the specific situation appropriately it seems that when I spring the dialog that I'll also need to track the particular action to indicate what I was intending to do in the modal, specifically, say, an update vs a create, etc.  Then when the dialog is closed I will need to look up whatever sort of flagging field I used in the source field to determine what the dialog was up to and then spring the appropriate actions through the DA.

       

      Is it the opinion of the community that this is the best way forward, or is there a more straight-forward way to directly tie an action in the modal dialog back to the source page?

       

      Thanks

        • 1. Re: Apex 5 declarative modals and post-close actions on source page
          Nathan Rooney-Oracle

          OK, I think that I understand how to do this.  I don't necessarily understand all of the mechanics of this, but I can now predict the outcome.

           

          Let's say that I have a create button on page 1 that opens a modal dialog on page 2.  I also have a report region with update buttons also pointing to the modal form on page 2.

           

          I can set up 2 close dialog dynamic actions on page 1.

           

          For the create confirmation I can choose an Event of 'Dialog Closed', a selection type of 'Button' and choose my create button, then in the True action I can add my alert for successful creation.

           

          For the update confirmation I can choose a selection type of 'Region' and choose the my report region that holds my update buttons and add a True action that fires my alert for updating.

           

          The selection type and item/button/region designation is the key differentiator that allowed me to tailor this accordingly.

           

          The modal dialog is actually an iframe pointing to the dialog page that's dynamically appended to the body of the source page when invoked.  The url contains a long 'cs=' string appended to it.  The source button also includes a similar 'cs=' query string.  I'm assuming that these values are what tie these together and allow the proper communication between the source page and iframe to allow the dynamic actions to sync appropriately.

          • 2. Re: Apex 5 declarative modals and post-close actions on source page
            John Snyders-Oracle

            Hi Nathan,

            Sounds like you have a good handle on the situation. The report page should have a DA to listen for the Dialog Closed event and it can then refresh the report. What is missing is how to tell what kind of edit was made in the dialog. The way to handle that is when the dialog page is submitted it ends with a Close Dialog process. Under settings on the Close Dialog process there is Page Items to Return. So just return a page item that contains a value such as "create" or "update". If you don't already have a page item like that you can add a hidden one and if needed even populate the value with a process. Then in the Dialog Closed event DA you can read the value of that item and display an appropriate alert. I would use a JavaScript action and get the value like so (assume the dialog item to return is P50_CHANGE_TYPE):

             

            if (this.data.P50_CHANGE_TYPE === "create") {

              alert("A new row was added");

            else {

              alert("A row was updated");

            }

             

            To generalize: the way for a dialog to communicate any kind of data (including info about actions taken) to any interested calling page is through the Page Items to return attribute. This is true if you are using the Close Dialog process or the Close Dialog dynamic action.

             

            Regards,

            -John

            • 3. Re: Apex 5 declarative modals and post-close actions on source page
              John Snyders-Oracle

              Distinguishing what happened based on where the dialog was opened from will work in your specific situation but I think it is better and more general to let the dialog tell you what it did. That way you can have just a single Dialog Closed handler. In your situation you will need to handle the event on an element above both the region and the button so you capture both events. You could use a jQuery selector of body.