From 05c6e5769071173e5fff8e64671c12362f07cff0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Sun, 6 Mar 2016 11:35:31 -0500 Subject: [PATCH] Patron reg field validation (WIP) Signed-off-by: Bill Erickson --- .../src/templates/staff/circ/patron/t_edit.tt2 | 28 +++++++++-- .../web/js/ui/default/staff/circ/patron/regctl.js | 57 +++++++++++++--------- 2 files changed, 59 insertions(+), 26 deletions(-) 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 5dc691a66d..acde40d4db 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_edit.tt2 @@ -87,7 +87,7 @@ [% # draws a vanilla form input field for inputs that require no # special additions. -MACRO draw_form_input(cls, field, path, type, required) BLOCK; +MACRO draw_form_input(cls, field, path, type, disable) BLOCK; IF !type; type = 'text'; END; base_obj = path ? 'patron.' _ path : 'patron'; model = base_obj _ '.' _ field; @@ -101,6 +101,7 @@ MACRO draw_form_input(cls, field, path, type, required) BLOCK; ng-required="field_required('[% cls %]', '[% field %]')" ng-blur="handle_field_changed([% base_obj %], '[% field %]')" ng-pattern="field_pattern('[% cls %]', '[% field %]')" + [% IF disable %]ng-disabled="[% disable %]"[% END %] ng-model="[% model %]"/> [% END %] @@ -416,7 +417,7 @@ within the "form" by name for validation.
-
@@ -474,7 +475,8 @@ within the "form" by name for validation.
[% draw_field_label('au', 'claims_returned_count') %] - [% draw_form_input('au', 'claims_returned_count', '', 'number') %] + [% draw_form_input('au', 'claims_returned_count', + '', 'number', '!perms.UPDATE_PATRON_CLAIM_RETURN_COUNT') %]
[% draw_example_text('au', 'claims_returned_count') %]
@@ -484,7 +486,8 @@ 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') %] + [% draw_form_input('au', 'claims_never_checked_out_count', + '', 'number', '!perms.UPDATE_PATRON_CLAIM_NEVER_CHECKED_OUT_COUNT') %]
[% draw_example_text('au', 'claims_never_checked_out_count') %]
@@ -547,6 +550,23 @@ within the "form" by name for validation.
+ +
+
+ +
+
+
+ +
+
+
+
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 bd56ecf5e3..d0baa685cc 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 @@ -155,14 +155,29 @@ angular.module('egCoreMod') ); } - service.has_group_link_perms = function(org_id) { - return egCore.perm.hasPermAt('CREATE_USER_GROUP_LINK', true) - .then(function(p) { return p.indexOf(org_id) > -1; }); - } + // resolves to a hash of perm-name => boolean value indicating + // wether the user has the permission at org_id. + service.has_perms_for_org = function(org_id) { + + var perms_needed = [ + 'UPDATE_USER', + 'CREATE_USER', + 'CREATE_USER_GROUP_LINK', + 'UPDATE_PATRON_COLLECTIONS_EXEMPT', + 'UPDATE_PATRON_CLAIM_RETURN_COUNT', + 'UPDATE_PATRON_CLAIM_NEVER_CHECKED_OUT_COUNT' + ]; + + return egCore.perm.hasPermAt(perms_needed, true) + .then(function(perm_map) { + + angular.forEach(perms_needed, function(perm) { + perm_map[perm] = + Boolean(perm_map[perm].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; }); + return perm_map; + }); } service.get_surveys = function() { @@ -995,8 +1010,6 @@ angular.module('egCoreMod') var cls = parts[1]; var name = parts[2]; patterns[cls][name] = new RegExp(val); - console.log('adding field pattern for ' + - name + ' : ' + patterns[cls][name]); }); } @@ -1019,6 +1032,10 @@ function PatronRegCtrl($scope, $routeParams, $scope.focus_bc = !Boolean($scope.patron_id); $scope.dupe_counts = {}; + // map of perm name to true/false for perms the logged in user + // has at the currently selected patron home org unit. + $scope.perms = {}; + if (!$scope.edit_passthru) { // in edit more, scope.edit_passthru is delivered to us by // the enclosing controller. In register mode, there is @@ -1483,15 +1500,11 @@ 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}); + patronRegSvc.has_perms_for_org(org_id).then(function(map) { + angular.forEach(map, function(v, k) { $scope.perms[k] = v }); + }); } // This is called with every character typed in a form field, @@ -1567,10 +1580,6 @@ function PatronRegCtrl($scope, $routeParams, maintain_juvenile_flag(); break; } - - // Not every form field has an on-change handler. - // Fire it here to cover those. - $scope.field_modified(); } // patron.juvenile is set to true if the user was born after @@ -1618,12 +1627,16 @@ function PatronRegCtrl($scope, $routeParams, // Returns true if any input elements are tagged as invalid $scope.edit_passthru.has_invalid_fields = function() { - return $('#patron-reg-container.ng-invalid').length > 0; + return $('#patron-reg-container .ng-invalid').length > 0; } $scope.edit_passthru.hide_save_actions = function() { + + var can_save = $scope.patron.isnew ? + $scope.perms.CREATE_USER : $scope.perms.UPDATE_USER; + return ( - !$scope.has_user_edit_perm || + !can_save || $scope.edit_passthru.has_invalid_fields() ); } -- 2.11.0