+<!-- idlObject and fieldName applied programmatically -->
+<eg-translate #translator></eg-translate>
+
<ng-template #dialogContent>
<div class="modal-header bg-info">
<h4 class="modal-title" i18n>Record Editor: {{recordLabel}}</h4>
<div class="modal-body">
<form #fmEditForm="ngForm" role="form" class="form-validated common-form striped-odd">
<div class="form-group row" *ngFor="let field of fields">
- <div class="col-lg-3 offset-lg-1">
+ <div class="col-lg-3">
<label for="{{idPrefix}}-{{field.name}}">{{field.label}}</label>
</div>
<div class="col-lg-7">
</ng-container>
</ng-container> <!-- switch -->
</div>
+ <div class="col-lg-1" *ngIf="field.i18n && !field.readOnly">
+ <a (click)="openTranslator(field.name)"
+ i18n-title title="Translate">
+ <button class="btn btn-outline-info mat-icon-in-button">
+ <span class="material-icons">translate</span>
+ </button>
+ </a>
+ </div>
</div>
</form>
</div>
-import {Component, OnInit, Input,
+import {Component, OnInit, Input, ViewChild,
Output, EventEmitter, TemplateRef} from '@angular/core';
import {IdlService, IdlObject} from '@eg/core/idl.service';
import {Observable} from 'rxjs';
import {DialogComponent} from '@eg/share/dialog/dialog.component';
import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
+import {TranslateComponent} from '@eg/staff/share/translate/translate.component';
+
interface CustomFieldTemplate {
template: TemplateRef<any>;
// Emit an error message when the save action fails.
@Output() onError$ = new EventEmitter<string>();
+ @ViewChild('translator') private translator: TranslateComponent;
+
// IDL info for the the selected IDL class
idlDef: any;
update: pc.update ? pc.update.perms : [],
};
+ this.pkeyIsEditable = !('pkey_sequence' in this.idlDef);
+
if (this.mode === 'update' || this.mode === 'view') {
let promise;
if (this.record && this.recId === null) {
promise = Promise.resolve(this.record);
} else {
- promise =
+ promise =
this.pcrud.retrieve(this.idlClass, this.recId).toPromise();
}
});
}
- // create a new record from scratch or from a stub record
- // provided by the caller.
- this.pkeyIsEditable = !('pkey_sequence' in this.idlDef);
- if (!this.record || this.recId) {
- // user provided no seed record, create one.
- this.recId = null;
- this.record = this.idl.create(this.idlClass);
- }
+ // In 'create' mode.
+ //
+ // Create a new record from the stub record provided by the
+ // caller or a new from-scratch record
+ this.setRecord(this.record || this.idl.create(this.idlClass));
+
return this.getFieldList();
}
// datatype == text / interval / editable-pkey
return 'text';
}
+
+ openTranslator(field: string) {
+ this.translator.fieldName = field;
+ this.translator.idlObject = this.record;
+
+ // TODO: will need to change once LP1823041 is merged
+ this.translator.open().then(
+ newValue => {
+ if (newValue) {
+ this.record[field](newValue);
+ }
+ },
+ () => {} // avoid console error
+ );
+ }
}