templateUrl: './org-select.component.html'
})
export class OrgSelectComponent implements OnInit {
+ static domId = 0;
selected: OrgDisplay;
click$ = new Subject<string>();
@Input() placeholder = '';
// ID to display in the DOM for this selector
- @Input() domId = '';
+ @Input() domId = 'eg-org-select-' + OrgSelectComponent.domId++;
// Org unit field displayed in the selector
@Input() displayField = 'shortname';
if (ids) { this._disabledOrgs = ids; }
}
+ get disableOrgs(): number[] {
+ return this._disabledOrgs;
+ }
+
// Apply an org unit value at load time.
// These will NOT result in an onChange event.
@Input() initialOrg: IdlObject;
return {
id : org.id(),
label : label,
- disabled : false
+ disabled : this.disableOrgs.includes(org.id())
};
}
this.selected = null;
}
+ // NgbTypeahead doesn't offer a way to style the dropdown
+ // button directly, so we have to reach up and style it ourselves.
+ applyDisableStyle() {
+ this.disableOrgs.forEach(id => {
+ const node = document.getElementById(`${this.domId}-${id}`);
+ if (node) {
+ const button = node.parentNode as HTMLElement;
+ button.classList.add('disabled');
+ }
+ });
+ }
+
filter = (text$: Observable<string>): Observable<OrgDisplay[]> => {
+
return text$.pipe(
debounceTime(200),
distinctUntilChanged(),
});
}
+ // Give the typeahead a chance to open before applying
+ // the disabled org unit styling.
+ setTimeout(() => this.applyDisableStyle());
+
return orgs.map(org => this.formatForDisplay(org));
})
);