dialogBody="Delete Org Unit Type {{selected ? selected.label : ''}}?">
</eg-confirm-dialog>
-<eg-fm-record-editor #editDialog idlClass="aout" readonlyFields="depth,parent">
+<eg-fm-record-editor #editDialog idlClass="aout" readonlyFields="depth,parent"
+ [fieldOptions]="{name:{isRequired:true},opac_label:{isRequired:true}}"
+>
</eg-fm-record-editor>
<div class="row">
<div class="col-lg-9">
<button class="btn btn-info mr-2" (click)="edit()" i18n>Edit</button>
<button class="btn btn-info mr-2" (click)="addChild()" i18n>Add Child</button>
- <button class="btn btn-warning mr-2" (click)="remove()" i18n>Delete</button>
+ <button class="btn btn-warning mr-2" (click)="remove()"
+ [disabled]="selected.callerData.aout.children().length > 0 || selected.callerData.orgCount > 0" i18n>Delete</button>
</div>
</div>
<div class="row">
<label i18n>Name: </label>
</div>
<div class="col-lg-8 font-weight-bold">
- {{selected.callerData.name()}}
+ {{selected.callerData.aout.name()}}
</div>
</div>
<div class="row">
<label i18n>Label: </label>
</div>
<div class="col-lg-8 font-weight-bold">
- {{selected.callerData.opac_label()}}
+ {{selected.callerData.aout.opac_label()}}
</div>
</div>
<div class="row">
</div>
<div class="col-lg-8 font-weight-bold">
<!-- TODO: use <eg-bool/> once merged-->
- {{selected.callerData.can_have_users() == 't'}}
+ {{selected.callerData.aout.can_have_users() == 't'}}
</div>
</div>
<div class="row">
</div>
<div class="col-lg-8 font-weight-bold">
<!-- TODO: use <eg-bool/> once merged-->
- {{selected.callerData.can_have_vols() == 't'}}
+ {{selected.callerData.aout.can_have_vols() == 't'}}
</div>
</div>
<div class="row">
<label i18n>Depth: </label>
</div>
<div class="col-lg-8 font-weight-bold">
- {{selected.callerData.depth()}}
+ {{selected.callerData.aout.depth()}}
+ </div>
+ </div>
+ <div class="row">
+ <div class="col-lg-4">
+ <label i18n>Number of Org Units Of This Type: </label>
+ </div>
+ <div class="col-lg-8 font-weight-bold">
+ {{selected.callerData.orgCount}}
</div>
</div>
</div>
loadAoutTree() {
this.pcrud.search('aout', {depth: 0},
- {flesh: -1, flesh_fields: {aout: ['children']}},
+ {flesh: -1, flesh_fields: {aout: ['children','org_units']}},
{anonymous: true}
).subscribe(aoutTree => this.ingestAoutTree(aoutTree));
}
const handleNode = (aoutNode: IdlObject): TreeNode => {
if (!aoutNode) { return; }
+ // grab number of associated org units, then
+ // clear it so that FmRecordEditor doesn't try
+ // to render the list
+ const orgCount = aoutNode.org_units().length;
+ aoutNode.org_units(null);
+
const treeNode = new TreeNode({
id: aoutNode.id(),
label: aoutNode.name(),
- callerData: aoutNode
+ callerData: { aout: aoutNode, orgCount: orgCount },
});
aoutNode.children().forEach(childNode =>
edit() {
this.editDialog.mode = 'update';
- this.editDialog.setRecord(this.selected.callerData);
+ this.editDialog.setRecord(this.selected.callerData.aout);
this.editDialog.open().then(
success => {
this.postUpdate(this.editString);
+ this.loadAoutTree(); // since the tree is never going to
+ // be large, just reload the whole
+ // thing
},
rejected => {
if (rejected && rejected.dismissed) {
remove() {
this.delConfirm.open().then(
ok => {
- this.pcrud.remove(this.selected.callerData)
+ this.pcrud.remove(this.selected.callerData.aout)
.subscribe(
ok2 => {},
err => {
() => {
// Avoid updating until we know the entire
// pcrud action/transaction completed.
- this.tree.removeNode(this.selected);
+ this.loadAoutTree(); // since the tree is never going to
+ // be large, just reload the whole
+ // thing
this.selected = null;
this.postUpdate(this.editString);
}
addChild() {
const parentTreeNode = this.selected;
- const parentType = parentTreeNode.callerData;
+ const parentType = parentTreeNode.callerData.aout;
const newType = this.idl.create('aout');
newType.parent(parentType.id());
const newNode = new TreeNode({
id: result.id(),
label: result.name(),
- callerData: result
+ callerData: { aout: result, orgCount: 0 }
});
- parentTreeNode.children.push(newNode);
+ this.loadAoutTree(); // since the tree is never going to
+ // be large, just reload the whole
+ // thing
this.postUpdate(this.createString);
},