JBAS-1665 Self-register return-to/no-wrapper options
authorBill Erickson <berickxx@gmail.com>
Fri, 6 Jan 2017 19:49:31 +0000 (14:49 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
New URL parameter controls:

return-to=https://example.org -- override the default post-submit and
timeout redirect URL.

no-wrapper=1 -- hide the kcls.org header/footers.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/openils/var/templates_kcls/opac/register.tt2
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm
Open-ILS/web/js/ui/default/opac/register.js

index 82618fd..3f64b28 100644 (file)
@@ -4,8 +4,21 @@
     ctx.page_title = l("Get a Library Card");
 
 # for privacy, reload the page after (default) 5 minutes
+return_to  = CGI.param('return-to');
+no_wrapper = CGI.param('no-wrapper');
 refresh_time = ctx.register.settings.refresh_timeout || 300; 
-ctx.refresh = refresh_time _ '; ' _ 'https://www.kcls.org';
+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.
+redo_url = '/eg/opac/register';
+IF return_to;
+  redo_url = redo_url _ '?return-to=' _ return_to;
+  SET redo_url = redo_url _ '&no-wrapper=1' IF no_wrapper;
+ELSIF no_wrapper;
+  redo_url = redo_url _ '?no-wrapper=1';
+END;
 
 # some useful variables and MACROs for display, 
 # field validation, and added info display
@@ -64,6 +77,9 @@ END; # input_field()
     <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 %]';
+    </script>
 
 <style>
 /* Keep the CSS here for now for simplicity.  
@@ -193,19 +209,21 @@ END; # input_field()
 
     [% IF ctx.register.success %]
       <h2>[% l('Registration successful!') %]<h3>
-      <a href='/eg/opac/register'><button 
+      <a href='[% redo_url | html %]'><button 
         id='submit-another'>Submit Another Application</button></a>
       <br/>
       <br/>
       <div class='success-minus-2'>
         You will be automatically redirected to 
-        <a href="https://www.kcls.org">www.kcls.org</a>...
+        <a href="[% complete_url | html %]">[% complete_url | html %]</a>...
       </div>
       <hr/>
       <input type='hidden' id='register-success' value='yep'/>
     [% ELSE %]
 
     <form method='POST' onsubmit="return onsub()">
+      <input type="hidden" name="return-to"  value="[% return_to %]"/>
+      <input type="hidden" name="no-wrapper" value="[% no_wrapper %]"/>
       <ul>
         <li>
           <label>Choose a card size....</label>
@@ -528,7 +546,7 @@ END; # input_field()
               <input type="submit" value="[% l('Submit Registration') %]"/>
             </div>
             <div class="grid-cell">
-              <button onclick="location.href='https://www.kcls.org/'; return false">
+              <button onclick="location.href='[% complete_url | html %]'; return false">
                 Cancel and Return to KCLS
               </button>
             </div>
index 6bdd3d0..fcc4067 100644 (file)
@@ -497,6 +497,9 @@ my $footer;
 sub collect_header_footer {
     my $self = shift;
 
+    # no-wrapper == no header/footer
+    return if $self->cgi->param('no-wrapper');
+
     if ($header) {
         $self->ctx->{register_header} = $header;
         $self->ctx->{register_footer} = $footer;
index cb1a864..4d8c78c 100644 (file)
@@ -19,10 +19,12 @@ var required_fields = [
 var last_activity = new Date();
 var activity_timeout = 300000;  // 300 seconds
 var post_success_timeout = 30000; // 15 seconds
-var timeout_redirect = 'https://www.kcls.org';
 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';
+
 /* show/hide card options depending on the selected type. */
 function show_card_types(type) {
     last_activity = new Date();