execute function after profound loading

Use this board to ask questions or have discussions with other Rich Displays users.
sgagn0
Profound User
Posts: 41
Joined: Fri Aug 16, 2013 7:23 am
First Name: Sebastien
Last Name: Gagne
Company Name: Oceanex
Contact:

execute function after profound loading

Post by sgagn0 »

How can we execute a JS function after profound loading as finished?
For now we call our function from the onload event, but it seems it is too early in the process. We need to have that function executed only after profound as render the widget and loaded all is properties.
Specification: we would really like to avoid the timeout usage and would rather prefer having a way to plug our JS execution in a onready event of the page (instead of onload).

Thanks
DaveLClarkI
Experienced User
Posts: 165
Joined: Wed Dec 11, 2013 10:40 am
First Name: Dave
Last Name: Clark
Company Name: WinWholesale, Inc.
Phone: 937-294-5331
Address 1: 31101 Kettering Blvd.
City: Dayton
State / Province: Outside Canada/USA
Zip / Postal Code: 45439
Country: United States
Contact:

Re: execute function after profound loading

Post by DaveLClarkI »

I do something similar but it is completely outside of the designer. What I did was to modify my start.html page in the Profound Genie skin folder to add two lines like the following:

<script type="text/javascript" src="/jquery/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="/profoundui/userdata/WinWholesale/js/myscript.js"></script>

Then, using JQuery, I created my script file containing the function I needed to execute and tied it to the document's onready event as follows:

Code: Select all

/*
        Add any of your functions into the following which are to execute as
        the page is loading into the browser.
*/
$(document).ready(function()    // jQuery function to execute as soon as the browser page is ready
{
  // put your function here
});
sgagn0
Profound User
Posts: 41
Joined: Fri Aug 16, 2013 7:23 am
First Name: Sebastien
Last Name: Gagne
Company Name: Oceanex
Contact:

Re: execute function after profound loading

Post by sgagn0 »

We already have that type of setup where we load JS in the start.html.
In our case, the jquery ready function is triggered before the pui.onload function.
We tried to plug our javascript function execution in a bunch of places (document ready, window ready, iframe ready, ... name it). It looks like pui.onload is always triggered after those events.
From what I see we would need to have pui.onready() function that would be placed at the end of the pui.onload. We could then be sure that everything we put in there is executed once profound as completely finish working the page.
DaveLClarkI
Experienced User
Posts: 165
Joined: Wed Dec 11, 2013 10:40 am
First Name: Dave
Last Name: Clark
Company Name: WinWholesale, Inc.
Phone: 937-294-5331
Address 1: 31101 Kettering Blvd.
City: Dayton
State / Province: Outside Canada/USA
Zip / Postal Code: 45439
Country: United States
Contact:

Re: execute function after profound loading

Post by DaveLClarkI »

Interesting. Sorry I couldn't help.
sgagn0
Profound User
Posts: 41
Joined: Fri Aug 16, 2013 7:23 am
First Name: Sebastien
Last Name: Gagne
Company Name: Oceanex
Contact:

Re: execute function after profound loading

Post by sgagn0 »

no problem. thanks for trying. always good to see what others do with the product (in this case you do the same think as we do, which is integrate jquery at the start.html level).
Steve Bone
New User
Posts: 11
Joined: Wed Jul 16, 2014 6:19 am
First Name: Steve
Last Name: Bone
Company Name: Kuehne + Nagel
Contact:

Re: execute function after profound loading

Post by Steve Bone »

We had exactly the same problem.

We used a work around to solve this issue:
We used a javascript interval that checks if the needed field is filled every 100 milliseconds.
If the needed field is filled, the interval clears itself and the after load functions are executed.

Well, it's not a timeout function, but I'd still prefer an afterload() one.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: execute function after profound loading

Post by Scott Klement »

Steve, can you tell me how to reproduce the problem that you're having where Profound calls onload before it has finished loading things?

Database-driven components will load their data after the onload runs. The data loads asyncrhonously because it's not provided as part of the record format sent from the RPG program.

Aside from that, everything should already be loaded when onload fires.

There were problems awhile back with the "External JS" and "External CSS" screen-level properties where the onload could fire before these external files were loaded. Could that be it?
Steve Bone
New User
Posts: 11
Joined: Wed Jul 16, 2014 6:19 am
First Name: Steve
Last Name: Bone
Company Name: Kuehne + Nagel
Contact:

Re: execute function after profound loading

Post by Steve Bone »

Instead of just 1 .html file, we use 3;
top.html for a banner on top of the page, band.thml for a functional band on the right side, and start.html for the common usage of different other programs.
Each one should be loaded in a separate iframe and execute a different profound UI program. (So there are always 3 programs on screen.)

We had problems with synchronizing some fields via Javascript.
For example; there were fields in the banner program that manage if select boxes in the band program are disabled or not.
The onload() of the page and the onchange() event of those fields both fired before the value was applied to the fields in the banner, so the changes were applied 1 screen after they were needed.

edit:
Does the exfmt inside a RPGLE program trigger the onload() event?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: execute function after profound loading

Post by Scott Klement »

Are these database-driven select boxes? (i.e. loaded using properties in the "Database-driven Selection" category.) If so, yes, they will be loaded after the onload event fires. In that case, you'll need to load your dropdown from the RPG program to make it happen earlier, because stuff that's database-driven occurs asynchronously after the page is loaded.

Yes, the onload event is triggered by the EXFMT (or READ) opcodes from RPG. When you do EXFMT, the handler sends all of the JSON data for your screen format(s), as well as all of the variable values, to the PUI Javascript framework running in the browser. The framework will then render all of the widgets, then call your onload event. When the database-driven components are rendered, they kick off asynchronous AJAX requests to the PUI SQL database server, which performs the SQL statement to get the data, and returns it so the components are loaded. Since this is fired asynchronously when the widget is rendered, database-driven components can (and usually do) finish loading after the onload event. But data from your RPG program should always be loaded before the onload, since it's sent with the screen format.

Hope that makes sense.
Steve Bone
New User
Posts: 11
Joined: Wed Jul 16, 2014 6:19 am
First Name: Steve
Last Name: Bone
Company Name: Kuehne + Nagel
Contact:

Re: execute function after profound loading

Post by Steve Bone »

Thanks for your good explanation :)

These select boxes are not database-driven and the problem we experienced has mainly to do with the control fields within the top.html
(They are simple labels which are filled within the program)

Is there a possibility that the onload event could be fired some when else before the values are applied?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest