LP#1904244: fm-edit: teach how to format selectors when wiring up comoboxes
authorGalen Charlton <gmc@equinoxOLI.org>
Sun, 28 Mar 2021 17:38:55 +0000 (13:38 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 12 Aug 2021 19:29:26 +0000 (15:29 -0400)
Matches similar functionality in combobox.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Signed-off-by: Ruth Frasur <rfrasur@library.in.gov>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts

index 4ac2e2e..9d4ae66 100644 (file)
@@ -6,6 +6,7 @@ import {Observable} from 'rxjs';
 import {map} from 'rxjs/operators';
 import {AuthService} from '@eg/core/auth.service';
 import {PcrudService} from '@eg/core/pcrud.service';
+import {OrgService} from '@eg/core/org.service';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
 import {ToastService} from '@eg/share/toast/toast.service';
 import {StringComponent} from '@eg/share/string/string.component';
@@ -246,6 +247,7 @@ export class FmRecordEditorComponent
       private auth: AuthService,
       private toast: ToastService,
       private format: FormatService,
+      private org: OrgService,
       private pcrud: PcrudService) {
       super(modal);
     }
@@ -432,11 +434,38 @@ export class FmRecordEditorComponent
 
         return list.map(item => {
             if (item !== undefined) {
-                return {id: item[idField](), label: item[selector]()};
+                return {id: item[idField](), label: this.getFmRecordLabel(field, selector, item)};
             }
         });
     }
 
+    private getFmRecordLabel(field: any, selector: string, fm: IdlObject): string {
+        // for now, need to keep in sync with getFmRecordLabel in combobox
+        // alternatively, have fm-edit not wire-up the combobox's data source for it
+        switch (field.class) {
+            case 'acmc':
+                return fm.course_number() + ': ' + fm.name();
+                break;
+            case 'acqf':
+                return fm.code() + ' (' + fm.year() + ')'
+                       + ' (' + this.getOrgShortname(fm.org()) + ')';
+                break;
+            case 'acpl':
+                return fm.name() + ' (' + this.getOrgShortname(fm.owning_lib()) + ')';
+                break;
+            default:
+                // no equivalent of idlIncludeLibraryInLabel yet
+                return fm[selector]();
+        }
+    }
+    getOrgShortname(ou: any) {
+        if (typeof ou === 'object') {
+            return ou.shortname();
+        } else {
+            return this.org.get(ou).shortname();
+        }
+    }
+
     private getFieldList(): Promise<any> {
 
         const fields = this.idlDef.fields.filter(f =>