From df82edde99bf84f46d6e79be6ba6f19271c5a631 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 25 Oct 2016 17:23:13 -0400 Subject: [PATCH] webstaff: implement patron merge interface This patch adds a 'Merge Patrons' button to the patron search grid. If the user selects two patron records, the button can be clicked to present a dialog that allows the user to pick a lead record and confirm a merge of the patrons. This patch also adds an egPatronSummary directive that uses the existing patron summary template with a couple modifications. Signed-off-by: Galen Charlton Signed-off-by: Kathy Lussier --- Open-ILS/src/templates/staff/circ/patron/index.tt2 | 1 + .../staff/circ/patron/t_search_results.tt2 | 5 ++ .../src/templates/staff/circ/patron/t_summary.tt2 | 13 ++++ .../web/js/ui/default/staff/circ/patron/app.js | 25 +++++- .../js/ui/default/staff/circ/services/patrons.js | 89 ++++++++++++++++++++++ 5 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/web/js/ui/default/staff/circ/services/patrons.js diff --git a/Open-ILS/src/templates/staff/circ/patron/index.tt2 b/Open-ILS/src/templates/staff/circ/patron/index.tt2 index 810950dfe8..ebde904e53 100644 --- a/Open-ILS/src/templates/staff/circ/patron/index.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/index.tt2 @@ -11,6 +11,7 @@ + [% INCLUDE 'staff/circ/share/circ_strings.tt2' %] diff --git a/Open-ILS/src/templates/staff/circ/patron/t_search_results.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_search_results.tt2 index f7378f72bb..a5a58af774 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_search_results.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_search_results.tt2 @@ -20,6 +20,11 @@ grid-controls="gridControls" items-provider="patronSearchGridProvider" persist-key="circ.patron.search"> + + + diff --git a/Open-ILS/src/templates/staff/circ/patron/t_summary.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_summary.tt2 index 83a5957e81..606687dd61 100644 --- a/Open-ILS/src/templates/staff/circ/patron/t_summary.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/t_summary.tt2 @@ -18,6 +18,19 @@
[% l('Profile') %]
{{patron().profile().name()}}
+
+
[% l('ID') %]
+
{{patron().id()}}
+
+
+
[% l('Name') %]
+
+ [% l('[_1], [_2] [_3]', + '{{patron().family_name()}}', + '{{patron().first_given_name()}}', + '{{patron().second_given_name()}}') %] +
+
[% l('Home Library') %]
{{patron().home_ou().shortname()}}
diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js index 31b23582b2..bb514c4f00 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js @@ -789,8 +789,10 @@ function($scope , $location , egCore , egConfirmDialog , egUser , patronSvc) { .controller('PatronSearchCtrl', ['$scope','$q','$routeParams','$timeout','$window','$location','egCore', '$filter','egUser', 'patronSvc','egGridDataProvider','$document', + 'egPatronMerge', function($scope, $q, $routeParams, $timeout, $window, $location, egCore, - $filter, egUser, patronSvc , egGridDataProvider , $document) { + $filter, egUser, patronSvc , egGridDataProvider , $document, + egPatronMerge) { $scope.initTab('search'); $scope.focusMe = true; @@ -1080,6 +1082,27 @@ function($scope, $q, $routeParams, $timeout, $window, $location, egCore, // force the grid to load the url-based search on page load provider.refresh(); } + + $scope.need_two_selected = function() { + var items = $scope.gridControls.selectedItems(); + return (items.length == 2) ? false : true; + } + $scope.merge_patrons = function() { + var items = $scope.gridControls.selectedItems(); + if (items.length != 2) return false; + + var patron_ids = []; + angular.forEach(items, function(i) { + patron_ids.push(i.id()); + }); + egPatronMerge.do_merge(patron_ids).then(function() { + // ensure that we're not drawing from cached + // resuts, as a successful merge just deleted a + // record + delete patronSvc.lastSearch; + $scope.gridControls.refresh(); + }); + } }]) diff --git a/Open-ILS/web/js/ui/default/staff/circ/services/patrons.js b/Open-ILS/web/js/ui/default/staff/circ/services/patrons.js new file mode 100644 index 0000000000..08e5548826 --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/circ/services/patrons.js @@ -0,0 +1,89 @@ +angular.module('egCoreMod') + +.factory('egPatronMerge', + ['$uibModal','$q','egCore', +function($uibModal , $q , egCore) { + + var service = {}; + + service.do_merge = function(patron_ids) { + var deferred = $q.defer(); + $uibModal.open({ + templateUrl: './circ/share/t_merge_patrons', + size: 'lg', + windowClass: 'eg-wide-modal', + controller: + ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) { + $scope.lead_id = 0; + $scope.patron_ids = patron_ids; + $scope.ok = function() { + $uibModalInstance.close({ lead_id : $scope.lead_id }); + } + $scope.cancel = function () { $uibModalInstance.dismiss() } + }] + }).result.then(function (args) { + if (args.lead_id == 0) return; + var sub_id = (args.lead_id == patron_ids[0]) ? + patron_ids[1] : + patron_ids[0]; + egCore.net.request( + 'open-ils.actor', + 'open-ils.actor.user.merge', + egCore.auth.token(), + args.lead_id, + [ sub_id ] + ).then(function(resp) { + var evt = egCore.evt.parse(resp); + if (evt) { + console.debug(evt); + deferred.reject(evt); + return; + } else { + deferred.resolve(); + } + }); + }); + return deferred.promise; + } + + return service; + +}]) + +.directive('egPatronSummary', ['egUser','patronSvc', function(egUser, patronSvc) { + return { + restrict : 'E', + transclude: true, + templateUrl : './circ/patron/t_summary', + scope : { + patronId : '=' + }, + controller : [ + '$scope','egCore', + function($scope , egCore) { + var user; + var user_stats; + egUser.get($scope.patronId).then(function(u) { + user = u; + patronSvc.localFlesh(user); + }); + patronSvc.getUserStats($scope.patronId).then(function(s) { + user_stats = s; + }); + $scope.patron = function() { + return user; + } + $scope.patron_stats = function() { + return user_stats; + } + + // needed because this directive shares a template with + // the patron summary in circ app, but the circ app + // displays the patron name elsewhere. + $scope.show_name = function() { + return true; + } + } + ] + } +}]); -- 2.11.0