</eg-confirm-dialog>
<ng-template #treeNodeLabelTmpl let-org="org">
- <span *ngIf="org" i18n>{{org.name()}} ({{org.shortname()}})</span>
+ <span *ngIf="org" i18n>{{org.name()}} -- {{org.shortname()}}</span>
</ng-template>
<eg-string #treeNodeLabel key='admin.server.org_unit.treenode'
[template]="treeNodeLabelTmpl"></eg-string>
</div>
<div class="col-lg-8">
<div class="alert alert-info">
- <div *ngIf="selected" i18n>
- {{currentOrg().name()}} ({{currentOrg().shortname()}})
+ <div *ngIf="currentOrg()">
+ <span *ngIf="currentOrg().name()" i18n>
+ {{currentOrg().name()}} ({{currentOrg().shortname()}})
+ </span>
+ <span *ngIf="!currentOrg().name()" class="font-italic" i18n>
+ Add Name
+ </span>
</div>
</div>
- <ngb-tabset #rootTabs (tabChange)="tabChanged($event)">
+ <ngb-tabset #rootTabs (tabChange)="tabChanged($event)" *ngIf="currentOrg()">
<ngb-tab title="Main Settings" i18n-title id="main">
<ng-template ngbTabContent>
<div class="mt-2">
<eg-fm-record-editor *ngIf="currentOrg()" #editDialog idlClass="aou"
[mode]="currentOrg().isnew() ? 'create': 'update'" [hideBanner]="true"
(recordSaved)="orgSaved($event)" displayMode="inline"
+ (recordDeleted)="orgDeleted()"
readonlyFields="parent,parent_ou" [preloadLinkedValues]="true"
[fieldOptions]="{ou_type: {customValues: orgTypeOptions()}}"
[record]="currentOrg().isnew() ? currentOrg() : null"
[recordId]="currentOrg().isnew() ? null : currentOrg().id()"
+ [showDelete]="!orgHasChildren()"
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"
+ [disabled]="orgChildTypes().length === 0 || currentOrg().isnew()"
(actionClick)="addChild()"></eg-fm-record-editor-action>
</eg-fm-record-editor>
</div>
</ng-template>
</ngb-tab>
- <ngb-tab title="Hours of Operation" i18n-title id="hours">
+ <ngb-tab title="Hours of Operation" i18n-title id="hours"
+ [disabled]="currentOrg().isnew()">
<ng-template ngbTabContent>
<div class="mt-2 common-form striped-even">
<div class="row font-weight-bold mb-2">
</div>
</ng-template>
</ngb-tab>
- <ngb-tab title="Addresses" i18n-title id="addresses">
+ <ngb-tab title="Addresses" i18n-title id="addresses"
+ [disabled]="currentOrg().isnew()">
<ng-template ngbTabContent>
<div class="mt-2">
<ngb-tabset #addressTabs>
// stubbing out in case we need it.
}
- orgSaved(orgId: number) {
- if (!orgId && this.currentOrg()) {
- orgId = this.currentOrg().id();
+ orgSaved(orgId: number | IdlObject) {
+ let id;
+
+ if (orgId) { // new org created, focus it.
+ id = typeof orgId === 'object' ? orgId.id() : orgId;
+ } else if (this.currentOrg()) {
+ id = this.currentOrg().id();
}
- this.loadAouTree(orgId).then(_ => this.postUpdate(this.editString));
+
+ this.loadAouTree(id).then(_ => this.postUpdate(this.editString));
+ }
+
+ orgDeleted() {
+ this.loadAouTree();
}
loadAouTree(selectNodeId?: number): Promise<any> {
]}}, {authoritative: true}
).toPromise().then(tree => {
this.ingestAouTree(tree);
- if (selectNodeId) {
- const node = this.tree.findNode(selectNodeId);
- this.selected = node;
- this.tree.selectNode(node);
- }
+ if (!selectNodeId) { selectNodeId = this.org.root().id(); }
+ const node = this.tree.findNode(selectNodeId);
+ this.selected = node;
+ this.tree.selectNode(node);
});
}
return this.selected ? this.selected.callerData.orgUnit : null;
}
+ orgHasChildren(): boolean {
+ const org = this.currentOrg();
+ return (org && org.children().length > 0);
+ }
+
postUpdate(message: StringComponent) {
// Modifying org unit types means refetching the org unit
// data normally fetched on page load, since it includes
addChild() {
const parentTreeNode = this.selected;
- const parentOrg = parentTreeNode.callerData.orgUnit;
+ const parentOrg = this.currentOrg();
const newType = this.orgChildTypes()[0];
const org = this.idl.create('aou');
org.isnew(true);
org.parent_ou(parentOrg.id());
org.ou_type(newType.id());
+ org.children([]);
// Create a dummy, detached org node to keep the UI happy.
this.selected = new TreeNode({