Patron reg field validation (WIP)
authorBill Erickson <berickxx@gmail.com>
Sat, 5 Mar 2016 20:52:56 +0000 (15:52 -0500)
committerBill Erickson <berickxx@gmail.com>
Sat, 5 Mar 2016 20:52:56 +0000 (15:52 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/circ/patron/reg_actions.tt2
Open-ILS/src/templates/staff/circ/patron/t_edit.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index 3640961..1508018 100644 (file)
 <div>
   <span class="pad-all-min">
     <button type="button" class="btn btn-default" 
-      ng-disabled="edit_passthru.has_invalid_fields()"
+      ng-disabled="edit_passthru.hide_save_actions()"
       ng-click="edit_passthru.save()">[% l('Save') %]</button>
   </span>
   <span class="pad-all-min">
     <button type="button" class="btn btn-default"
-      ng-disabled="edit_passthru.has_invalid_fields()"
+      ng-disabled="edit_passthru.hide_save_actions()"
       ng_click="edit_passthru.save({clone:true})">[% l('Save & Clone') %]</button>
   </span>
 </div>
index 13a974a..5dc691a 100644 (file)
@@ -384,7 +384,10 @@ within the "form" by name for validation.
 <div class="row reg-field-row" ng-show="show_field('au.home_ou')">
   [% draw_field_label('au', 'home_ou') %]
   <div class="col-md-3 reg-field-input">
-    <eg-org-selector selected="patron.home_ou" onchange="handle_home_org_changed">
+    <eg-org-selector 
+      selected="patron.home_ou" 
+      onchange="handle_home_org_changed"
+      disable-test="disable_home_org">
     </eg-org-selector>
   </div>
 </div>
@@ -651,7 +654,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'address_type') %]
     [% draw_form_input('aua', 'address_type', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'address_type') %]
+      [% draw_example_text('aua', 'address_type') %]
     </div>
   </div>
 
@@ -661,7 +664,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'post_code') %]
     [% draw_form_input('aua', 'post_code', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'post_code') %]
+      [% draw_example_text('aua', 'post_code') %]
     </div>
   </div>
 
@@ -671,7 +674,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'street1') %]
     [% draw_form_input('aua', 'street1', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'street1') %]
+      [% draw_example_text('aua', 'street1') %]
     </div>
   </div>
 
@@ -681,7 +684,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'street2') %]
     [% draw_form_input('aua', 'street2', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'street2') %]
+      [% draw_example_text('aua', 'street2') %]
     </div>
   </div>
 
@@ -691,7 +694,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'city') %]
     [% draw_form_input('aua', 'city', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'city') %]
+      [% draw_example_text('aua', 'city') %]
     </div>
   </div>
 
@@ -701,7 +704,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'county') %]
     [% draw_form_input('aua', 'county', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'county') %]
+      [% draw_example_text('aua', 'county') %]
     </div>
   </div>
 
@@ -711,7 +714,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'state') %]
     [% draw_form_input('aua', 'state', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'state') %]
+      [% draw_example_text('aua', 'state') %]
     </div>
   </div>
 
@@ -721,7 +724,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'country') %]
     [% draw_form_input('aua', 'country', 'addresses[$index]') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'country') %]
+      [% draw_example_text('aua', 'country') %]
     </div>
   </div>
 
@@ -731,7 +734,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'valid') %]
     [% draw_form_input('aua', 'valid', 'addresses[$index]', 'checkbox') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'valid') %]
+      [% draw_example_text('aua', 'valid') %]
     </div>
   </div>
 
@@ -741,7 +744,7 @@ within the "form" by name for validation.
     [% draw_field_label('aua', 'within_city_limits') %]
     [% draw_form_input('aua', 'within_city_limits', 'addresses[$index]', 'checkbox') %]
     <div class="col-md-6 patron-reg-example">
-      [% draw_example_text('au', 'within_city_limits') %]
+      [% draw_example_text('aua', 'within_city_limits') %]
     </div>
   </div>
 
