LP#1724083 Webstaff approve pending patron address
authorBill Erickson <berickxx@gmail.com>
Mon, 30 Jul 2018 21:23:49 +0000 (17:23 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 11 Sep 2018 17:40:49 +0000 (13:40 -0400)
Add support for approving pending patron addresses in the webstaff
patron edit interface.

To test:
[1] Enable the pending address org unit setting.
[2] Log into the catalog and "edit" an address.
[3] Edit same user in staff client and use the Approve action.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Garry Collum <gcollum@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/circ/patron/t_edit.tt2
Open-ILS/src/templates/staff/css/circ.css.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index 87a1522..3a502a7 100644 (file)
@@ -825,6 +825,35 @@ within the "form" by name for validation.
       </div>
   </div>
 
+  <div ng-if="addr.pending" class="row">
+    <div class="col-md-6 patron-reg-pending-address">
+      <div class="row">
+        <div class="col-md-6">
+          [% l('This is a pending address') %]
+        </div>
+        <div class="col-md-6">
+          <button class="btn btn-success" 
+            ng-click="approve_pending_address(addr)">[% l('Approve') %]</button>
+        </div>
+      </div>
+      <div class="row" ng-if="addr._replaces">
+        <div class="col-md-6">
+          [% | l(
+            '{{addr._replaces.street1}}',
+            '{{addr._replaces.street2}}',
+            '<br/>'
+            '{{addr._replaces.city}}',
+            '{{addr._replaces.state}}',
+            '{{addr._replaces.post_code}}') %]
+            Replaces: [_1] [_2] [_3] [_4], [_5] [_6]
+          [% END %]
+        </div>
+      </div>
+    </div>
+    <!-- make sure we occupy the entire row -->
+    <div class="col-md-6"> </div>
+  </div>
+
   <!-- ADDRESS_TYPE -->
   <div class="row reg-field-row" ng-show="show_field('aua.address_type')">
     [% draw_field_label('aua', 'address_type') %]
index cbbf509..798117e 100644 (file)
@@ -189,6 +189,13 @@ but the ones I'm finding aren't quite cutting it..*/
   background-color: rgb(215, 215, 215);
 }
 
+.patron-reg-pending-address {
+  border:2px dashed #d9e8f9;
+  -moz-border-radius: 10px;
+  padding: 10px;
+  margin-bottom: 5px;
+}
+
 /* -- end patron registration -- */
 
 [%# 
index 30f2a63..7599020 100644 (file)
@@ -720,6 +720,7 @@ angular.module('egCoreMod')
             addr.id == patron.mailing_address.id);
         addr._is_billing = (patron.billing_address && 
             addr.id == patron.billing_address.id);
+        addr.pending = addr.pending === 't';
     }
 
     /*
@@ -761,6 +762,14 @@ angular.module('egCoreMod')
         angular.forEach(patron.addresses, 
             function(addr) { service.ingest_address(patron, addr) });
 
+        // Link replaced address to its pending address.
+        angular.forEach(patron.addresses, function(addr) {
+            if (addr.replaces) {
+                addr._replaces = patron.addresses.filter(
+                    function(a) {return a.id == addr.replaces})[0];
+            }
+        });
+
         service.get_linked_addr_users(patron.addresses);
 
         // Remove stat cat entries that link to out-of-scope stat
@@ -1071,6 +1080,7 @@ angular.module('egCoreMod')
             patron.addresses().push(addr);
             addr.valid(addr.valid() ? 't' : 'f');
             addr.within_city_limits(addr.within_city_limits() ? 't' : 'f');
+            addr.pending(addr.pending() ? 't' : 'f');
             if (addr_hash._is_mailing) patron.mailing_address(addr);
             if (addr_hash._is_billing) patron.billing_address(addr);
         });
@@ -1563,6 +1573,37 @@ function($scope , $routeParams , $q , $uibModal , $window , egCore ,
         $scope.patron.addresses = addresses;
     } 
 
+    $scope.approve_pending_address = function(addr) {
+
+        egCore.net.request(
+            'open-ils.actor',
+            'open-ils.actor.user.pending_address.approve',
+            egCore.auth.token(), addr.id
+        ).then(function(replaced_id) {
+            var evt = egCore.evt.parse(replaced_id);
+            if (evt) { alert(evt); return; }
+
+            // Remove the pending address and the replaced address
+            // from the local list of patron addresses.
+            var addresses = [];
+            angular.forEach($scope.patron.addresses, function(a) {
+                if (a.id != addr.id && a.id != replaced_id) {
+                    addresses.push(a);
+                }
+            });
+            $scope.patron.addresses = addresses;
+
+            // Fetch a fresh copy of the modified address from the server.
+            // and add it back to the list.
+            egCore.pcrud.retrieve('aua', replaced_id, {}, {authoritative: true})
+            .then(null, null, function(new_addr) {
+                new_addr = egCore.idl.toHash(new_addr);
+                patronRegSvc.ingest_address($scope.patron, new_addr);
+                $scope.patron.addresses.push(new_addr);
+            });
+        });
+    }
+
     $scope.post_code_changed = function(addr) { 
         egCore.net.request(
             'open-ils.search', 'open-ils.search.zip', addr.post_code)