From 6284787334f67c412e339d5dba2a78a87cf7865e Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Sat, 5 Mar 2016 15:52:56 -0500 Subject: [PATCH] Patron reg field validation (WIP) Signed-off-by: Bill Erickson --- .../templates/staff/circ/patron/reg_actions.tt2 | 4 +- .../src/templates/staff/circ/patron/t_edit.tt2 | 25 ++++++----- .../web/js/ui/default/staff/circ/patron/regctl.js | 50 +++++++++++++++++++++- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/Open-ILS/src/templates/staff/circ/patron/reg_actions.tt2 b/Open-ILS/src/templates/staff/circ/patron/reg_actions.tt2 index 3640961bee..15080184ba 100644 --- a/Open-ILS/src/templates/staff/circ/patron/reg_actions.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/reg_actions.tt2 @@ -24,12 +24,12 @@
diff --git a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 index 13a974abfb..5dc691a66d 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 @@ -384,7 +384,10 @@ within the "form" by name for validation.
[% draw_field_label('au', 'home_ou') %]
- +
@@ -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]') %]
- [% draw_example_text('au', 'address_type') %] + [% draw_example_text('aua', 'address_type') %]
@@ -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]') %]
- [% draw_example_text('au', 'post_code') %] + [% draw_example_text('aua', 'post_code') %]
@@ -671,7 +674,7 @@ within the "form" by name for validation. [% draw_field_label('aua', 'street1') %] [% draw_form_input('aua', 'street1', 'addresses[$index]') %]
- [% draw_example_text('au', 'street1') %] + [% draw_example_text('aua', 'street1') %]
@@ -681,7 +684,7 @@ within the "form" by name for validation. [% draw_field_label('aua', 'street2') %] [% draw_form_input('aua', 'street2', 'addresses[$index]') %]
- [% draw_example_text('au', 'street2') %] + [% draw_example_text('aua', 'street2') %]
@@ -691,7 +694,7 @@ within the "form" by name for validation. [% draw_field_label('aua', 'city') %] [% draw_form_input('aua', 'city', 'addresses[$index]') %]
- [% draw_example_text('au', 'city') %] + [% draw_example_text('aua', 'city') %]
@@ -701,7 +704,7 @@ within the "form" by name for validation. [% draw_field_label('aua', 'county') %] [% draw_form_input('aua', 'county', 'addresses[$index]') %]
- [% draw_example_text('au', 'county') %] + [% draw_example_text('aua', 'county') %]
@@ -711,7 +714,7 @@ within the "form" by name for validation. [% draw_field_label('aua', 'state') %] [% draw_form_input('aua', 'state', 'addresses[$index]') %]
- [% draw_example_text('au', 'state') %] + [% draw_example_text('aua', 'state') %]
@@ -721,7 +724,7 @@ within the "form" by name for validation. [% draw_field_label('aua', 'country') %] [% draw_form_input('aua', 'country', 'addresses[$index]') %]
- [% draw_example_text('au', 'country') %] + [% draw_example_text('aua', 'country') %]
@@ -731,7 +734,7 @@ within the "form" by name for validation. [% draw_field_label('aua', 'valid') %] [% draw_form_input('aua', 'valid', 'addresses[$index]', 'checkbox') %]
- [% draw_example_text('au', 'valid') %] + [% draw_example_text('aua', 'valid') %]
@@ -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') %]
- [% draw_example_text('au', 'within_city_limits') %] + [% draw_example_text('aua', 'within_city_limits') %]
diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js b/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js index 5bbe3f44f7..bd56ecf5e3 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js @@ -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 = {}; -- 2.11.0