]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates/opac-new/register.tt2
LP#1778972: (follow-up) remove a NFPL-specific template
[Evergreen.git] / Open-ILS / src / templates / opac-new / register.tt2
1 [%- PROCESS "opac/parts/header.tt2";
2     PROCESS "opac/parts/org_selector.tt2";
3     WRAPPER "opac/parts/base.tt2";
4     INCLUDE "opac/parts/topnav.tt2";
5     ctx.page_title = l("Request Library Card");
6
7 # for privacy, reload the page after (default) 5 minutes
8 refresh_time = ctx.register.settings.refresh_timeout || 300; 
9 ctx.refresh = refresh_time _ '; ' _ ctx.opac_root _ '/home';
10
11 # some useful variables and MACROs for display, 
12 # field validation, and added info display
13
14 ctx_org = ctx.physical_loc || ctx.search_ou || ctx.aou_tree.id;
15
16 # list of the registration fields to (potentially) 
17 # display in the order they should be shown
18
19 # post_code is the only field below that is required in the database and
20 # post_code is only required if an address is created.
21 # To prevent any of these fields from showing locally, regardless org unit
22 # settings, simply remove the fields from this list.  In the case of 
23 # addresses, if all address fields are removed, no attempt at creating
24 # an address will be made (and post_code will no longer be required).
25
26 register_fields = [
27     {class => 'stgu',  name = 'first_given_name', label => l('First Name')},
28     {class => 'stgu',  name = 'second_given_name', label => l('Middle Name')},
29     {class => 'stgu',  name = 'family_name', label => l('Last Name')},
30     {class => 'stgu',  name = 'pref_first_given_name', label => l('Preferred First Name')},
31     {class => 'stgu',  name = 'pref_second_given_name', label => l('Preferred Middle Name')},
32     {class => 'stgu',  name = 'pref_family_name', label => l('Preferred Last Name')},
33     {class => 'stgma', name = 'street1', label => l('Street Address')},
34     {class => 'stgma', name = 'street2', label => l('Street Address (2)')},
35     {class => 'stgma', name = 'city', label => l('City')},
36     {class => 'stgma', name = 'county', label => l('County')},
37     {class => 'stgma', name = 'state', label => l('State')},
38     {class => 'stgma', name = 'post_code', label => l('Zip Code')},
39     {class => 'stgu',  name = 'dob', label => l('Date of Birth')},
40     {class => 'stgu',  name = 'day_phone', label => l('Phone Number')},
41     {class => 'stgu',  name = 'email', label => l('Email Address')}
42     {class => 'stgu',  name = 'usrname', label => l('Requested Username')}
43 ];
44
45 # The dojo date widget in the patron edit UI only accepts default 
46 # values in ISO8601 format.  It will not accept locale-shaped dates.
47 IF !ctx.register.settings.stgu.dob.example;
48     ctx.register.settings.stgu.dob.example = l('YYYY-MM-DD or YYYY/MM/DD');
49 END;
50
51 %]
52
53 <h2 class="sr-only">[% l('Account Registration') %]</h2>
54 <div id="content-wrapper">
55     <div id="main-content-register" class="container">
56         <div class="common-full-pad"></div>
57         <h1>[% l('Request a Library Card')%]</h1>
58         <span style="color:red;">&bigstar; = Required Field</span> 
59         <hr/>
60
61         [% IF ctx.register.success %]
62             <h3>[% l('Registration successful!') %]<h3>
63             <h4>[% l('Please see library staff to complete your registration.') %]</h4>
64
65             [% IF ctx.register.username_taken %]
66             <p>
67                 [% |l %]
68                 Note: The selected username may be in use by another patron.  
69                 You may select another username when finalizing your 
70                 registration or in the online catalog.
71                 [% END %]
72             </p>
73             [% END %]
74
75             <br/>
76             <p>
77                 <a href="[% ctx.opac_root %]/home" 
78                     class="btn btn-confirm">[% l('Return to the Catalog') %]</a>
79             </p>
80
81         [% ELSIF ctx.register.error %]
82             <h3>[% l('A registration error has occurred') %]</h3>
83             <h4>[% l('Please see library staff to complete your registration.') %]</h4>
84
85             <br/>
86             <p>
87                 <a href="[% ctx.opac_root %]/home" 
88                     class="btn btn-confirm">[% l('Return to the Catalog') %]</a>
89             </p>
90
91         [% ELSE %]
92
93         [% IF ctx.user %]
94             <!-- if the user is logged in, make it 
95                 clear we are tracking the requestor -->
96             <h4>[% l('New account requested by [_1] [_2] [_3] [_4] [_5]',
97                     ctx.user.prefix, ctx.user.first_given_name,
98                     ctx.user.second_given_name, ctx.user.family_name,
99                     ctx.user.suffix
100                 ) | html %]</h4>
101         [% END %]
102
103         <form method='POST' class="needs-validation" onSubmit="return dobValidate(document.getElementById('stgu.dob'))" novalidate>
104             <table class="w-100">
105                 <tr>
106                     <td width="30">
107                         <label for='stgu.home_ou'>[% l('Home Library') %]</label>
108                     </td>
109                     <td width="50">[% INCLUDE build_org_selector 
110                             name='stgu.home_ou' 
111                             value=value || ctx_org
112                             can_have_users_only=1
113                             valid_org_list=ctx.register.valid_orgs
114                         %]
115                     </td>
116                     <td width="20" >
117                         [% IF ctx.register.invalid.bad_home_ou %]
118                         <span class='patron-reg-invalid'>
119                             [% l('Please select a valid library') %]
120                         </span>
121                         [% END %]
122                 </tr>
123                 
124 [%
125 # <=== shifting code left for readability
126
127 # render the table row for each of the register fields
128 FOR field_def IN register_fields;
129     fclass = field_def.class;
130     fname = field_def.name;
131     orig_name = fname;
132
133     field_path = fclass _ "." _ fname;
134     
135     IF fname.match('^pref_');
136         # Preferred name fields adopt most visibility, etc.
137         # settings from the primary name counterparts.
138         fname = fname.remove('^pref_');
139     END;
140
141     show = ctx.register.settings.$fclass.$fname.show;
142     require = ctx.register.settings.$fclass.$fname.require;
143     example = ctx.register.settings.$fclass.$fname.example;
144     value = ctx.register.values.$fclass.$fname;
145
146     invalid_require = ctx.register.invalid.$fclass.$fname.require;
147     invalid_regex = ctx.register.invalid.$fclass.$fname.regex;
148
149     IF orig_name.match('^pref_');
150         show = show || require;
151         require = 0; # pref name values never required
152     END;
153      
154     NEXT UNLESS require OR show;
155 %]
156 <tr>
157     <td>
158         <label for='[% field_path %]'>[% field_def.label | html %]</label>
159     </td>
160     <td class="py-3">
161         <input 
162                 class='form-control'
163             type='text'
164             id='[% field_path %]'
165             name='[% field_path %]'
166             value='[% value || CGI.param(field_path) | html %]' [% IF require %]required[% END %]/>
167         <div class="invalid-feedback">
168           Please enter a [% field_def.label | html %]
169         </div>
170          [% IF example %]
171         <span class='patron-reg-extra'>
172             [% l('(Example: [_1])', example) %]
173         </span>
174     [% END %]
175     </td>
176     <td>
177         [% IF require %]
178         <span style="color:red;">&bigstar;</span>
179         [% END %]
180     <!-- display errors and example text -->
181
182     [% IF invalid_require %]
183         <span class='patron-reg-invalid'>
184             [% l('This field is required') %]
185         </span>
186     [% ELSIF invalid_regex %]
187         <span class='patron-reg-invalid'>
188             [% l('The value entered does not have the correct format') %]
189         </span>
190     [% END %]
191     [% IF example %]
192         <span class='patron-reg-extra'>
193             [% l('(Example: [_1])', example) %]
194         </span>
195     [% END %]
196
197     </td>
198 </tr>
199 [% END %]
200 <!-- ====> shifting the code back to the right for context -->
201                     [% IF ctx.register.opt_in_settings.size > 0 %]
202                         [% FOR optin IN ctx.register.opt_in_settings %]
203                         <tr>
204                             <td><label for="stgs.[% optin.name | uri %]'">[% optin.label | html %]</label></td>
205                             <td>
206                                 <input type='checkbox'
207                                     name='stgs.[% optin.name | uri %]'
208                                     id='stgs.[% optin.name | uri %]'
209                                     title="[% optin.label | html %]"
210                                 ></input>
211                             </td>
212                             <td><!-- display errors and example text --></td>
213                         </tr>
214                         [% END %]
215                     [% END %]
216                     <tr>
217                         <td colspan='3' class="text-center py-4">
218                             <a href="[% ctx.opac_root %]/home" 
219                                 class="btn btn-confirm">[% l('Go Back') %]</a>
220                             <input type="submit" 
221                                 value="[% l('Submit Registration') %]" 
222                                 class="btn btn-confirm" />
223                         </td>
224                     </tr>
225                 </table>
226             </form>
227             [% END %]
228             <div class="common-full-pad"></div> 
229         </div>
230     </div>
231 [%- END %]
232 <script>
233 (function() {
234   'use strict';
235   window.addEventListener('load', function() {
236     // Fetch all the forms we want to apply custom Bootstrap validation styles to
237     var forms = document.getElementsByClassName('needs-validation');
238     // Loop over them and prevent submission
239     var validation = Array.prototype.filter.call(forms, function(form) {
240       form.addEventListener('submit', function(event) {
241         if (form.checkValidity() === false) {
242           event.preventDefault();
243           event.stopPropagation();
244         }
245         form.classList.add('was-validated');
246       }, false);
247     });
248   }, false);
249 })();
250 </script>