{{record[field.name]()}}
</span>
- <input *ngIf="field.datatype == 'id' && pkeyIsEditable"
- class="form-control"
- name="{{field.name}}"
- id="{{idPrefix}}-{{field.name}}"
- placeholder="{{field.label}}..."
- i18n-placeholder
- [readonly]="field.readOnly"
- [required]="field.isRequired()"
- [ngModel]="record[field.name]()"
- (ngModelChange)="record[field.name]($event)"/>
+ <ng-container *ngIf="field.datatype == 'id' && pkeyIsEditable">
+ <ng-container *ngIf="field.readOnly">
+ <span>{{record[field.name]()}}</span>
+ </ng-container>
+ <ng-container *ngIf="!field.readOnly">
+ <input
+ class="form-control"
+ name="{{field.name}}"
+ id="{{idPrefix}}-{{field.name}}"
+ placeholder="{{field.label}}..."
+ i18n-placeholder
+ [required]="field.isRequired()"
+ [ngModel]="record[field.name]()"
+ (ngModelChange)="record[field.name]($event)"/>
+ </ng-container>
+ </ng-container>
- <input *ngIf="field.datatype == 'text' || field.datatype == 'interval'"
- class="form-control"
- name="{{field.name}}"
- id="{{idPrefix}}-{{field.name}}"
- placeholder="{{field.label}}..."
- i18n-placeholder
- [readonly]="field.readOnly"
- [required]="field.isRequired()"
- [ngModel]="record[field.name]()"
- (ngModelChange)="record[field.name]($event)"/>
+ <ng-container
+ *ngIf="field.datatype == 'text' || field.datatype == 'interval'">
+ <ng-container *ngIf="field.readOnly">
+ <span>{{record[field.name]()}}</span>
+ </ng-container>
+ <ng-container *ngIf="!field.readOnly">
+ <input
+ class="form-control"
+ name="{{field.name}}"
+ id="{{idPrefix}}-{{field.name}}"
+ placeholder="{{field.label}}..."
+ i18n-placeholder
+ [required]="field.isRequired()"
+ [ngModel]="record[field.name]()"
+ (ngModelChange)="record[field.name]($event)"/>
+ </ng-container>
+ </ng-container>
+ <!-- TODO: add support to eg-date-select for read-only view -->
<span *ngIf="field.datatype == 'timestamp'">
<eg-date-select
domId="{{idPrefix}}-{{field.name}}"
</eg-date-select>
</span>
- <input *ngIf="field.datatype == 'int'"
- class="form-control"
- type="number"
- name="{{field.name}}"
- id="{{idPrefix}}-{{field.name}}"
- placeholder="{{field.label}}..."
- i18n-placeholder
- [readonly]="field.readOnly"
- [required]="field.isRequired()"
- [ngModel]="record[field.name]()"
- (ngModelChange)="record[field.name]($event)"/>
-
- <input *ngIf="field.datatype == 'float'"
- class="form-control"
- type="number" step="0.1"
- name="{{field.name}}"
- id="{{idPrefix}}-{{field.name}}"
- placeholder="{{field.label}}..."
- i18n-placeholder
- [readonly]="field.readOnly"
- [required]="field.isRequired()"
- [ngModel]="record[field.name]()"
- (ngModelChange)="record[field.name]($event)"/>
-
- <span *ngIf="field.datatype == 'money'">
- <!-- in read-only mode display the local-aware currency -->
- <input *ngIf="field.readOnly"
- class="form-control"
- type="number" step="0.1"
- name="{{field.name}}"
- id="{{idPrefix}}-{{field.name}}"
- [readonly]="field.readOnly"
- [required]="field.isRequired()"
- [ngModel]="record[field.name]() | currency"/>
-
- <input *ngIf="!field.readOnly"
+ <ng-container *ngIf="field.datatype == 'int'">
+ <ng-container *ngIf="field.readOnly">
+ <span>{{record[field.name]()}}</span>
+ </ng-container>
+ <ng-container *ngIf="!field.readOnly">
+
+ <input
class="form-control"
- type="number" step="0.1"
+ type="number"
name="{{field.name}}"
id="{{idPrefix}}-{{field.name}}"
placeholder="{{field.label}}..."
i18n-placeholder
- [readonly]="field.readOnly"
[required]="field.isRequired()"
[ngModel]="record[field.name]()"
(ngModelChange)="record[field.name]($event)"/>
- </span>
+ </ng-container>
+ </ng-container>
+
+ <ng-container *ngIf="field.datatype == 'float'">
+ <ng-container *ngIf="field.readOnly">
+ <span>{{record[field.name]()}}</span>
+ </ng-container>
+ <ng-container *ngIf="!field.readOnly">
+ <input
+ class="form-control"
+ type="number" step="0.1"
+ name="{{field.name}}"
+ id="{{idPrefix}}-{{field.name}}"
+ placeholder="{{field.label}}..."
+ i18n-placeholder
+ [required]="field.isRequired()"
+ [ngModel]="record[field.name]()"
+ (ngModelChange)="record[field.name]($event)"/>
+ </ng-container>
+ </ng-container>
+
+ <ng-container *ngIf="field.datatype == 'money'">
+ <ng-container *ngIf="field.readOnly">
+ <span>{{record[field.name]() | currency}}</span>
+ </ng-container>
+ <ng-container *ngIf="!field.readOnly">
+ <input
+ class="form-control"
+ type="number" step="0.1"
+ name="{{field.name}}"
+ id="{{idPrefix}}-{{field.name}}"
+ placeholder="{{field.label}}..."
+ i18n-placeholder
+ [readonly]="field.readOnly"
+ [required]="field.isRequired()"
+ [ngModel]="record[field.name]()"
+ (ngModelChange)="record[field.name]($event)"/>
+ </ng-container>
+ </ng-container>
<input *ngIf="field.datatype == 'bool'"
class="form-check-input"
type="checkbox"
name="{{field.name}}"
id="{{idPrefix}}-{{field.name}}"
- [readonly]="field.readOnly"
+ [disabled]="field.readOnly"
[ngModel]="record[field.name]()"
(ngModelChange)="record[field.name]($event)"/>
- <span *ngIf="field.datatype == 'link'"
- [ngClass]="{nullable : !field.isRequired()}">
- <select
- class="form-control"
- name="{{field.name}}"
- id="{{idPrefix}}-{{field.name}}"
- [disabled]="field.readOnly"
- [required]="field.isRequired()"
- [ngModel]="record[field.name]()"
- (ngModelChange)="record[field.name]($event)">
- <option *ngFor="let item of field.linkedValues"
- [value]="item.id">{{item.name}}</option>
- </select>
- </span>
+ <ng-container *ngIf="field.datatype == 'link'">
+ <ng-container *ngIf="field.readOnly">
+ <!-- in readOnly mode, if a value is presetn, it will
+ live as the only item in the linkedValues array -->
+ <ng-container *ngIf="field.linkedValues[0]">
+ <span>{{field.linkedValues[0].name}}</span>
+ </ng-container>
+ </ng-container>
+ <ng-container *ngIf="!field.readOnly">
+ <span [ngClass]="{nullable : !field.isRequired()}">
+ <select
+ class="form-control"
+ name="{{field.name}}"
+ id="{{idPrefix}}-{{field.name}}"
+ [required]="field.isRequired()"
+ [ngModel]="record[field.name]()"
+ (ngModelChange)="record[field.name]($event)">
+ <option *ngFor="let item of field.linkedValues"
+ [value]="item.id">{{item.name}}</option>
+ </select>
+ </span>
+ </ng-container>
+ </ng-container>
<eg-org-select *ngIf="field.datatype == 'org_unit'"
placeholder="{{field.label}}..."
i18n-placeholder
domId="{{idPrefix}}-{{field.name}}"
[limitPerms]="modePerms[mode]"
+ [readOnly]="field.readOnly"
[applyDefault]="field.orgDefaultAllowed"
[initialOrgId]="record[field.name]()"
(onChange)="record[field.name]($event)">
// list of fields on the IDL, since some are hidden, virtual, etc.
fields: any[];
+ // DOM id prefix to prevent id collisions.
+ idPrefix: string;
+
@Input() editMode(mode: 'create' | 'update' | 'view') {
this.mode = mode;
}
if (id) { this.recId = id; }
}
- idPrefix: string;
-
constructor(
private modal: NgbModal, // required for passing to parent
private idl: IdlService,
this.idlDef = this.idl.classes[this.idlClass];
this.recordLabel = this.idlDef.label;
- // Add some randomness to the generated DOM IDs to ensure against clobbering
- this.idPrefix = 'fm-editor-' + Math.floor(Math.random() * 100000);
+ // Add some randomness to the generated DOM IDs to ensure against clobbering
+ this.idPrefix = 'fm-editor-' + Math.floor(Math.random() * 100000);
}
// Opening dialog, fetch data.
};
}
- if (field.datatype === 'link' && field.readOnly) { // no need to fetch all possible values for read-only fields
- let id_to_fetch = this.record[field.name]();
- if (id_to_fetch) {
- promises.push(
- this.pcrud.retrieve(field.class, this.record[field.name]())
- .toPromise().then(list => {
- field.linkedValues =
- this.flattenLinkedValues(field.class, Array(list));
- })
- );
+ if (field.datatype === 'link' && field.readOnly) {
+
+ // no need to fetch all possible values for read-only fields
+ const idToFetch = this.record[field.name]();
+
+ if (idToFetch) {
+
+ // If the linked class defines a selector field, fetch the
+ // linked data so we can display the data within the selector
+ // field. Otherwise, avoid the network lookup and let the
+ // bare value (usually an ID) be displayed.
+ const idField = this.idl.classes[field.class].pkey;
+ const selector =
+ this.idl.classes[field.class].field_map[idField].selector;
+
+ if (selector && selector !== field.name) {
+ promises.push(
+ this.pcrud.retrieve(field.class, this.record[field.name]())
+ .toPromise().then(list => {
+ field.linkedValues =
+ this.flattenLinkedValues(field.class, Array(list));
+ })
+ );
+ } else {
+ // No selector, display the raw id/key value.
+ field.linkedValues = [{id: idToFetch, name: idToFetch}];
+ }
}
} else if (field.datatype === 'link') {
promises.push(