wire up functionality for primary contact
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 17 Aug 2020 19:44:56 +0000 (15:44 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 17 Aug 2020 19:44:56 +0000 (15:44 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.html
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-contacts.component.ts
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-details.component.html
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-record.service.ts
Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.css
Open-ILS/src/eg2/src/app/staff/acq/provider/summary-pane.component.html

index 113b3bf..ec7bdab 100644 (file)
@@ -4,7 +4,8 @@
 <eg-string #updateFailedString i18n-text text="Provider Contact Update Failed"></eg-string>
 <eg-string #deleteFailedString i18n-text text="Delete of Provider Contact failed or was not allowed"></eg-string>
 <eg-string #deleteSuccessString i18n-text text="Delete of Provider Contact succeeded"></eg-string>
-
+<eg-string #setAsPrimarySuccessString i18n-text text="Successfully set primary contact"></eg-string>
+<eg-string #setAsPrimaryFailedtring i18n-text text="Failed to set primary contact"></eg-string>
 
 <ng-template #emailTmpl let-contact="row">
   <a href="mailto:{{contact.email()}}">{{contact.email()}}</a>
   <a href="tel:{{contact.phone()}}">{{contact.phone()}}</a>
 </ng-template>
 
+<eg-confirm-dialog #confirmSetAsPrimary
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Confirm Setting Primary Contact"
+  dialogBody="Set {{selected ? selected.name() : ''}} as the primary contact for {{provider ? provider.name() : ''}}?">
+</eg-confirm-dialog>
+
 <eg-grid #acqProviderContactsGrid
   persistKey="acq.provider.contacts"
   idlClass="acqpc" [dataSource]="gridSource"
   <eg-grid-toolbar-button label="New Provider Contact" 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 Primary Contact" i18n-label (onClick)="setAsPrimary($event)" [disableOnRows]="notOneSelectedRow">
+  </eg-grid-toolbar-action>
+
 
   <eg-grid-column path="email" [cellTemplate]="emailTmpl" [disableTooltip]="true"></eg-grid-column>
   <eg-grid-column path="phone" [cellTemplate]="phoneTmpl" [disableTooltip]="true"></eg-grid-column>
+  <eg-grid-column [filterable]="false" [sortable]="false" i18n-label label="Is Primary?" path="_is_primary" datatype="bool"></eg-grid-column>
 </eg-grid>
 
 <ng-container *ngIf="selectedContact">
index 70ddbc5..28b997a 100644 (file)
@@ -15,6 +15,7 @@ import {ProviderContactAddressesComponent} from './provider-contact-addresses.co
 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 {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
 import {ToastService} from '@eg/share/toast/toast.service';
 
 
@@ -31,12 +32,15 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
     @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
     @ViewChild('providerContactAddresses', { static: false }) providerContactAddresses: ProviderContactAddressesComponent;
     @ViewChild('acqProviderContactsGrid', { static: true }) providerContactsGrid: GridComponent;
+    @ViewChild('confirmSetAsPrimary', { static: true }) confirmSetAsPrimary: 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('setAsPrimarySuccessString', { static: true }) setAsPrimarySuccessString: StringComponent;
+    @ViewChild('setAsPrimaryFailedString', { static: true }) setAsPrimaryFailedString: StringComponent;
 
     @Output('desireSummarize') summarize: EventEmitter<number> = new EventEmitter<number>();
 
@@ -47,6 +51,7 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
     canCreate: boolean;
     canDelete: boolean;
     deleteSelected: (rows: IdlObject[]) => void;
+    notOneSelectedRow: (rows: IdlObject[]) => boolean;
 
     permissions: {[name: string]: boolean};
 
@@ -71,6 +76,7 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
     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(
@@ -253,4 +259,33 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
             }
         );
     }
+
+    setAsPrimary(providerContacts: IdlObject[]) {
+        this.selectedContact = providerContacts[0];
+        this.confirmSetAsPrimary.open().subscribe(confirmed => {
+            if (!confirmed) { return; }
+            this.providerRecord.refreshCurrent().then(() => {
+                this.provider.primary_contact(providerContacts[0].id());
+                this.provider.ischanged(true);
+                this.providerRecord.batchUpdate(this.provider).subscribe(
+                    val => {
+                        this.setAsPrimarySuccessString.current()
+                            .then(str => this.toast.success(str));
+                    },
+                    err => {
+                        this.setAsPrimaryFailedString.current()
+                            .then(str => this.toast.danger(str));
+                    },
+                    () => {
+                        this.providerRecord.refreshCurrent().then(
+                            () => {
+                                this.providerContactsGrid.reload();
+                                this.summarize.emit(this.provider.id());
+                            }
+                        );
+                    }
+                );
+            });
+        });
+    }
 }
index 08e3b93..f548c5e 100644 (file)
@@ -10,7 +10,7 @@
   [record]="provider"
   (recordSaved)="updateProvider($event)"
   readonlyFields="id"
-  hiddenFields="holding_tag"
+  hiddenFields="holding_tag,primary_contact"
   [fieldOptions]="{currency_type:{preloadLinkedValues:true},edi_default:{preloadLinkedValues:true},default_claim_policy:{preloadLinkedValues:true}}"
   fieldOrder="active,name,code,id,currency_type,default_claim_policy,default_copy_count,edi_default,owner,phone,fax_phone,email,url,san,prepayment_required"
 >
index fdb398e..edac9ce 100644 (file)
@@ -67,6 +67,14 @@ export class ProviderRecordService {
                     }
                 }
             });
+            acqpro.contacts().forEach(acct => {
+                acct['_is_primary'] = false;
+                if (acqpro.primary_contact()) {
+                    if (acct.id() === acqpro.primary_contact()) {
+                        acct['_is_primary'] = true;
+                    }
+                }
+            });
             this.currentProvider = provider;
             this.checkIfCanDelete(provider);
             return provider;
index 48c8550..de3c24b 100644 (file)
@@ -23,4 +23,5 @@
 .row.provider_default_copy_count { display: none; }
 .row.provider_contacts { }
 .provider_contact_role { font-style: italic; }
+.provider_primary_contact { color: red; }
 .row.provider_provider_notes { display: none; }
index 7fe963f..1adc157 100644 (file)
@@ -43,6 +43,7 @@
   <div *ngFor="let contact of provider_contacts">
     <span *ngIf="contact.role()"><span class="provider_contact_role">{{contact.role()}} : </span><span>{{contact.name()}}</span></span>
     <span *ngIf="!contact.role()">{{contact.name()}}</span>
+    <span *ngIf="contact._is_primary"><span class="provider_primary_contact"> (primary)</span></span>
   </div>
 </div>
 </div>