From: Bill Erickson Date: Mon, 29 Feb 2016 23:51:55 +0000 (-0500) Subject: Patron reg field validation (WIP) X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=47c891084d038d2f5570a58d64d09fb073c683ff;p=working%2FEvergreen.git Patron reg field validation (WIP) Signed-off-by: Bill Erickson --- 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 5a0aa9d22b..84e3ab5fca 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 @@ -83,6 +83,37 @@ [% 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; +%] +
+ +
+[% END %] + +[% MACRO draw_example_text(cls, field) BLOCK; + set_str = "org_settings['ui.patron.edit." _ cls _ "." _ field _ ".example']"; +%] + + [% l('Example: [_1]', '{{' _ set_str _ '}}') %] + +[% END %] +
@@ -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. [% draw_field_label('au', 'passwd') %] -
- -
+ [% draw_form_input('au', 'passwd'); %]
@@ -177,21 +198,9 @@ within the "form" by name for validation.
[% draw_field_label('au', 'prefix') %] -
- -
+ [% draw_form_input('au', 'prefix'); %]
- - [% l('Example: [_1]', "{{org_settings['ui.patron.edit.au.prefix.example']}}") %] - + [% draw_example_text('au', 'prefix') %]
@@ -199,19 +208,9 @@ within the "form" by name for validation.
[% draw_field_label('au', 'first_given_name') %] -
- -
+ [% draw_form_input('au', 'first_given_name'); %]
- - [% l('Example: [_1]', "{{org_settings['ui.patron.edit.au.first_given_name.example']}}") %] - + [% draw_example_text('au', 'first_given_name') %]
@@ -219,19 +218,9 @@ within the "form" by name for validation.
[% draw_field_label('au', 'second_given_name') %] -
- -
+ [% draw_form_input('au', 'second_given_name'); %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.second_given_name.example']}}") %] - + [% draw_example_text('au', 'second_given_name') %]
@@ -239,20 +228,9 @@ within the "form" by name for validation.
[% draw_field_label('au', 'family_name') %] -
- -
+ [% draw_form_input('au', 'family_name'); %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.family_name.example']}}") %] - + [% draw_example_text('au', 'family_name') %]
@@ -260,21 +238,9 @@ within the "form" by name for validation.
[% draw_field_label('au', 'suffix') %] -
- -
+ [% draw_form_input('au', 'suffix'); %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.suffix.example']}}") %] - + [% draw_example_text('au', 'suffix') %]
@@ -282,21 +248,9 @@ within the "form" by name for validation.
[% draw_field_label('au', 'alias') %] -
- -
+ [% draw_form_input('au', 'alias'); %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.alias.example']}}") %] - + [% draw_example_text('au', 'alias') %]
@@ -313,10 +267,7 @@ within the "form" by name for validation. class="form-control" ng-model="patron.dob"/>
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.dob.example']}}") %] - + [% draw_example_text('au', 'dob') %]
@@ -324,15 +275,7 @@ within the "form" by name for validation.
[% draw_field_label('au', 'juvenile') %] -
- -
+ [% draw_form_input('au', 'alias', '', 'checkbox'); %]
@@ -362,58 +305,26 @@ within the "form" by name for validation.
[% draw_field_label('au', 'ident_value') %] -
- -
+ [% draw_form_input('au', 'ident_value') %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.ident_value.example']}}") %] - + [% draw_example_text('au', 'ident_value') %]
[% draw_field_label('au', 'ident_value2') %] -
- -
+ [% draw_form_input('au', 'ident_value2') %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.ident_value2.example']}}") %] - + [% draw_example_text('au', 'ident_value2') %]
- [% draw_field_label('au', 'ident_value2') %] -
- -
+ [% draw_field_label('au', 'email') %] + [% draw_form_input('au', 'email', '', 'email') %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.day_phone.example']}}") %] - + [% draw_example_text('au', 'day_phone') %] [% l('Example: [_1]', @@ -458,23 +358,12 @@ within the "form" by name for validation.
[% draw_field_label('au', 'evening_phone') %] -
- -
+ [% draw_form_input('au', 'evening_phone') %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.evening_phone.example']}}") %] - + [% draw_example_text('au', 'evening_phone') %] [% l('Example: [_1]', @@ -487,23 +376,12 @@ within the "form" by name for validation.
[% draw_field_label('au', 'other_phone') %] -
- -
+ [% draw_form_input('au', 'other_phone') %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.other_phone.example']}}") %] - + [% draw_example_text('au', 'other_phone') %] [% l('Example: [_1]', @@ -590,56 +468,30 @@ within the "form" by name for validation.
[% draw_field_label('au', 'active') %] -
-
- -
-
+ [% draw_form_input('au', 'active', '', 'checkbox') %]
[% draw_field_label('au', 'barred') %] -
-
- -
-
+ [% draw_form_input('au', 'barred', '', 'checkbox') %]
[% draw_field_label('au', 'master_account') %] -
-
- -
-
+ [% draw_form_input('au', 'master_account', '', 'checkbox') %]
[% draw_field_label('au', 'claims_returned_count') %] -
- -
+ [% draw_form_input('au', 'claims_returned_count', '', 'number') %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.claims_returned_count.example']}}") %] - + [% draw_example_text('au', 'claims_returned_count') %]
@@ -647,17 +499,9 @@ within the "form" by name for validation.
[% draw_field_label('au', 'claims_never_checked_out_count') %] -
- -
+ [% draw_form_input('au', 'claims_never_checked_out_count', '', 'number') %]
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.claims_never_checked_out_count.example']}}") %] - + [% draw_example_text('au', 'claims_never_checked_out_count') %]
@@ -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')"> +
- - [% l('Example: [_1]', - "{{org_settings['ui.patron.edit.au.alert_message.example']}}") %] - + [% draw_example_text('au', 'alert_message') %]
@@ -825,18 +667,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'address_type') %] -
- -
+ [% draw_form_input('aua', 'address_type', 'addresses[$index]') %]
- - Example: {{org_settings['ui.patron.edit.aua.address_type.example']}} - + [% draw_example_text('au', 'address_type') %]
@@ -844,18 +677,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'post_code') %] -
- -
+ [% draw_form_input('aua', 'post_code', 'addresses[$index]') %]
- - Example: {{org_settings['ui.patron.edit.aua.post_code.example']}} - + [% draw_example_text('au', 'post_code') %]
@@ -863,18 +687,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'street1') %] -
- -
+ [% draw_form_input('aua', 'street1', 'addresses[$index]') %]
- - Example: {{org_settings['ui.patron.edit.aua.street1.example']}} - + [% draw_example_text('au', 'street1') %]
@@ -882,18 +697,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'street2') %] -
- -
+ [% draw_form_input('aua', 'street2', 'addresses[$index]') %]
- - Example: {{org_settings['ui.patron.edit.aua.street2.example']}} - + [% draw_example_text('au', 'street2') %]
@@ -901,18 +707,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'city') %] -
- -
+ [% draw_form_input('aua', 'city', 'addresses[$index]') %]
- - Example: {{org_settings['ui.patron.edit.aua.city.example']}} - + [% draw_example_text('au', 'city') %]
@@ -920,18 +717,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'county') %] -
- -
+ [% draw_form_input('aua', 'county', 'addresses[$index]') %]
- - Example: {{org_settings['ui.patron.edit.aua.county.example']}} - + [% draw_example_text('au', 'county') %]
@@ -939,18 +727,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'state') %] -
- -
+ [% draw_form_input('aua', 'state', 'addresses[$index]') %]
- - Example: {{org_settings['ui.patron.edit.aua.state.example']}} - + [% draw_example_text('au', 'state') %]
@@ -958,18 +737,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'country') %] -
- -
+ [% draw_form_input('aua', 'country', 'addresses[$index]') %]
- - Example: {{org_settings['ui.patron.edit.aua.country.example']}} - + [% draw_example_text('au', 'country') %]
@@ -977,16 +747,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'valid') %] -
- -
+ [% draw_form_input('aua', 'valid', 'addresses[$index]', 'checkbox') %]
- - Example: {{org_settings['ui.patron.edit.aua.valid.example']}} - + [% draw_example_text('au', 'valid') %]
@@ -994,16 +757,9 @@ within the "form" by name for validation.
[% draw_field_label('aua', 'within_city_limits') %] -
- -
+ [% draw_form_input('aua', 'within_city_limits', 'addresses[$index]', 'checkbox') %]
- - Example: {{org_settings['ui.patron.edit.aua.within_city_limits.example']}} - + [% draw_example_text('au', '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 79bd6736ef..02e7575572 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 @@ -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;