</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">
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.
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;
}
$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;
+ }
}