LP#626157 Ang2 experiments
authorBill Erickson <berickxx@gmail.com>
Fri, 1 Dec 2017 01:41:45 +0000 (20:41 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 11 Dec 2017 17:39:51 +0000 (12:39 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.html
Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.ts
Open-ILS/webby-src/src/app/staff/share/org-select.component.ts

index cc6fc30..c5ec3fd 100644 (file)
@@ -16,6 +16,7 @@
           [onChange]="orgOnChange"
           [shouldHide]="shouldHideOrg"
           [shouldDisable]="shouldDisableOrg"
+          [initialOrg]="initialOrg"
           [placeholder]="'Owner'" >
         </eg-org-select>
       </div>
index 7467124..861d388 100644 (file)
@@ -24,6 +24,8 @@ export class EgWorkstationsComponent implements OnInit {
     newOwner: EgIdlObject;
     newName: String;
 
+    //initialOrg: EgIdlObject; // XXX testing
+
     // Org selector callbacks
     shouldDisableOrg = (org: EgIdlObject): boolean => {
         // TODO: check register perms too
@@ -49,6 +51,8 @@ export class EgWorkstationsComponent implements OnInit {
     ngOnInit() {
         this.store.getItem('eg.workstation.all')
         .then(res => this.workstations = res);
+
+        // this.initialOrg = this.org.root().children()[0];
     }
 
     selected(): Workstation {
index d5a361a..d16d7b0 100644 (file)
@@ -26,13 +26,13 @@ export class EgOrgSelectComponent implements OnInit {
     selected: OrgDisplay;
 
     // Read-only properties optionally provided by the calling component.
-    @Input() placeholder: String;
+    @Input() placeholder: string;
     @Input() initialOrg: EgIdlObject;
-    @Input() stickySetting: String;
-    @Input() displayField: String = 'shortname';
+    @Input() stickySetting: string;
+    @Input() displayField: string = 'shortname';
 
     // Call-backs
-    // Note onChange could be handled via an EventEmitter, but
+    // Note: onChange could be handled via an EventEmitter, but
     // should* functions require real time two-way communication.
     @Input() onChange: (org:EgIdlObject) => void;
     @Input() shouldDisable: (org:EgIdlObject) => boolean;
@@ -45,6 +45,18 @@ export class EgOrgSelectComponent implements OnInit {
     ) {}
     
     ngOnInit() {
+        if (this.initialOrg) {
+            this.selected = this.formatForDisplay(this.initialOrg);
+        }
+    }
+
+    formatForDisplay(org: EgIdlObject): OrgDisplay {
+        return {
+            id : org.id(),
+            label : PAD_SPACE.repeat(org.ou_type().depth()) 
+              + org[this.displayField](),
+            disabled : false
+        };
     }
 
     orgChanged(selEvent: NgbTypeaheadSelectItemEvent) {
@@ -62,25 +74,17 @@ export class EgOrgSelectComponent implements OnInit {
             .distinctUntilChanged()
             .map(term => {
 
-                // TODO: displayField / shortname
                 return this.org.list().filter(org => {
 
                     // Find orgs matching the search term
-                    return org.shortname()
+                    return org[this.displayField]()
                       .toLowerCase().indexOf(term.toLowerCase()) > -1
 
                 }).filter(org => {
                     // Exclude hidden orgs
                     return !this.shouldHide || !this.shouldHide(org)
 
-                }).map(org => {
-                    
-                    return {
-                        id : org.id(),
-                        label : PAD_SPACE.repeat(org.ou_type().depth()) + org.shortname(),
-                        disabled : this.shouldDisable && this.shouldDisable(org)
-                    }
-                })
+                }).map(org => { return this.formatForDisplay(org) })
             });
     }
 }