From 11c53c945ad49b67643bf39217c0091c32097ffe Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Sun, 6 Mar 2016 17:50:30 -0500 Subject: [PATCH] LP#1550036 Linked patrons for new users Support adding auzillary (linked) groups for new patrons in the browser client editor. Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- .../js/ui/default/staff/circ/patron/regctl.js | 53 +++++++++++++++---- 1 file changed, 42 insertions(+), 11 deletions(-) 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 1749f32f69..ae7838ed50 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 @@ -67,6 +67,21 @@ angular.module('egCoreMod') }); } + service.apply_secondary_groups = function(user_id, group_ids) { + return egCore.net.request( + 'open-ils.actor', + 'open-ils.actor.user.set_groups', + egCore.auth.token(), user_id, group_ids) + .then(function(resp) { + if (resp == 1) { + return true; + } else { + // debugging -- should be no events + alert('linked groups failure ' + egCore.evt.parse(resp)); + } + }); + } + service.get_stage_user = function() { if (!service.stage_username) return $q.when(); @@ -619,6 +634,7 @@ angular.module('egCoreMod') cards : [card], home_ou : egCore.org.get(egCore.auth.user().ws_ou()), stat_cat_entries : [], + groups : [], addresses : [addr] }; @@ -1463,19 +1479,20 @@ function PatronRegCtrl($scope, $routeParams, } }).result.then( function(args) { + + if ($scope.patron.isnew) { + // groups must be linked for new patrons after the + // patron is created. + $scope.patron.groups = args.linked_groups; + return; + } + + // update links groups for existing users in real time. var ids = args.linked_groups.map(function(g) {return g.id()}); - console.log('linking permission groups ' + ids); - return egCore.net.request( - 'open-ils.actor', - 'open-ils.actor.user.set_groups', - egCore.auth.token(), $scope.patron.id, ids) - .then(function(resp) { - if (resp == 1) { + patronRegSvc.apply_secondary_groups($scope.patron.id, ids) + .then(function(success) { + if (success) $scope.patron.groups = args.linked_groups; - } else { - // debugging -- should be no events - alert('linked groups failure ' + egCore.evt.parse(resp)); - } }); } ); @@ -1666,6 +1683,20 @@ function PatronRegCtrl($scope, $routeParams, if (updated_user) return patronRegSvc.remove_staged_user(); + return $q.when(); + + }).then(function() { + + // linked groups for new users must be created after the new + // user is created. + if ($scope.patron.isnew && + $scope.patron.groups && $scope.patron.groups.length) { + var ids = $scope.patron.groups.map(function(g) {return g.id()}); + return patronRegSvc.apply_secondary_groups(updated_user.id(), ids) + } + + return $q.when(); + }).then(function() { // reloading the page means potentially losing some information -- 2.43.2