Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Current »

Content Freeze

As of July 25th, 2023, there is a content freeze on this page.

pui.Timer simplifies running JavaScript repeatedly on a timer.  It is a more robust alternative to JavaScript’s native functions like setTimeout(), clearTimeout(), setInterval(), and clearInterval().

Usage

To use pui.Timer, you must first instantiate it using the new keyword. For example:

var mytimer = new pui.Timer();

Then, you can set the timer’s properties and use its methods: For example:

mytimer.timeout = 600;
mytimer.action = function() { console.log("Refreshed.") };
mytimer.start();

pui.Timer is available for use in Genie and Rich Display File applications.  You can also use it in other environments, such as custom HTML pages or within Atrium, by including the Timer.js script file located in /www/[Instance Name]/htdocs/profoundui/proddata/js.

Properties

  • timeout - timeout value in seconds
  • showDebugInfo - when set to true, shows the elapsed time in the browser's title bar
  • action - action to take when the timeout occurs, specified as a JavaScript function
  • checkFrequency - how often to check whether the timeout occurred, specified in milliseconds; default value is 1000
  • resetOnUserActivity - when set to true, resets timer if user moves the mouse or uses the keyboard

Methods

  • start() - starts the timer
  • stop() - stops the timer
  • reset() - resets the timer

Example:

Profound UI has some built-in user/session inactivity timeout features. However, these can be overridden with a custom implementation by setting the pui["client side timeout"] flag to false and creating your own timers.

To be complete, the custom implementation should have something that keeps the server alive by "pinging" it once in a while. This is because the user could be active (moving mouse around or typing) on the screen, but in the meanwhile the server side could time out.

The following example implements custom timeout and keepalive timers for Profound UI applications.

// Turn off Profound UI's built-in client-side timeout monitoring
pui["client side timeout"] = false;

var timeoutMonitor = {};

timeoutMonitor.timer = new pui.Timer();
timeoutMonitor.timer.resetOnUserActivity = true;
timeoutMonitor.timer.action = function() {
  if (getObj("timeout") != null) pui.click("timeout");
  timeoutMonitor.timer.stop();
  timeoutMonitor.keepalive.stop();
}

timeoutMonitor.keepalive = new pui["Timer"]();
timeoutMonitor.keepalive.action = function() {
  pui["keepAlive"]();
}

timeoutMonitor.start = function() {  // this is called when a screen is rendered
  timeoutMonitor.timer.stop();
  timeoutMonitor.keepalive.stop();
  if (getObj("timeout") == null) return;
  var timeout = getObj("timeout").pui.properties["user defined data"];
  if (timeout == null) return;
  timeout = Number(timeout);
  if (isNaN(timeout) || timeout <= 0) return;
  var keepAliveValue = 600;  // keep Profound UI session alive every 10 minutes
  timeoutMonitor.timer.timeout = timeout;
  //timeoutMonitor.timer.showDebugInfo = true;
  timeoutMonitor.keepalive.timeout = keepAliveValue;
  //timeoutMonitor.keepalive.showDebugInfo = true;
  timeoutMonitor.timer.start();
  timeoutMonitor.keepalive.start();
}

timeoutMonitor.end = function() {  // this is called when a screen is submitted
  timeoutMonitor.timer.stop();
  timeoutMonitor.keepalive.stop();
}

The code looks for a hidden button on your screens with an id of "timeout". This can be bound to a response indicator to let the RPG program know that the screen has timed out. This element should also have the timeout value specified in seconds in the "user defined data" property. When there is no activity, the hidden button is "pressed" by the code. 

To implement this, you can put the code into an external JavaScript file. It could go into your /www/[Instance Name]/htdocs/profoundui/userdata/custom/js directory, for example. Then, on the screen’s onload event, use timeoutMonitor.start(). And on the screen’s onsubmit event, use timeoutMonitor.end().

  • No labels