From: Bill Erickson Date: Fri, 16 Aug 2019 19:44:54 +0000 (-0400) Subject: LP1840050 org unit admin UI WIP X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d39f39700f7134fda10d4aa22fa2bf720455b217;p=working%2FEvergreen.git LP1840050 org unit admin UI WIP Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.html index 0545025c6e..b3a787b5f4 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.html @@ -1,9 +1,9 @@ - + type = {{type}} - + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts index 1bc28634cd..3b4a498bc6 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-addr.component.ts @@ -2,6 +2,7 @@ import {Component, Input, Output, EventEmitter} from '@angular/core'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {OrgService} from '@eg/core/org.service'; import {PcrudService} from '@eg/core/pcrud.service'; +import {NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap'; const ADDR_TYPES = ['billing_address', 'holds_address', 'mailing_address', 'ill_address']; @@ -13,6 +14,7 @@ const ADDR_TYPES = export class OrgAddressComponent { private orgUnit: IdlObject = null; + private tabName: string; private _orgId: number; @@ -37,6 +39,7 @@ export class OrgAddressComponent { private pcrud: PcrudService ) { this.addrChange = new EventEmitter(); + this.tabName = 'billing_address'; } init() { @@ -55,6 +58,10 @@ export class OrgAddressComponent { }); } + tabChanged($event: NgbTabChangeEvent) { + this.tabName = $event.nextId; + } + addrTypes(): string[] { // for UI return ADDR_TYPES; } @@ -68,7 +75,7 @@ export class OrgAddressComponent { const addr = this.idl.create('aoa'); addr.isnew(true); addr.valid('t'); - addr.org_unit(this.orgUnit); + addr.org_unit(this.orgId); this.orgUnit[addrType](addr); } @@ -99,15 +106,58 @@ export class OrgAddressComponent { }).length > 1; } + deleteAddress($event: any) { + const addr = $event.record; + const tmpOrg = this.updatableOrg(); + + // Set the FKey to NULL on the org unit for deleted addresses + ADDR_TYPES.forEach(aType => { + const a = this.addr(aType); + if (a && a.id() === addr.id()) { + tmpOrg[aType](null); + this.createAddress(aType); + } + }); + + this.pcrud.update(tmpOrg).toPromise() + .then(_ => this.pcrud.remove(addr).toPromise()) + .then(_ => this.addrChange.emit(addr)); + } + + // Addr saved by fm-editor. + // In the case of new address creation, point the org unit at + // the new address ID. addrSaved(addr: number | IdlObject) { - const id = typeof addr === 'object' ? addr.id() : addr; - // TODO: update org if needed... + if (typeof addr !== 'object') { + // pcrud returns a number on 'update' calls. No need to + // reload the data on a simple address change. it's changed + // in place. + return; + } + + // update local copy with version that has an ID. + this.orgUnit[this.tabName](addr); + + const org = this.updatableOrg(); + org[this.tabName](addr.id()); + + // Creating a new address -- tell our org about it. + this.pcrud.update(org).toPromise().then(_ => this.addrChange.emit(addr)); } - addrDeleted(addr: number | IdlObject) { - const id = typeof addr === 'object' ? addr.id() : addr; - // TODO: update org + // Create an unfleshed org unit object that's a clone of this.orgUnit + // to use when pushing updates to the server. + updatableOrg(): IdlObject { + const org = this.idl.clone(this.orgUnit); + + ADDR_TYPES.forEach(aType => { + const addr = this.addr(aType); + if (addr) { org[aType](addr.id()); } + }); + + return org; } + } diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html index ef8d360ab1..294d62c2bf 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html @@ -52,6 +52,7 @@ hiddenFields="id,billing_address,mailing_address,holds_address,ill_address"> @@ -91,6 +92,15 @@
+
+ Hours of Operation Have Not Yet Been Saved. +
+
+ +