• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

How to detect a tab close event or an exit event

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to detect a tab close event or an exit event

    Is there a way to implement an exit program on the Ext-js side?
    I have a need to detect an "Exit" event (be it closing of a tab thus ending an app or closing of window) so that Ext-js can fire off a submit job on the backend to do a housekeeping routine.

  • #2
    Yes, this can be done through the Hook.js file (located in the resources/desktop/ folder). There are events for both "beforecloseapp" and "closeapp".

    Code:
    closeapp : function(app){
        Ext.Ajax.request({
            url : 'xyz',
            params : {
                closingAppId : app.appId
            }
        });
    }

    Comment


    • #3
      Thank you. I will give that a try.

      Comment


      • #4
        Hi Sean,
        Looks like there is an error after I added hook.js as Resources in my project.

        PortalError.PNG

        Also, just discovered that after I made modification to the hook.js file, I noticed that the logo reverted back to the default Valence logo.
        Should I make the changes directly onto hook.js?
        Last edited by Dleong@celsinc.com; 05-03-2016, 04:28 PM.

        Comment


        • #5
          Hello -

          Did you not modify the Hook.js under the Valence "resources/desktop" folder?

          Comment


          • #6
            I did.

            Here's the part I modified:

            HookModified.png

            I added this modified js into my project as a js resource.
            After that I ran the app in my portal.
            First thing I noticed is the error about portal not defined.
            Then I also noticed that the company logo got reverted back to Valence's.

            Comment


            • #7
              Hi Sean,
              I think I figured out what went wrong.
              I should have just modified the hook.js but NOT adding to my project as a resource.

              Now I am getting a different error.
              It seems like I have to pass the "closingAppId : app.appId" as a required parameter?
              The portal is now responding with an error message:

              HoodError.png

              How does the back end trapping works?
              I need to call my server program via vvcall.pgm with an action "housekeep" to perform a clean house.
              By the way, the appid would be different between my test environment vs my production environment. What is the best way to detect the appId or some sort of unique name?

              Sorry for causing confusion.

              Comment


              • #8
                I assume that your url is "/valence/vvcall.pgm", correct? If so, you need to authorize CX0040 to be called. You can do this via Portal Admin -> Settings. There is an input field for authorized programs.

                As far as your last question, I would have the CX0040 program chain out to the VVAPPS file using the appID that is passed....then you can determine which app is making the call.

                Does that make sense?

                Comment


                • #9
                  Hi Sean,
                  Yes, I am using "/valence/vvcall.pgm" as the url.
                  I am assuming you are referring to this?

                  ExitProgram.PNG

                  Thanks for the 2nd part, I got it.

                  Comment


                  • #10
                    No, it is labeled "Programs that may be called without checking authority" under the "IBM i Settings" section.

                    Comment


                    • #11
                      Sean,
                      Thanks for the info.

                      So, if I understand this correctly...
                      I will specify a program in the field you just mentioned in the "IBM i setting" section.
                      This program will be invoked when a close tab (in a portal) event fires off passing appId of the closing app as the only param via "/valence/vvcall.pgm" just like you put it in the previous conversation.
                      I will need to put logic into this program (CX0040 for example) to determine if a certain function needs to be executed because this program will be called upon universally whenever a tab is closed.

                      Thank you for your patience with me.

                      Comment


                      • #12
                        No problem.

                        A call will be made each time an application is closed due to the change you added to the Hook.js. The call should have a url of "/valence/vvcall.pgm" and it should also pass a "param" of "pgm" which will be set to your CX0040. You can pass any other parameters that you wish along with it. These parameters can then be pulled in by CX0040.

                        Adding the CX0040 program in the IBM i Settings section is telling the Portal that this program is allowed to be called....thus you should not get the error message you were seeing before. And yes, this program will be called universally for each app that is closed. This is why you would likely want to pass the appId as a parameter as well in case you need to perform any conditional logic based on the application that was closed.

                        Comment


                        • #13
                          Sean,
                          This is very clear. I think I got it.
                          Thank you again for your help.

                          Comment


                          • #14
                            Great, don't hesitate to post back if you run into any trouble.

                            Comment


                            • #15
                              Just wanted to post back the result.

                              The hook.js works like a charm.

                              Only catch is the backward chain to VVAPPS to find the closing program name. Unfortunately, the name has to be parsed from the VVPATH column (knowing that the program name has to be in the path for it to be launched) but not in a column by itself.

                              Thanks!

                              Comment

                              Working...
                              X