Patron reg field validation (WIP)
authorBill Erickson <berickxx@gmail.com>
Mon, 29 Feb 2016 23:51:55 +0000 (18:51 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 29 Feb 2016 23:51:55 +0000 (18:51 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/circ/patron/t_edit.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index 5a0aa9d..84e3ab5 100644 (file)
   </div>
 [% END %]
 
+
+[% 
+# draws a vanilla form input field for inputs that require no 
+# special additions.
+MACRO draw_form_input(cls, field, path, type, required) BLOCK;
+  IF !type; type = 'text'; END;
+  base_obj = path ? 'patron.' _ path : 'patron';
+  model = base_obj _ '.' _ field;
+%]
+  <div class="col-md-3 reg-field-input">
+    <input 
+      type="[% type %]" 
+      class="form-control" 
+      name="[% model %]"
+      ng-change="field_modified()" 
+      ng-required="field_required('[% cls %]', '[% field %]')"
+      ng-blur="handle_field_changed([% base_obj %], '[% field %]')"
+      ng-pattern="field_pattern('[% cls %]', '[% field %]')"
+      ng-class="{'patron-reg-invalid-field' : field_is_invalid('[% model %]')}"
+      ng-model="[% model %]"/>
+  </div>
+[% END %]
+
+[% MACRO draw_example_text(cls, field) BLOCK;
+  set_str = "org_settings['ui.patron.edit." _ cls _ "." _ field _ ".example']";
+%]
+  <span ng-if="[% set_str %]">
+    [% l('Example: [_1]', '{{' _ set_str _ '}}') %]
+  </span>
+[% END %]
+
 <!-- progress dialog displayed as we await all data to finish loading -->
 <div class="row" ng-show="!page_data_loaded">
   <div class="col-md-6 pad-vert">
@@ -113,7 +144,7 @@ within the "form" by name for validation.
         ng-model="patron.card.barcode"
         ng-class="{'patron-reg-invalid-field' : field_is_invalid('barcode')}"
         ng-pattern="field_pattern('ac', 'barcode')"
-        ng-required="true"
+        ng-required="field_required('ac', 'barcode')"
         focus-me="focus_bc"
         ng-change="field_modified()" 
         ng-disabled="disable_bc"
@@ -137,7 +168,7 @@ within the "form" by name for validation.
     <input type="text" 
       name='usrname'
       ng-class="{'patron-reg-invalid-field' : field_is_invalid('usrname')}"
-      ng-required="true"
+      ng-required="field_required('au', 'usrname')"
       focus-me="focus_usrname"
       ng-change="field_modified()" 
       ng-pattern="field_pattern('au', 'usrname')"
@@ -156,17 +187,7 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.passwd')">
   [% draw_field_label('au', 'passwd') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="text" 
-      name='passwd'
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('passwd')}"
-      ng-pattern="field_pattern('au', 'passwd')"
-      ng-required="true"
-      ng-change="field_modified()" 
-      ng-blur="handle_field_changed(patron, 'passwd')"
-      class="form-control" 
-      ng-model="patron.passwd"/>
-  </div>
+  [% draw_form_input('au', 'passwd'); %]
   <div class="col-md-6 patron-reg-example">
     <button class="btn btn-default" ng-click="generate_password()">
       [% l('Generate Password') %]</button>
@@ -177,21 +198,9 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.prefix')">
   [% draw_field_label('au', 'prefix') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <input type="text" 
-      ng-change="field_modified()" 
-      class="form-control" 
-      name="prefix"
-      ng-blur="handle_field_changed(patron, 'prefix')"
-      ng-pattern="field_pattern('au', 'prefix')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('prefix')}"
-      ng-required="org_settings['ui.patron.edit.au.prefix.require']"
-      ng-model="patron.prefix"/>
-  </div>
+  [% draw_form_input('au', 'prefix'); %]
   <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.au.prefix.example']">
-        [% l('Example: [_1]', "{{org_settings['ui.patron.edit.au.prefix.example']}}") %]
-      </span>
+    [% draw_example_text('au', 'prefix') %]
   </div>
 </div>
 
@@ -199,19 +208,9 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.first_given_name')">
   [% draw_field_label('au', 'first_given_name') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="text" 
-      ng-change="field_modified()" 
-      name="first_given_name"
-      ng-pattern="field_pattern('au', 'first_given_name')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('first_given_name')}"
-      ng-blur="handle_field_changed(patron, 'first_given_name')"
-      class="form-control" ng-model="patron.first_given_name"/>
-  </div>
+  [% draw_form_input('au', 'first_given_name'); %]
   <div class="col-md-6 patron-reg-example">
-    <span ng-if="org_settings['ui.patron.edit.au.first_given_name.example']">
-      [% l('Example: [_1]', "{{org_settings['ui.patron.edit.au.first_given_name.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'first_given_name') %]
   </div>
 </div>
 
@@ -219,19 +218,9 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.second_given_name')">
   [% draw_field_label('au', 'second_given_name') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <input type="text" 
-      name="second_given_name"
-      ng-change="field_modified()" 
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('second_given_name')}"
-      ng-pattern="field_pattern('au', 'second_given_name')"
-      class="form-control" ng-model="patron.second_given_name"/>
-  </div>
+  [% draw_form_input('au', 'second_given_name'); %]
   <div class="col-md-6 patron-reg-example">
-    <span ng-if="org_settings['ui.patron.edit.au.second_given_name.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.second_given_name.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'second_given_name') %]
   </div>
 </div>
 
@@ -239,20 +228,9 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.family_name')">
   [% draw_field_label('au', 'family_name') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <input type="text" 
-      name="family_name"
-      ng-change="field_modified()" 
-      ng-pattern="field_pattern('au', 'family_name')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('family_name')}"
-      ng-blur="handle_field_changed(patron, 'family_name')"
-      class="form-control" ng-model="patron.family_name"/>
-  </div>
+  [% draw_form_input('au', 'family_name'); %]
   <div class="col-md-6 patron-reg-example">
-    <span ng-if="org_settings['ui.patron.edit.au.family_name.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.family_name.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'family_name') %]
   </div>
 </div>
 
@@ -260,21 +238,9 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.suffix')">
   [% draw_field_label('au', 'suffix') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <input type="text" 
-      name="suffix"
-      ng-change="field_modified()" 
-      ng-blur="handle_field_changed(patron, 'suffix')"
-      ng-pattern="field_pattern('au', 'suffix')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('suffix')}"
-      class="form-control" 
-      ng-model="patron.suffix"/>
-  </div>
+  [% draw_form_input('au', 'suffix'); %]
   <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.au.suffix.example']">
-        [% l('Example: [_1]', 
-          "{{org_settings['ui.patron.edit.au.suffix.example']}}") %]
-      </span>
+    [% draw_example_text('au', 'suffix') %]
   </div>
 </div>
 
@@ -282,21 +248,9 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.alias')">
   [% draw_field_label('au', 'alias') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <input type="text" 
-      name="alias"
-      ng-change="field_modified()" 
-      ng-blur="handle_field_changed(patron, 'alias')"
-      ng-pattern="field_pattern('au', 'alias')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('alias')}"
-      class="form-control" 
-      ng-model="patron.alias"/>
-  </div>
+  [% draw_form_input('au', 'alias'); %]
   <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.au.alias.example']">
-        [% l('Example: [_1]', 
-          "{{org_settings['ui.patron.edit.au.alias.example']}}") %]
-      </span>
+    [% draw_example_text('au', 'alias') %]
   </div>
 </div>
 
@@ -313,10 +267,7 @@ within the "form" by name for validation.
       class="form-control" ng-model="patron.dob"/>
   </div>
   <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.au.dob.example']">
-        [% l('Example: [_1]', 
-          "{{org_settings['ui.patron.edit.au.dob.example']}}") %]
-      </span>
+    [% draw_example_text('au', 'dob') %]
   </div>
 </div>
 
@@ -324,15 +275,7 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.juvenile')">
   [% draw_field_label('au', 'juvenile') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="checkbox"
-      name="juvenile"
-      ng-change="field_modified()" 
-      ng-pattern="field_pattern('au', 'juvenile')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('juvenile')}"
-      ng-blur="handle_field_changed(patron, 'juvenile')"
-      class="form-control" ng-model="patron.juvenile"/>
-  </div>
+  [% draw_form_input('au', 'alias', '', 'checkbox'); %]
 </div>
 
 <!-- ident_type -->
@@ -362,58 +305,26 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.ident_value')">
   [% draw_field_label('au', 'ident_value') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="text" 
-      ng-change="field_modified()" 
-      name="ident_value"
-      ng-blur="handle_field_changed(patron, 'ident_value')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('ident_value')}"
-      ng-pattern="field_pattern('au', 'ident_value')"
-      class="form-control" 
-      ng-model="patron.ident_value"/>
-  </div>
+  [% draw_form_input('au', 'ident_value') %]
   <div class="col-md-6 patron-reg-example">
-    <span ng-if="org_settings['ui.patron.edit.au.ident_value.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.ident_value.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'ident_value') %]
   </div>
 </div>
 
 <!-- IDENT_VALUE2 -->
 <div class="row reg-field-row" ng-show="show_field('au.ident_value2')">
   [% draw_field_label('au', 'ident_value2') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="text" 
-      name="ident_value2"
-      ng-change="field_modified()" 
-      ng-pattern="field_pattern('au', 'ident_valued')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('ident_value2')}"
-      ng-blur="handle_field_changed(patron, 'ident_value2')"
-      class="form-control" 
-      ng-model="patron.ident_value2"/>
-  </div>
+  [% draw_form_input('au', 'ident_value2') %]
   <div class="col-md-6 patron-reg-example">
-    <span ng-if="org_settings['ui.patron.edit.au.ident_value2.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.ident_value2.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'ident_value2') %]
   </div>
 </div>
 
 
 <!-- EMAIL -->
 <div class="row reg-field-row" ng-show="show_field('au.email')">
-  [% draw_field_label('au', 'ident_value2') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="email" 
-      name="email"
-      ng-change="field_modified()" 
-      ng-pattern="field_pattern('au', 'email')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('email')}"
-      ng-blur="handle_field_changed(patron, 'email')"
-      class="form-control" ng-model="patron.email"/>
-  </div>
+  [% draw_field_label('au', 'email') %]
+  [% draw_form_input('au', 'email', '', 'email') %]
   <div class="col-md-6 patron-reg-example">
     <button ng-show="patron.email && !patron.isnew" 
       class="btn btn-default" 
@@ -429,23 +340,12 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.day_phone')">
   [% draw_field_label('au', 'day_phone') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="text" 
-      name="day_phone"
-      ng-blur="handle_field_changed(patron, 'day_phone')"
-      ng-change="field_modified()" 
-      ng-pattern="field_pattern('au', 'day_phone')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('day_phone')}"
-      class="form-control" ng-model="patron.day_phone"/>
-  </div>
+  [% draw_form_input('au', 'day_phone') %]
   <div class="col-md-6 patron-reg-example">
     <button ng-show="patron.day_phone && !patron.isnew" 
         class="btn btn-default" 
         ng-click="invalidate_field('day_phone')">[% l('Invalidate') %]</button>
-    <span ng-if="org_settings['ui.patron.edit.au.day_phone.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.day_phone.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'day_phone') %]
     <!-- phones have a fall-through example strings -->
     <span ng-if="!org_settings['ui.patron.edit.au.day_phone.example'] && org_settings['ui.patron.edit.phone.example']">
       [% l('Example: [_1]', 
@@ -458,23 +358,12 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.evening_phone')">
   [% draw_field_label('au', 'evening_phone') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="text" 
-      name="evening_phone"
-      ng-pattern="field_pattern('au', 'evening_phone')"
-      ng-blur="handle_field_changed(patron, 'evening_phone')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('evening_phone')}"
-      ng-change="field_modified()" 
-      class="form-control" ng-model="patron.evening_phone"/>
-  </div>
+  [% draw_form_input('au', 'evening_phone') %]
   <div class="col-md-6 patron-reg-example">
     <button ng-show="patron.evening_phone && !patron.isnew" 
         class="btn btn-default" 
         ng-click="invalidate_field('evening_phone')">[% l('Invalidate') %]</button>
-    <span ng-if="org_settings['ui.patron.edit.au.evening_phone.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.evening_phone.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'evening_phone') %]
     <!-- phones have a fall-through example strings -->
     <span ng-if="!org_settings['ui.patron.edit.au.evening_phone.example'] && org_settings['ui.patron.edit.phone.example']">
       [% l('Example: [_1]', 
@@ -487,23 +376,12 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.other_phone')">
   [% draw_field_label('au', 'other_phone') %]
-  <div class="col-md-3 reg-field-input">
-    <input type="text" 
-      name="other_phone"
-      ng-blur="handle_field_changed(patron, 'other_phone')"
-      ng-pattern="field_pattern('au', 'other_phone')"
-      ng-class="{'patron-reg-invalid-field' : field_is_invalid('other_phone')}"
-      ng-change="field_modified()" 
-      class="form-control" ng-model="patron.other_phone"/>
-  </div>
+  [% draw_form_input('au', 'other_phone') %]
   <div class="col-md-6 patron-reg-example">
     <button ng-show="patron.other_phone && !patron.isnew" 
         class="btn btn-default" 
         ng-click="invalidate_field('other_phone')">[% l('Invalidate') %]</button>
-    <span ng-if="org_settings['ui.patron.edit.au.other_phone.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.other_phone.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'other_phone') %]
     <!-- phones have a fall-through example strings -->
     <span ng-if="!org_settings['ui.patron.edit.au.other_phone.example'] && org_settings['ui.patron.edit.phone.example']">
       [% l('Example: [_1]', 
@@ -590,56 +468,30 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.active')">
   [% draw_field_label('au', 'active') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <div class='checkbox'>
-      <input type='checkbox' 
-        ng-blur="handle_field_changed(patron, 'active')"
-        ng-model='patron.active'/>
-    </div>
-  </div>
+  [% draw_form_input('au', 'active', '', 'checkbox') %]
 </div>
 
 <!-- BARRED -->
 
 <div class="row reg-field-row" ng-show="show_field('au.barred')">
   [% draw_field_label('au', 'barred') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <div class='checkbox'>
-      <input type='checkbox' 
-        ng-blur="handle_field_changed(patron, 'barred')"
-        ng-model='patron.barred'/>
-    </div>
-  </div>
+  [% draw_form_input('au', 'barred', '', 'checkbox') %]
 </div>
 
 <!-- MASTER_ACCOUNT -->
 
 <div class="row reg-field-row" ng-show="show_field('au.master_account')">
   [% draw_field_label('au', 'master_account') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <div class='checkbox'>
-      <input type='checkbox' 
-        ng-blur="handle_field_changed(patron, 'master_account')"
-        ng-model='patron.master_account'/>
-    </div>
-  </div>
+  [% draw_form_input('au', 'master_account', '', 'checkbox') %]
 </div>
 
 <!-- CLAIMS_RETURNED_COUNT -->
 
 <div class="row reg-field-row" ng-show="show_field('au.claims_returned_count')">
   [% draw_field_label('au', 'claims_returned_count') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <input type="number" 
-      ng-blur="handle_field_changed(patron, 'claims_returned_count')"
-      ng-change="field_modified()" 
-      class="form-control" ng-model="patron.claims_returned_count"/>
-  </div>
+  [% draw_form_input('au', 'claims_returned_count', '', 'number') %]
   <div class="col-md-6 patron-reg-example">
-    <span ng-if="org_settings['ui.patron.edit.au.claims_returned_count.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.claims_returned_count.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'claims_returned_count') %]
   </div>
 </div>
 
@@ -647,17 +499,9 @@ within the "form" by name for validation.
 
 <div class="row reg-field-row" ng-show="show_field('au.claims_never_checked_out_count')">
   [% draw_field_label('au', 'claims_never_checked_out_count') %]
-  <div class="col-md-3 reg-field-input"> <!-- field form input -->
-    <input type="number" 
-      ng-blur="handle_field_changed(patron, 'claims_never_checked_out_count')"
-      ng-change="field_modified()" 
-      class="form-control" ng-model="patron.claims_never_checked_out_count"/>
-  </div>
+  [% draw_form_input('au', 'claims_never_checked_out_count', '', 'number') %]
   <div class="col-md-6 patron-reg-example">
-    <span ng-if="org_settings['ui.patron.edit.au.claims_never_checked_out_count.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.claims_never_checked_out_count.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'claims_never_checked_out_count') %]
   </div>
 </div>
 
@@ -672,12 +516,10 @@ within the "form" by name for validation.
       ng-pattern="field_pattern('au', 'alert_message')"
       ng-change="field_modified()" 
       ng-blur="handle_field_changed(patron, 'alert_message')">
+    </textarea>
   </div>
   <div class="col-md-6 patron-reg-example">
-    <span ng-if="org_settings['ui.patron.edit.au.alert_message.example']">
-      [% l('Example: [_1]', 
-        "{{org_settings['ui.patron.edit.au.alert_message.example']}}") %]
-    </span>
+    [% draw_example_text('au', 'alert_message') %]
   </div>
 </div>
 
@@ -825,18 +667,9 @@ within the "form" by name for validation.
   <!-- ADDRESS_TYPE -->
   <div class="row reg-field-row" ng-show="show_field('aua.address_type')">
     [% draw_field_label('aua', 'address_type') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="text" 
-        ng-change="field_modified()" 
-        ng-pattern="field_pattern('aua', 'address_type')"
-        class="form-control" 
-        ng-model="patron.addresses[$index].address_type"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'address_type')"/>
-    </div>
+    [% draw_form_input('aua', 'address_type', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.address_type.example']">
-         Example: {{org_settings['ui.patron.edit.aua.address_type.example']}}
-       </span>
+      [% draw_example_text('au', 'address_type') %]
     </div>
   </div>
 
@@ -844,18 +677,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.post_code')">
     [% draw_field_label('aua', 'post_code') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="text" 
-        ng-change="field_modified()" 
-        ng-pattern="field_pattern('aua', 'post_code')"
-        class="form-control" 
-        ng-model="patron.addresses[$index].post_code"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'post_code')"/>
-    </div>
+    [% draw_form_input('aua', 'post_code', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.post_code.example']">
-         Example: {{org_settings['ui.patron.edit.aua.post_code.example']}}
-       </span>
+      [% draw_example_text('au', 'post_code') %]
     </div>
   </div>
 
@@ -863,18 +687,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.street1')">
     [% draw_field_label('aua', 'street1') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="text" 
-        ng-change="field_modified()" 
-        ng-pattern="field_pattern('aua', 'street1')"
-        class="form-control" 
-        ng-model="patron.addresses[$index].street1"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'street1')"/>
-    </div>
+    [% draw_form_input('aua', 'street1', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.street1.example']">
-         Example: {{org_settings['ui.patron.edit.aua.street1.example']}}
-       </span>
+      [% draw_example_text('au', 'street1') %]
     </div>
   </div>
 
@@ -882,18 +697,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.street2')">
     [% draw_field_label('aua', 'street2') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="text" 
-        ng-change="field_modified()" 
-        ng-pattern="field_pattern('aua', 'street2')"
-        class="form-control" 
-        ng-model="patron.addresses[$index].street2"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'street2')"/>
-    </div>
+    [% draw_form_input('aua', 'street2', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.street2.example']">
-         Example: {{org_settings['ui.patron.edit.aua.street2.example']}}
-       </span>
+      [% draw_example_text('au', 'street2') %]
     </div>
   </div>
 
@@ -901,18 +707,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.city')">
     [% draw_field_label('aua', 'city') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="text" 
-        ng-change="field_modified()" 
-        ng-pattern="field_pattern('aua', 'city')"
-        class="form-control" 
-        ng-model="patron.addresses[$index].city"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'city')"/>
-    </div>
+    [% draw_form_input('aua', 'city', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.city.example']">
-         Example: {{org_settings['ui.patron.edit.aua.city.example']}}
-       </span>
+      [% draw_example_text('au', 'city') %]
     </div>
   </div>
 
@@ -920,18 +717,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.county')">
     [% draw_field_label('aua', 'county') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="text" 
-        ng-change="field_modified()" 
-        ng-pattern="field_pattern('aua', 'county')"
-        class="form-control" 
-        ng-model="patron.addresses[$index].county"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'county')"/>
-    </div>
+    [% draw_form_input('aua', 'county', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.county.example']">
-         Example: {{org_settings['ui.patron.edit.aua.county.example']}}
-       </span>
+      [% draw_example_text('au', 'county') %]
     </div>
   </div>
 
@@ -939,18 +727,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.state')">
     [% draw_field_label('aua', 'state') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="text" 
-        ng-change="field_modified()" 
-        ng-pattern="field_pattern('aua', 'state')"
-        class="form-control" 
-        ng-model="patron.addresses[$index].state"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'state')"/>
-    </div>
+    [% draw_form_input('aua', 'state', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.state.example']">
-         Example: {{org_settings['ui.patron.edit.aua.state.example']}}
-       </span>
+      [% draw_example_text('au', 'state') %]
     </div>
   </div>
 
@@ -958,18 +737,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.country')">
     [% draw_field_label('aua', 'country') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="text" 
-        ng-change="field_modified()" 
-        ng-pattern="field_pattern('aua', 'country')"
-        class="form-control" 
-        ng-model="patron.addresses[$index].country"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'country')"/>
-    </div>
+    [% draw_form_input('aua', 'country', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.country.example']">
-         Example: {{org_settings['ui.patron.edit.aua.country.example']}}
-       </span>
+      [% draw_example_text('au', 'country') %]
     </div>
   </div>
 
@@ -977,16 +747,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.valid')">
     [% draw_field_label('aua', 'valid') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="checkbox" 
-        class="form-control" 
-        ng-model="patron.addresses[$index].valid"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'valid')"/>
-    </div>
+    [% draw_form_input('aua', 'valid', 'addresses[$index]', 'checkbox') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.valid.example']">
-         Example: {{org_settings['ui.patron.edit.aua.valid.example']}}
-       </span>
+      [% draw_example_text('au', 'valid') %]
     </div>
   </div>
 
@@ -994,16 +757,9 @@ within the "form" by name for validation.
 
   <div class="row reg-field-row" ng-show="show_field('aua.within_city_limits')">
     [% draw_field_label('aua', 'within_city_limits') %]
-    <div class="col-md-3 reg-field-input">
-      <input type="checkbox" 
-        class="form-control" 
-        ng-model="patron.addresses[$index].within_city_limits"
-        ng-blur="handle_field_changed(patron.addresses[$index], 'within_city_limits')"/>
-    </div>
+    [% draw_form_input('aua', 'within_city_limits', 'addresses[$index]', 'checkbox') %]
     <div class="col-md-6 patron-reg-example">
-      <span ng-if="org_settings['ui.patron.edit.aua.within_city_limits.example']">
-         Example: {{org_settings['ui.patron.edit.aua.within_city_limits.example']}}
-       </span>
+      [% draw_example_text('au', 'within_city_limits') %]
     </div>
   </div>
 
index 79bd673..02e7575 100644 (file)
@@ -1143,25 +1143,28 @@ function PatronRegCtrl($scope, $routeParams,
     };
 
     // field visibility cache.  Some fields are universally required.
+    // 3 == value universally required
+    // 2 == field is visible by default
+    // 1 == field is suggested by default
     var field_visibility = {
-        'ac.barcode' : 2,
-        'au.usrname' : 2,
-        'au.passwd' :  2,
-        'au.first_given_name' : 2,
-        'au.family_name' : 2,
-        'au.ident_type' : 2,
-        'au.home_ou' : 2,
-        'au.profile' : 2,
-        'au.expire_date' : 2,
-        'au.net_access_level' : 2,
-        'aua.address_type' : 2,
-        'aua.post_code' : 2,
-        'aua.street1' : 2,
+        'ac.barcode' : 3,
+        'au.usrname' : 3,
+        'au.passwd' :  3,
+        'au.first_given_name' : 3,
+        'au.family_name' : 3,
+        'au.ident_type' : 3,
+        'au.home_ou' : 3,
+        'au.profile' : 3,
+        'au.expire_date' : 3,
+        'au.net_access_level' : 3,
+        'aua.address_type' : 3,
+        'aua.post_code' : 3,
+        'aua.street1' : 3,
         'aua.street2' : 2,
-        'aua.city' : 2,
+        'aua.city' : 3,
         'aua.county' : 2,
         'aua.state' : 2,
-        'aua.country' : 2,
+        'aua.country' : 3,
         'aua.valid' : 2,
         'aua.within_city_limits' : 2,
         'stat_cats' : 1,
@@ -1183,7 +1186,7 @@ function PatronRegCtrl($scope, $routeParams,
             var sug_set = 'ui.patron.edit.' + field_key + '.suggest';
 
             if ($scope.org_settings[req_set]) {
-                field_visibility[field_key] = 2;
+                field_visibility[field_key] = 3;
             } else if ($scope.org_settings[sho_set]) {
                 field_visibility[field_key] = 2;
             } else if ($scope.org_settings[sug_set]) {
@@ -1196,6 +1199,12 @@ function PatronRegCtrl($scope, $routeParams,
         return field_visibility[field_key] >= $scope.edit_passthru.vis_level;
     }
 
+    // See $scope.show_field().
+    // A field with visbility level 3 means it's required.
+    $scope.field_required = function(cls, field) {
+        return (field_visibility[cls + '.' + field] == 3);
+    }
+
     // generates a random 4-digit password
     $scope.generate_password = function() {
         $scope.patron.passwd = Math.floor(Math.random()*9000) + 1000;