private orgMap: {[id: number]: IdlObject} = {};
private settingsCache: OrgSettingsBatch = {};
+ private orgTypeMap: {[id: number]: IdlObject} = {};
+ private orgTypeList: IdlObject[] = [];
+
constructor(
private net: NetService,
private auth: AuthService,
return this.orgList;
}
+ typeList(): IdlObject[] {
+ return this.orgTypeList;
+ }
+
+ typeMap(): {[id: number]: IdlObject} {
+ return this.orgTypeMap;
+ }
+
/**
* Returns a list of org units that match the selected criteria.
* All filters must match for an org to be included in the result set.
node = this.orgTree;
this.orgMap = {};
this.orgList = [];
+ this.orgTypeMap = {};
}
this.orgMap[node.id()] = node;
this.orgList.push(node);
+
+ this.orgTypeMap[node.ou_type().id()] = node.ou_type();
+ if (!this.orgTypeList.filter(t => t.id() === node.ou_type().id())[0]) {
+ this.orgTypeList.push(node.ou_type());
+ }
+
node.children().forEach(c => this.absorbTree(c));
}
@Input() startId: any;
@Input() startIdFiresOnChange: boolean;
+ // Allow the selected entry ID to be passed via the template
+ // This does NOT not emit onChange events.
+ @Input() set selectedId(id: any) {
+ if (id) {
+ if (this.entrylist.length) {
+ this.selected = this.entrylist.filter(e => e.id === id)[0];
+ } else {
+ this.startId = id;
+ }
+ }
+ }
+ get selectedId(): any {
+ return this.selected ? this.selected.id : null;
+ }
+
@Input() idlClass: string;
@Input() idlField: string;
@Input() asyncDataSource: (term: string) => Observable<ComboboxEntry>;
if (this.startId &&
this.entrylist && !this.defaultSelectionApplied) {
+ console.log('applyg select ' + this.startId);
+
const entry =
this.entrylist.filter(e => e.id === this.startId)[0];
// Manually set the selected value by ID.
// This does NOT fire the onChange handler.
+ // DEPRECATED: use this.selectedId = abc or [selectedId]="abc" instead.
applyEntryId(entryId: any) {
this.selected = this.entrylist.filter(e => e.id === entryId)[0];
}
<eg-fm-record-editor *ngIf="currentOrg()" #editDialog idlClass="aou"
[mode]="currentOrg().isnew() ? 'create': 'update'" [hideBanner]="true"
(recordSaved)="orgSaved($event)" displayMode="inline"
- readonlyFields="parent,ou_type,parent_ou"
+ readonlyFields="parent,parent_ou" [preloadLinkedValues]="true"
+ [fieldOptions]="{ou_type: {customValues: orgTypeOptions()}}"
[record]="currentOrg().isnew() ? currentOrg() : null"
[recordId]="currentOrg().isnew() ? null : currentOrg().id()"
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"
+ (actionClick)="addChild()"></eg-fm-record-editor-action>
</eg-fm-record-editor>
</div>
</ng-template>
import {StringService} from '@eg/share/string/string.service';
import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
+import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
@Component({
templateUrl: './org-unit.component.html'
});
}
+ orgTypeOptions(): ComboboxEntry[] {
+ let ouType = this.currentOrg().ou_type();
+
+ if (typeof ouType === 'number') {
+ // May not be fleshed for new org units
+ ouType = this.org.typeMap()[ouType];
+ }
+ const curDepth = ouType.depth();
+
+ return this.org.typeList()
+ .filter(type_ => type_.depth() === curDepth)
+ .map(type_ => ({id: type_.id(), label: type_.name()}));
+ }
+
+ orgChildTypes(): IdlObject[] {
+ let ouType = this.currentOrg().ou_type();
+
+ if (typeof ouType === 'number') {
+ // May not be fleshed for new org units
+ ouType = this.org.typeMap()[ouType];
+ }
+
+ const depth = ouType.depth();
+ return this.org.typeList()
+ .filter(type_ => type_.depth() === depth + 1);
+ }
+
addChild() {
const parentTreeNode = this.selected;
const parentOrg = parentTreeNode.callerData.orgUnit;
+ const newType = this.orgChildTypes()[0];
const org = this.idl.create('aou');
org.isnew(true);
- org.parent(parentOrg.id());
- // TODO: limit org type selector to types at parent depth + 1
+ org.parent_ou(parentOrg.id());
+ org.ou_type(newType.id());
// Create a dummy, detached org node to keep the UI happy.
this.selected = new TreeNode({