JBAS-1665 return-to=self option; timeout repairs
authorBill Erickson <berickxx@gmail.com>
Wed, 15 Feb 2017 17:33:56 +0000 (12:33 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Adds a special ?return-to=self parameter, telling the UI to return to
its own URL after completion / timeout / exit.

Rely solely on JS activity checker for page timeouts.  Otherwise, the
refresh simply overrides the activity checker.

Put all timeout value configuration into the template so no JS changes
are required for timeout changes.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/openils/var/templates_kcls/opac/register.tt2
Open-ILS/web/js/ui/default/opac/register.js

index 8efe776..2b34da7 100644 (file)
@@ -6,9 +6,6 @@
 # for privacy, reload the page after (default) 5 minutes
 return_to  = CGI.param('return-to');
 kiosk = CGI.param('kiosk');
-refresh_time = ctx.register.settings.refresh_timeout || 300; 
-complete_url = return_to || 'https://www.kcls.org'
-ctx.refresh  = refresh_time _ '; ' _ complete_url;
 
 # Ugh, CGI.new/.param insists on mangling the return-to URL. 
 # Build the redo_url by hand.
@@ -20,6 +17,19 @@ IF return_to;
 END;
 SET redo_url = redo_url _ joiner _ 'kiosk=1' IF kiosk;
 
+complete_url = 'https://www.kcls.org';
+IF return_to;
+  IF return_to == 'self';
+    # 'self' is a special return-to value that means return back to the 
+    # current URL.  Without this, to return back to the samge page, 
+    # we'd need an infinitely nesting series of return-to values.
+    # The self URL is the same as the redo ("submit another") url.
+    complete_url = redo_url;
+  ELSE;
+    complete_url = return_to;
+  END;
+END;
+
 # some useful variables and MACROs for display, 
 # field validation, and added info display
 ctx_org = ctx.physical_loc || ctx.search_ou || ctx.aou_tree.id;
@@ -70,15 +80,15 @@ END; # input_field()
 <html lang="en-US">
   <head>
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
-    <meta http-equiv="refresh" content="[% ctx.refresh %]">
     <title>[% l('[_1]', ctx.page_title) %]</title>
     [% INCLUDE 'opac/parts/goog_analytics.tt2' %]
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
     <script type="text/javascript"
       src="[% ctx.media_prefix %]/js/ui/default/opac/register.js"></script>
     <script>
-      var timeout_redirect = '[% complete_url | html %]';
-      var post_success_timeout = '[% kiosk ? 300000 : 30000 %]';
+      var timeout_redirect = '[% complete_url | url %]';
+      var post_success_timeout = '[% kiosk ? 30000 : 30000 %]';
+      var activity_timeout = '[% kiosk ? 120000 : 300000 %]';
     </script>
 
 <style>
index 2d9f189..a7cdf13 100644 (file)
@@ -17,15 +17,9 @@ var required_fields = [
 ];
 
 var last_activity = new Date();
-var activity_timeout = 300000;  // 300 seconds
 var phone_regex = new RegExp(/^\d{3}-\d{3}-\d{4}/);
 var post_regex = new RegExp(/^\d{5}(?:[-\s]\d{4})?$/);
 
-// Loaded from the template to pick up return-to URL option.
-// var timeout_redirect = 'https://www.kcls.org';
-// Loaded from the template / longer in kiosk mode
-// var post_success_timeout = 30000; 
-
 /* show/hide card options depending on the selected type. */
 function show_card_types(type) {
     last_activity = new Date();
@@ -254,22 +248,18 @@ function activity_checker_thread() {
       document.getElementById('register-success') ?
       post_success_timeout : activity_timeout;
 
-    /*
     console.debug('checking activity timeout=' + 
       timeout + ' : time range (ms) = ' + diff);
-    */
 
     if (diff > timeout) {
         location.href = timeout_redirect;
         return;
     }
 
-    setTimeout(activity_checker_thread, 2000);
+    setTimeout(activity_checker_thread, 5000);
 }
 
 
-activity_checker_thread();
-
 // No other onload should be firing for this page.
 window.onload = function() {
     // Clear all values on page load to avoid browser-back leaking
@@ -285,5 +275,7 @@ window.onload = function() {
             input.value = '';
         }
     }
+
+    activity_checker_thread();
 }