--- /dev/null
+<eg-string #createString i18n-text text="New EDI Account Added"></eg-string>
+<eg-string #createErrString i18n-text text="Failed to Create New EDI Account"></eg-string>
+<eg-string #successString i18n-text text="EDI Account Update Succeeded"></eg-string>
+<eg-string #updateFailedString i18n-text text="EDI Account Update Failed"></eg-string>
+<eg-string #deleteFailedString i18n-text text="Delete of EDI Account failed or was not allowed"></eg-string>
+<eg-string #deleteSuccessString i18n-text text="Delete of EDI Account succeeded"></eg-string>
+<eg-string #setAsDefaultSuccessString i18n-text text="Successfully set EDI default account"></eg-string>
+<eg-string #setAsDefaultFailedtring i18n-text text="Failed to set EDI default account"></eg-string>
+
+<eg-confirm-dialog #confirmSetAsDefault
+ i18n-dialogTitle i18n-dialogBody
+ dialogTitle="Confirm Setting Default EDI Account"
+ dialogBody="Set {{selected ? selected.label() : ''}} as the default EDI account for {{provider ? provider.name() : ''}}?">
+</eg-confirm-dialog>
+
+<eg-grid #acqProviderEdiAccountsGrid
+ persistKey="acq.provider.edi_accounts.grid"
+ idlClass="acqedi" [dataSource]="gridSource"
+ [sortable]="true"
+ hideFields="provider"
+ [cellTextGenerator]="cellTextGenerator">
+ <eg-grid-toolbar-button
+ label="New EDI Account" 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-toolbar-action label="Set as Default" i18n-label (onClick)="setAsDefault($event)" [disableOnRows]="notOneSelectedRow">
+ </eg-grid-toolbar-action>
+</eg-grid>
+
+<eg-fm-record-editor #editDialog
+ idlClass="acqedi"
+ readonlyFields="id,provider"
+ hiddenFields="provider,last_activity"
+ fieldOrder="id,label,host,username,password,account,owner,path,in_dir,vendacct,vendcode,attr_set,use_attrs">
+</eg-fm-record-editor>
+
--- /dev/null
+import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter, 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 {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';
+import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
+
+@Component({
+ selector: 'eg-provider-edi-accounts',
+ templateUrl: 'provider-edi-accounts.component.html',
+})
+export class ProviderEdiAccountsComponent implements OnInit, AfterViewInit {
+
+ edi_accounts: any[] = [];
+
+ gridSource: GridDataSource;
+ @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
+ @ViewChild('acqProviderEdiAccountsGrid', { static: true }) providerEdiAccountsGrid: GridComponent;
+ @ViewChild('confirmSetAsDefault', { static: true }) confirmSetAsDefault: ConfirmDialogComponent;
+ @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;
+ @ViewChild('setAsDefaultSuccessString', { static: true }) setAsDefaultSuccessString: StringComponent;
+ @ViewChild('setAsDefaultFailedString', { static: true }) setAsDefaultFailedString: StringComponent;
+
+ cellTextGenerator: GridCellTextGenerator;
+ provider: IdlObject;
+ selected: IdlObject;
+
+ canCreate: boolean;
+ canDelete: boolean;
+ notOneSelectedRow: (rows: IdlObject[]) => boolean;
+ deleteSelected: (rows: IdlObject[]) => void;
+
+ permissions: {[name: string]: boolean};
+
+ // Size of create/edito dialog. Uses large by default.
+ @Input() dialogSize: 'sm' | 'lg' = 'lg';
+ @Output('desireSummarize') summarize: EventEmitter<number> = new EventEmitter<number>();
+
+ constructor(
+ private router: Router,
+ private route: ActivatedRoute,
+ private net: NetService,
+ private idl: IdlService,
+ private auth: AuthService,
+ private providerRecord: ProviderRecordService,
+ private toast: ToastService) {
+ }
+
+ ngOnInit() {
+ this.gridSource = this.getDataSource()
+ this.cellTextGenerator = {};
+ this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
+ this.deleteSelected = (idlThings: IdlObject[]) => {
+ idlThings.forEach(idlThing => idlThing.isdeleted(true));
+ this.providerRecord.batchUpdate(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.providerEdiAccountsGrid.reload();
+ }
+ );
+ }
+ );
+ };
+ this.providerEdiAccountsGrid.onRowActivate.subscribe(
+ (idlThing: IdlObject) => this.showEditDialog(idlThing)
+ );
+ }
+
+ ngAfterViewInit() {
+ console.log('this.providerRecord',this.providerRecord);
+ }
+
+ getDataSource(): GridDataSource {
+ const gridSource = new GridDataSource();
+
+ gridSource.getRows = (pager: Pager, sort: any[]) => {
+ this.provider = this.providerRecord.current();
+ if (!this.provider) {
+ return empty();
+ }
+ let edi_accounts = this.provider.edi_accounts()
+
+ if (sort.length > 0) {
+ edi_accounts = edi_accounts.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(edi_accounts.slice(pager.offset, pager.offset + pager.limit - 1));
+ };
+ return gridSource;
+ }
+
+ showEditDialog(providerEdiAccount: IdlObject): Promise<any> {
+ this.editDialog.mode = 'update';
+ this.editDialog.recordId = providerEdiAccount['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.providerEdiAccountsGrid.reload()
+ );
+ resolve(result);
+ },
+ error => {
+ this.updateFailedString.current()
+ .then(str => this.toast.danger(str));
+ reject(error);
+ }
+ );
+ });
+ }
+
+ editSelected(providerEdiAccountFields: IdlObject[]) {
+ // Edit each IDL thing one at a time
+ const editOneThing = (providerEdiAccount: IdlObject) => {
+ if (!providerEdiAccount) { return; }
+
+ this.showEditDialog(providerEdiAccount).then(
+ () => editOneThing(providerEdiAccountFields.shift()));
+ };
+
+ editOneThing(providerEdiAccountFields.shift());
+ }
+
+ setAsDefault(providerEdiAccountFields: IdlObject[]) {
+ this.selected = providerEdiAccountFields[0];
+ this.confirmSetAsDefault.open().subscribe(confirmed => {
+ if (!confirmed) { return; }
+ this.providerRecord.refreshCurrent().then(() => {
+ this.provider.edi_default(providerEdiAccountFields[0].id());
+ this.provider.ischanged(true);
+ this.providerRecord.batchUpdate(this.provider).subscribe(
+ val => {
+ this.setAsDefaultSuccessString.current()
+ .then(str => this.toast.success(str));
+ },
+ err => {
+ this.setAsDefaultFailedString.current()
+ .then(str => this.toast.danger(str));
+ },
+ () => {
+ this.providerRecord.refreshCurrent(),
+ this.summarize.emit(this.provider.id());
+ }
+ );
+ });
+ });
+ }
+
+ createNew() {
+ this.editDialog.mode = 'create';
+ const edi_account = this.idl.create('acqedi');
+ edi_account.provider(this.provider.id());
+ edi_account.owner(this.auth.user().ws_ou())
+ edi_account.use_attrs(true);
+ this.editDialog.record = edi_account;
+ 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.providerEdiAccountsGrid.reload()
+ );
+ },
+ rejection => {
+ if (!rejection.dismissed) {
+ this.createErrString.current()
+ .then(str => this.toast.danger(str));
+ }
+ }
+ );
+ }
+
+}