From: Mike Rylander Date: Wed, 25 Mar 2020 14:46:45 +0000 (-0400) Subject: contacts modal X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=534f776d432d0c9b690cff10a757ec1370e6d31a;p=working%2FEvergreen.git contacts modal Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html index e1095049a0..7152c2f5a6 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html @@ -1,18 +1,36 @@ + + + + + + + {{contact.email()}} - {{contact.phone()}} + {{contact.phone()}} - + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts index ba06c5d929..e42e3a7537 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts @@ -1,42 +1,89 @@ -import {Component, OnInit, Input, ViewChild} from '@angular/core'; +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 {IdlObject} from '@eg/core/idl.service'; +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 {ProviderRecordService} from './provider-record.service'; import {AcqProviderSearchFormComponent} from './acq-provider-search-form.component'; +import {PcrudService} from '@eg/core/pcrud.service'; +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-contacts', templateUrl: 'provider-contacts.component.html', }) -export class ProviderContactsComponent implements OnInit { +export class ProviderContactsComponent implements OnInit, AfterViewInit { @Input() providerId: any; contacts: any[] = []; gridSource: GridDataSource; + @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; @ViewChild('acqProviderContactsGrid', { static: true }) providerContactsGrid: 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; provider: IdlObject; + canCreate: boolean; + canDelete: boolean; + deleteSelected: (rows: IdlObject[]) => void; + + permissions: {[name: string]: boolean}; + + // Size of create/edito dialog. Uses large by default. + @Input() dialogSize: 'sm' | 'lg' = 'lg'; + constructor( private router: Router, private route: ActivatedRoute, private net: NetService, private auth: AuthService, - private providerRecord: ProviderRecordService) { + private idl: IdlService, + private providerRecord: ProviderRecordService, + private pcrud: PcrudService, + private toast: ToastService) { + } ngOnInit() { this.gridSource = this.getDataSource() this.cellTextGenerator = {}; + 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.providerContactsGrid.reload() + ); + }; + this.providerContactsGrid.onRowActivate.subscribe( + (idlThing: IdlObject) => this.showEditDialog(idlThing) + ); + } + + ngAfterViewInit() { + console.log('this.providerRecord',this.providerRecord); } getDataSource(): GridDataSource { @@ -70,4 +117,56 @@ export class ProviderContactsComponent implements OnInit { return gridSource; } + showEditDialog(providerContact: IdlObject): Promise { + this.editDialog.mode = 'update'; + this.editDialog.recordId = providerContact['id'](); + return new Promise((resolve, reject) => { + this.editDialog.open({size: this.dialogSize}).subscribe( + result => { + this.successString.current() + .then(str => this.toast.success(str)); + this.providerContactsGrid.reload(); + resolve(result); + }, + error => { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + reject(error); + } + ); + }); + } + + editSelected(providerContactFields: IdlObject[]) { + // Edit each IDL thing one at a time + const editOneThing = (providerContact: IdlObject) => { + if (!providerContact) { return; } + + this.showEditDialog(providerContact).then( + () => editOneThing(providerContactFields.shift())); + }; + + editOneThing(providerContactFields.shift()); + } + + createNew() { + this.editDialog.mode = 'create'; + const contact = this.idl.create('acqpc'); + contact.provider(this.provider.id()); + this.editDialog.record = contact; + this.editDialog.recordId = null; + this.editDialog.open({size: this.dialogSize}).subscribe( + ok => { + this.createString.current() + .then(str => this.toast.success(str)); + this.providerContactsGrid.reload(); + }, + rejection => { + if (!rejection.dismissed) { + this.createErrString.current() + .then(str => this.toast.danger(str)); + } + } + ); + } }