--- /dev/null
+<eg-string #createString i18n-text text="New Contact Address Added"></eg-string>
+<eg-string #createErrString i18n-text text="Failed to Create New Contact Address"></eg-string>
+<eg-string #successString i18n-text text="Contact Address Update Succeeded"></eg-string>
+<eg-string #updateFailedString i18n-text text="Contact Address Update Failed"></eg-string>
+<eg-string #deleteFailedString i18n-text text="Delete of Contact Address failed or was not allowed"></eg-string>
+<eg-string #deleteSuccessString i18n-text text="Delete of Contact Address succeeded"></eg-string>
+
+<eg-grid #acqProviderContactAddressesGrid
+ persistKey="acq.provider.contact.addresses.grid"
+ idlClass="acqpca" [dataSource]="gridSource"
+ [sortable]="true"
+ hideFields="contact"
+ [cellTextGenerator]="cellTextGenerator">
+ <eg-grid-toolbar-button
+ label="New Contact Address" i18n-label (onClick)="createNew()">
+ </eg-grid-toolbar-button>
+ <eg-grid-toolbar-action label="Edit Selected" i18n-label (onClick)="editSelected($event)">
+ </eg-grid-toolbar-action>
+ <eg-grid-toolbar-action label="Delete Selected" i18n-label (onClick)="deleteSelected($event)">
+ </eg-grid-toolbar-action>
+</eg-grid>
+
+<eg-fm-record-editor #editDialog
+ idlClass="acqpca"
+ readonlyFields="id,contact"
+ fieldOrder="id,valid,address_type,contact,street1,street2,city,county,state,country,post_code,fax_phone">
+</eg-fm-record-editor>
+
--- /dev/null
+import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core';
+import {empty, throwError, Observable, from} from 'rxjs';
+import {map} from 'rxjs/operators';
+import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {Pager} from '@eg/share/util/pager';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
+import {PcrudService} from '@eg/core/pcrud.service';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
+import {ProviderRecord, ProviderRecordService} from './provider-record.service';
+import {AcqProviderSearchFormComponent} from './acq-provider-search-form.component';
+import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
+import {StringComponent} from '@eg/share/string/string.component';
+import {ToastService} from '@eg/share/toast/toast.service';
+
+@Component({
+ selector: 'eg-provider-contact-addresses',
+ templateUrl: 'provider-contact-addresses.component.html',
+})
+export class ProviderContactAddressesComponent implements OnInit, AfterViewInit {
+
+ addresses: any[] = [];
+
+ gridSource: GridDataSource;
+ @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
+ @ViewChild('acqProviderContactAddressesGrid', { static: true }) providerContactAddressesGrid: GridComponent;
+ @ViewChild('successString', { static: true }) successString: StringComponent;
+ @ViewChild('createString', { static: false }) createString: StringComponent;
+ @ViewChild('createErrString', { static: false }) createErrString: StringComponent;
+ @ViewChild('updateFailedString', { static: false }) updateFailedString: StringComponent;
+ @ViewChild('deleteFailedString', { static: true }) deleteFailedString: StringComponent;
+ @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent;
+
+ cellTextGenerator: GridCellTextGenerator;
+
+ canCreate: boolean;
+ canDelete: boolean;
+ deleteSelected: (rows: IdlObject[]) => void;
+ reloadGrid: () => void;
+
+ permissions: {[name: string]: boolean};
+
+ // Size of create/edito dialog. Uses large by default.
+ @Input() dialogSize: 'sm' | 'lg' = 'lg';
+ @Input() contact: IdlObject;
+
+ constructor(
+ private router: Router,
+ private route: ActivatedRoute,
+ private net: NetService,
+ private idl: IdlService,
+ private auth: AuthService,
+ private providerRecord: ProviderRecordService,
+ private toast: ToastService,
+ private pcrud: PcrudService) {
+ }
+
+ ngOnInit() {
+ this.gridSource = this.getDataSource()
+ this.cellTextGenerator = {};
+ this.reloadGrid = () => this.providerContactAddressesGrid.reload();
+ this.deleteSelected = (idlThings: IdlObject[]) => {
+ idlThings.forEach(idlThing => idlThing.isdeleted(true));
+ this.pcrud.autoApply(idlThings).subscribe(
+ val => {
+ console.debug('deleted: ' + val);
+ this.deleteSuccessString.current()
+ .then(str => this.toast.success(str));
+ },
+ err => {
+ this.deleteFailedString.current()
+ .then(str => this.toast.danger(str));
+ },
+ () => {
+ this.providerRecord.refreshCurrent().then(
+ () => this.providerContactAddressesGrid.reload()
+ );
+ }
+ );
+ };
+ this.providerContactAddressesGrid.onRowActivate.subscribe(
+ (idlThing: IdlObject) => this.showEditDialog(idlThing)
+ );
+ }
+
+
+ ngAfterViewInit() {
+ console.log('this.contact',this.contact);
+ }
+
+ getDataSource(): GridDataSource {
+ const gridSource = new GridDataSource();
+
+ gridSource.getRows = (pager: Pager, sort: any[]) => {
+ if (!this.contact) {
+ return empty();
+ }
+ let addresses = this.contact.addresses()
+
+ if (sort.length > 0) {
+ addresses = addresses.sort((a, b) => {
+ for (let i = 0; i < sort.length; i++) {
+ let lt = -1;
+ let sfield = sort[i].name;
+ if (sort[i].dir.substring(0,1).toLowerCase() === 'd') {
+ lt *= -1;
+ }
+ if (a[sfield]() < b[sfield]()) { return lt }
+ if (a[sfield]() > b[sfield]()) { return lt * -1 }
+ }
+ return 0;
+ });
+
+ }
+
+ return from(addresses.slice(pager.offset, pager.offset + pager.limit - 1));
+ };
+ return gridSource;
+ }
+
+ showEditDialog(providerContactAddress: IdlObject): Promise<any> {
+ this.editDialog.mode = 'update';
+ this.editDialog.recordId = providerContactAddress['id']();
+ return new Promise((resolve, reject) => {
+ this.editDialog.open({size: this.dialogSize}).subscribe(
+ result => {
+ this.successString.current()
+ .then(str => this.toast.success(str));
+ this.providerRecord.refreshCurrent().then(
+ () => this.providerContactAddressesGrid.reload()
+ );
+ resolve(result);
+ },
+ error => {
+ this.updateFailedString.current()
+ .then(str => this.toast.danger(str));
+ reject(error);
+ }
+ );
+ });
+ }
+
+ editSelected(providerContactAddressFields: IdlObject[]) {
+ // Edit each IDL thing one at a time
+ const editOneThing = (providerContactAddress: IdlObject) => {
+ if (!providerContactAddress) { return; }
+
+ this.showEditDialog(providerContactAddress).then(
+ () => editOneThing(providerContactAddressFields.shift()));
+ };
+
+ editOneThing(providerContactAddressFields.shift());
+ }
+
+ createNew() {
+ this.editDialog.mode = 'create';
+ const address = this.idl.create('acqpca');
+ address.contact(this.contact.id());
+ address.valid(true);
+ this.editDialog.record = address;
+ this.editDialog.recordId = null;
+ this.editDialog.open({size: this.dialogSize}).subscribe(
+ ok => {
+ this.createString.current()
+ .then(str => this.toast.success(str));
+ this.providerRecord.refreshCurrent().then(
+ () => this.providerContactAddressesGrid.reload()
+ );
+ },
+ rejection => {
+ if (!rejection.dismissed) {
+ this.createErrString.current()
+ .then(str => this.toast.danger(str));
+ }
+ }
+ );
+ }
+}
import {GridComponent} from '@eg/share/grid/grid.component';
import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
import {ProviderRecordService} from './provider-record.service';
+import {ProviderContactAddressesComponent} from './provider-contact-addresses.component';
import {AcqProviderSearchFormComponent} from './acq-provider-search-form.component';
import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
import {StringComponent} from '@eg/share/string/string.component';
gridSource: GridDataSource;
@ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
+ @ViewChild('providerContactAddresses', { static: true }) providerContactAddresses: ProviderContactAddressesComponent;
@ViewChild('acqProviderContactsGrid', { static: true }) providerContactsGrid: GridComponent;
@ViewChild('successString', { static: true }) successString: StringComponent;
@ViewChild('createString', { static: false }) createString: StringComponent;
cellTextGenerator: GridCellTextGenerator;
provider: IdlObject;
+ selectedContact: IdlObject;
canCreate: boolean;
canDelete: boolean;
ngAfterViewInit() {
console.log('this.providerRecord',this.providerRecord);
+ console.log('this.providerContactAddresses',this.providerContactAddresses);
+ this.providerContactsGrid.onRowClick.subscribe(
+ (idlThing: IdlObject) => {
+ this.selectedContact = idlThing;
+ console.debug('selected contact',this.selectedContact);
+ this.providerContactAddresses.reloadGrid();
+ }
+ );
}
getDataSource(): GridDataSource {