From bc6cf1d05a13e4bbcd26fcf3fdae38daf9eaac19 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 3 Mar 2021 10:52:36 -0500 Subject: [PATCH] LP1888723 Support disabling select entries in combobox Adds a new @Input() disableEntries: any[] for tracking identifier values in the combobox that should be marked as disabled / unselectable. Substantive updates during rebasing made by Galen Charlton. Signed-off-by: Bill Erickson Signed-off-by: Ruth Frasur Signed-off-by: Galen Charlton --- .../share/combobox/combobox.component.html | 9 ++++--- .../app/share/combobox/combobox.component.ts | 26 ++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html index deb7464be3..c48d981fd4 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.html @@ -1,14 +1,15 @@ - -{{r.label || r.id}} + {{r.label}} - {{r.fm.code()}} ({{r.fm.year()}}) ({{getOrgShortname(r.fm.org())}}) + {{r.fm.code()}} ({{r.fm.year()}}) ({{getOrgShortname(r.fm.org())}}) - {{r.fm.name()}} ({{getOrgShortname(r.fm.owning_lib())}}) + + {{r.fm.name()}} ({{getOrgShortname(r.fm.owning_lib())}}) +
diff --git a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts index fb2d81bf45..7df59e8ddb 100644 --- a/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts +++ b/Open-ILS/src/eg2/src/app/share/combobox/combobox.component.ts @@ -23,6 +23,7 @@ export interface ComboboxEntry { freetext?: boolean; userdata?: any; // opaque external value; ignored by this component. fm?: IdlObject; + disabled?: boolean; } @Directive({ @@ -89,6 +90,9 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, AfterVie this.isRequired = r; } + // Array of entry identifiers to disable in the selector + @Input() disableEntries: any[] = []; + // Disable the input isDisabled: boolean; @Input() set disabled(d: boolean) { @@ -125,7 +129,8 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, AfterVie this.entrylist = [{ id: id, label: this.getFmRecordLabel(rec), - fm: rec + fm: rec, + disabled : this.disableEntries.includes(id) }]; this.selected = this.entrylist.filter(e => e.id === id)[0]; }); @@ -492,6 +497,18 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, AfterVie }); } + // NgbTypeahead doesn't offer a way to style the dropdown + // button directly, so we have to reach up and style it ourselves. + applyDisableStyle() { + this.disableEntries.forEach(id => { + const node = document.getElementById(`${this.domId}-${id}`); + if (node) { + const button = node.parentNode as HTMLElement; + button.classList.add('disabled'); + } + }); + } + filter = (text$: Observable): Observable => { return text$.pipe( debounceTime(200), @@ -520,10 +537,17 @@ export class ComboboxComponent implements ControlValueAccessor, OnInit, AfterVie if (this.asyncDataSource) { term = ''; } else { + // Give the typeahead a chance to open before applying + // the disabled entry styling. + setTimeout(() => this.applyDisableStyle()); return this.entrylist; } } + // Give the typeahead a chance to open before applying + // the disabled entry styling. + setTimeout(() => this.applyDisableStyle()); + // Filter entrylist whose labels substring-match the // text entered. return this.entrylist.filter(entry => { -- 2.43.2