index 5bbe3f4..bd56ecf 100644 (file)
@@ -160,6 +160,11 @@ angular.module('egCoreMod')
         .then(function(p) { return p.indexOf(org_id) > -1; });
     }
 
+    service.has_user_edit_perms = function(org_id) {
+        return egCore.perm.hasPermAt('CREATE_USER', true)
+        .then(function(p) { return p.indexOf(org_id) > -1; });
+    }
+
     service.get_surveys = function() {
         var org_ids = egCore.org.fullPath(egCore.auth.user().ws_ou(), true);
 
@@ -580,7 +585,7 @@ angular.module('egCoreMod')
             _is_mailing : true,
             _is_billing : true,
             within_city_limits : false,
-            stat_cat_entries : []
+            country : service.org_settings['ui.patron.default_country'],
         };
 
         var card = {
@@ -596,6 +601,7 @@ angular.module('egCoreMod')
             card : card,
             cards : [card],
             home_ou : egCore.org.get(egCore.auth.user().ws_ou()),
+            stat_cat_entries : [],
             addresses : [addr]
         };
 
@@ -1245,6 +1251,7 @@ function PatronRegCtrl($scope, $routeParams,
         addr.isnew = true;
         addr.valid = true;
         addr.within_city_limits = true;
+        addr.country($scope.org_settings['ui.patron.default_country']);
         $scope.patron.addresses.push(addr);
     }
 
@@ -1461,6 +1468,7 @@ function PatronRegCtrl($scope, $routeParams,
         patronRegSvc.invalidate_field($scope.patron, field);
     }
 
+
     $scope.dupe_value_changed = function(type, value) {
         $scope.dupe_counts[type] = 0;
         patronRegSvc.dupe_patron_search($scope.patron, type, value)
@@ -1478,8 +1486,12 @@ function PatronRegCtrl($scope, $routeParams,
     // TODO: check edit perms
     $scope.handle_home_org_changed = function() {
         org_id = $scope.patron.home_ou.id();
+
         patronRegSvc.has_group_link_perms(org_id)
         .then(function(bool) {$scope.has_group_link_perm = bool});
+
+        patronRegSvc.has_user_edit_perms(org_id)
+        .then(function(bool) {$scope.has_user_edit_perm = bool});
     }
 
     // This is called with every character typed in a form field,
@@ -1552,7 +1564,7 @@ function PatronRegCtrl($scope, $routeParams,
                 break;
 
             case 'dob':
-                // TODO: very date is valid; update juvenile.
+                maintain_juvenile_flag();
                 break;
         }
 
@@ -1561,6 +1573,33 @@ function PatronRegCtrl($scope, $routeParams,
         $scope.field_modified();
     }
 
+    // patron.juvenile is set to true if the user was born after
+    function maintain_juvenile_flag() {
+        if ( !($scope.patron && $scope.patron.dob) ) return;
+
+        var juv_interval = 
+            $scope.org_settings['global.juvenile_age_threshold'] 
+            || '18 years';
+
+        var base = new Date();
+
+        base.setTime(base.getTime() - 
+            Number(egCore.date.intervalToSeconds(juv_interval) + '000'));
+
+        $scope.patron.juvenile = ($scope.patron.dob > base);
+    }
+
+    // returns true (disable) for orgs that cannot have users.
+    $scope.disable_home_org = function(org_id) {
+        if (!org_id) return;
+        var org = egCore.org.get(org_id);
+        return (
+            org &&
+            org.ou_type() &&
+            org.ou_type().can_have_users() == 'f'
+        );
+    }
+
     /* NOTE: this function is not necessary since angular applies
      * the needed classes as each field becomes valid/invalid.
      * Leaving it here for now for reference.
@@ -1582,6 +1621,13 @@ function PatronRegCtrl($scope, $routeParams,
         return $('#patron-reg-container.ng-invalid').length > 0;
     }
 
+    $scope.edit_passthru.hide_save_actions = function() {
+        return (
+            !$scope.has_user_edit_perm ||
+            $scope.edit_passthru.has_invalid_fields()
+        );
+    }
+
     $scope.edit_passthru.save = function(save_args) {
         if (!save_args) save_args = {};