LP#1452950 add/delete patron address
authorBill Erickson <berickxx@gmail.com>
Mon, 31 Aug 2015 01:10:23 +0000 (21:10 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 25 Feb 2016 22:31:55 +0000 (17:31 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/templates/staff/circ/patron/t_edit.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index 9912d59..4bf4792 100644 (file)
   </div>
 </div>
 
-<div class="alert alert-success row" role="alert">
-    <div class="col-md-3">[% l('Address') %]</div>
-    <div class="col-md-3">
-        <span class='pad-all-min'>
-          [% l('Mailing') %] <input type='checkbox'/>
-        </span>
-        <span class='pad-all-min'>
-          [% l('Physical') %] <input type='checkbox'/>
-        </span>
-        <span class='pad-all-min'>
-          <button type="button" class="btn btn-danger">[% l('X') %]</button>
-        </span>
-    </div>
-</div>
 
 <!-- addresses -->
 
-[% formfield('aua', 'address_type', 'mailing_address') %]
-[% formfield('aua', 'post_code', 'mailing_address') %]
-[% formfield('aua', 'street1', 'mailing_address') %]
-[% formfield('aua', 'street2', 'mailing_address') %]
-[% formfield('aua', 'city', 'mailing_address') %]
-[% formfield('aua', 'county', 'mailing_address') %]
-[% formfield('aua', 'state', 'mailing_address') %]
-[% formfield('aua', 'country', 'mailing_address') %]
-[% formfield('aua', 'valid', 'mailing_address', 'checkbox') %]
-[% formfield('aua', 'within_city_limits', 'mailing_address', 'checkbox') %]
-
-<div class="row">
-  <button type="button" class="btn btn-success">[% l('New Address') %]</button>
-</div>
 
-<!-- pending address -->
+<div ng-repeat="addr in patron.addresses">
+  <div class="alert alert-success row" role="alert">
+      <div class="col-md-3">[% l('Address') %]</div>
+      <div class="col-md-3">
+          <span class='pad-all-min'>
+            [% l('Mailing') %] <input type='checkbox' ng-model="addr._is_mailing"/>
+          </span>
+          <span class='pad-all-min'>
+            [% l('Physical') %] <input type='checkbox' ng-model="addr._is_billing"/>
+          </span>
+          <span class='pad-all-min'>
+            <button type="button" ng-click="delete_address(addr.id)" 
+              class="btn btn-danger">[% l('X') %]</button>
+          </span>
+      </div>
+  </div>
+
+  [% formfield('aua', 'address_type', 'addresses[$index]') %]
+  [% formfield('aua', 'post_code', 'addresses[$index]') %]
+  [% formfield('aua', 'street1', 'addresses[$index]') %]
+  [% formfield('aua', 'street2', 'addresses[$index]') %]
+  [% formfield('aua', 'city', 'addresses[$index]') %]
+  [% formfield('aua', 'county', 'addresses[$index]') %]
+  [% formfield('aua', 'state', 'addresses[$index]') %]
+  [% formfield('aua', 'country', 'addresses[$index]') %]
+  [% formfield('aua', 'valid', 'addresses[$index]', 'checkbox') %]
+  [% formfield('aua', 'within_city_limits', 'addresses[$index]', 'checkbox') %]
+
+  <div class="row" ng-if="$last">
+    <button type="button" ng-click="new_address()" 
+      class="btn btn-success">[% l('New Address') %]</button>
+  </div>
+
+  <!-- pending address -->
+
+</div> <!-- addresses -->
 
 <div class="alert alert-success row" role="alert" 
     ng-show="show_field('stat_cats')" ng-if="stat_cats.length > 0">
index 3a46e61..b676963 100644 (file)
@@ -265,6 +265,15 @@ angular.module('egCoreMod')
         return service.init_existing_patron(current)
     }
 
+    service.ingest_address = function(patron, addr) {
+        addr.valid = addr.valid == 't';
+        addr.within_city_limits = addr.within_city_limits == 't';
+        addr._is_mailing = (patron.mailing_address && 
+            addr.id == patron.mailing_address.id);
+        addr._is_billing = (patron.billing_address && 
+            addr.id == patron.billing_address.id);
+    }
+
     /*
      * Existing patron objects reqire some data munging before insertion
      * into the scope.
@@ -289,10 +298,8 @@ angular.module('egCoreMod')
             function(field) { patron[field] = patron[field] == 't'; }
         );
 
-        angular.forEach(patron.addresses, function(addr) {
-            addr.valid = addr.valid == 't';
-            addr.within_city_limits = addr.within_city_limits == 't';
-        });
+        angular.forEach(patron.addresses, 
+            function(addr) { service.ingest_address(patron, addr) });
 
         return patron;
     }
@@ -457,6 +464,35 @@ function PatronRegCtrl($scope, $routeParams,
         $scope.patron.profile = grp;
         $scope.set_expire_date();
     }
+
+    var new_addr_id = -1;
+    $scope.new_address = function() {
+        var addr = egCore.idl.toHash(new egCore.idl.aua());
+        patronRegSvc.ingest_address($scope.patron, addr);
+        addr.id = new_addr_id--;
+        addr.valid = true;
+        addr.within_city_limits = true;
+        $scope.patron.addresses.push(addr);
+    }
+
+    // keep deleted addresses out of the patron object so
+    // they won't appear in the UI.  They'll be re-inserted
+    // when the patron is updated.
+    deleted_addresses = [];
+    $scope.delete_address = function(id) {
+        var addresses = [];
+        angular.forEach($scope.patron.addresses, function(addr) {
+            if (addr.id == id) {
+                if (id > 0) {
+                    addr.isdeleted = true;
+                    deleted_addresses.push(addr);
+                }
+            } else {
+                addresses.push(addr);
+            }
+        });
+        $scope.patron.addresses = addresses;
+    }
 }