LP1840050 org unit admin UI WIP
authorBill Erickson <berickxx@gmail.com>
Thu, 15 Aug 2019 15:40:23 +0000 (11:40 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 15 Aug 2019 15:40:23 +0000 (11:40 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/org-unit.component.ts

index 4389217..8b600a9 100644 (file)
@@ -14,7 +14,7 @@
 </eg-confirm-dialog>
 
 <ng-template #treeNodeLabelTmpl let-org="org">
-  <span *ngIf="org" i18n>{{org.name()}} ({{org.shortname()}})</span>
+  <span *ngIf="org" i18n>{{org.name()}} -- {{org.shortname()}}</span>
 </ng-template>
 <eg-string #treeNodeLabel key='admin.server.org_unit.treenode' 
   [template]="treeNodeLabelTmpl"></eg-string>
   </div>
   <div class="col-lg-8">
     <div class="alert alert-info">
-      <div *ngIf="selected" i18n>
-        {{currentOrg().name()}} ({{currentOrg().shortname()}})
+      <div *ngIf="currentOrg()">
+        <span *ngIf="currentOrg().name()" i18n>
+          {{currentOrg().name()}} ({{currentOrg().shortname()}})
+        </span>
+        <span *ngIf="!currentOrg().name()" class="font-italic" i18n>
+          Add Name
+        </span>
       </div>
     </div>
-    <ngb-tabset #rootTabs (tabChange)="tabChanged($event)">
+    <ngb-tabset #rootTabs (tabChange)="tabChanged($event)" *ngIf="currentOrg()">
       <ngb-tab title="Main Settings" i18n-title id="main">
         <ng-template ngbTabContent>
           <div class="mt-2">
             <eg-fm-record-editor *ngIf="currentOrg()" #editDialog idlClass="aou" 
               [mode]="currentOrg().isnew() ? 'create': 'update'" [hideBanner]="true" 
               (recordSaved)="orgSaved($event)" displayMode="inline" 
+              (recordDeleted)="orgDeleted()"
               readonlyFields="parent,parent_ou" [preloadLinkedValues]="true"
               [fieldOptions]="{ou_type: {customValues: orgTypeOptions()}}"
               [record]="currentOrg().isnew() ? currentOrg() : null"
               [recordId]="currentOrg().isnew() ? null : currentOrg().id()"
+              [showDelete]="!orgHasChildren()"
               fieldOrder="parent_ou,ou_type,name,shortname,phone,email,opac_visible,fiscal_calendar"
               hiddenFields="id,billing_address,mailing_address,holds_address,ill_address">
               <eg-fm-record-editor-action label="Add Child" i18n-label 
-                [disabled]="orgChildTypes().length === 0"
+                [disabled]="orgChildTypes().length === 0 || currentOrg().isnew()"
                 (actionClick)="addChild()"></eg-fm-record-editor-action>
             </eg-fm-record-editor>
           </div>
         </ng-template>
       </ngb-tab>
-      <ngb-tab title="Hours of Operation" i18n-title id="hours">
+      <ngb-tab title="Hours of Operation" i18n-title id="hours" 
+        [disabled]="currentOrg().isnew()">
         <ng-template ngbTabContent>
           <div class="mt-2 common-form striped-even">
             <div class="row font-weight-bold mb-2">
           </div>
         </ng-template>
       </ngb-tab>
-      <ngb-tab title="Addresses" i18n-title id="addresses">
+      <ngb-tab title="Addresses" i18n-title id="addresses" 
+        [disabled]="currentOrg().isnew()">
         <ng-template ngbTabContent>
           <div class="mt-2">
             <ngb-tabset #addressTabs>
index e2ade99..6c86587 100644 (file)
@@ -42,11 +42,20 @@ export class OrgUnitComponent implements OnInit {
         // stubbing out in case we need it.
     }
 
-    orgSaved(orgId: number) {
-        if (!orgId && this.currentOrg()) {
-            orgId = this.currentOrg().id();
+    orgSaved(orgId: number | IdlObject) {
+        let id;
+
+        if (orgId) { // new org created, focus it.
+            id = typeof orgId === 'object' ? orgId.id() : orgId;
+        } else if (this.currentOrg()) {
+            id = this.currentOrg().id();
         }
-        this.loadAouTree(orgId).then(_ => this.postUpdate(this.editString));
+
+        this.loadAouTree(id).then(_ => this.postUpdate(this.editString));
+    }
+
+    orgDeleted() {
+        this.loadAouTree();
     }
 
     loadAouTree(selectNodeId?: number): Promise<any> {
@@ -57,11 +66,10 @@ export class OrgUnitComponent implements OnInit {
             ]}}, {authoritative: true}
         ).toPromise().then(tree => {
             this.ingestAouTree(tree);
-            if (selectNodeId) {
-                const node = this.tree.findNode(selectNodeId);
-                this.selected = node;
-                this.tree.selectNode(node);
-            }
+            if (!selectNodeId) { selectNodeId = this.org.root().id(); }
+            const node = this.tree.findNode(selectNodeId);
+            this.selected = node;
+            this.tree.selectNode(node);
         });
     }
 
@@ -179,6 +187,11 @@ export class OrgUnitComponent implements OnInit {
         return this.selected ? this.selected.callerData.orgUnit : null;
     }
 
+    orgHasChildren(): boolean {
+        const org = this.currentOrg();
+        return (org && org.children().length > 0);
+    }
+
     postUpdate(message: StringComponent) {
         // Modifying org unit types means refetching the org unit
         // data normally fetched on page load, since it includes
@@ -242,13 +255,14 @@ export class OrgUnitComponent implements OnInit {
 
     addChild() {
         const parentTreeNode = this.selected;
-        const parentOrg = parentTreeNode.callerData.orgUnit;
+        const parentOrg = this.currentOrg();
         const newType = this.orgChildTypes()[0];
 
         const org = this.idl.create('aou');
         org.isnew(true);
         org.parent_ou(parentOrg.id());
         org.ou_type(newType.id());
+        org.children([]);
 
         // Create a dummy, detached org node to keep the UI happy.
         this.selected = new TreeNode({