LH#15: tweaks to primary contact functionality
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 31 Aug 2020 21:43:47 +0000 (17:43 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 31 Aug 2020 21:43:47 +0000 (17:43 -0400)
- added unset as primary action
- fixed confirmation modals
- more selectively enable and disable the set and unset actions

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

index ec7bdab..694ca44 100644 (file)
@@ -6,6 +6,8 @@
 <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>
+<eg-string #unsetAsPrimarySuccessString i18n-text text="Successfully removed primary contact"></eg-string>
+<eg-string #unsetAsPrimaryFailedtring i18n-text text="Failed to remove primary contact"></eg-string>
 
 <ng-template #emailTmpl let-contact="row">
   <a href="mailto:{{contact.email()}}">{{contact.email()}}</a>
 <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() : ''}}?">
+  dialogBody="Set {{selectedContact ? selectedContact.name() : ''}} as the primary contact for {{provider ? provider.name() : ''}}?">
+</eg-confirm-dialog>
+
+<eg-confirm-dialog #confirmUnsetAsPrimary
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Confirm Unsetting Primary Contact"
+  dialogBody="Unset {{selectedContact ? selectedContact.name() : ''}} as the primary contact for {{provider ? provider.name() : ''}}?">
 </eg-confirm-dialog>
 
 <eg-grid #acqProviderContactsGrid
@@ -33,7 +41,9 @@
   <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 label="Set as Primary Contact" i18n-label (onClick)="setAsPrimary($event)" [disableOnRows]="cannotSetPrimaryContact">
+  </eg-grid-toolbar-action>
+  <eg-grid-toolbar-action label="Unset as Primary Contact" i18n-label (onClick)="unsetAsPrimary($event)" [disableOnRows]="cannotUnsetPrimaryContact">
   </eg-grid-toolbar-action>
 
 
index 28b997a..5e1b0c4 100644 (file)
@@ -33,6 +33,7 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
     @ViewChild('providerContactAddresses', { static: false }) providerContactAddresses: ProviderContactAddressesComponent;
     @ViewChild('acqProviderContactsGrid', { static: true }) providerContactsGrid: GridComponent;
     @ViewChild('confirmSetAsPrimary', { static: true }) confirmSetAsPrimary: ConfirmDialogComponent;
+    @ViewChild('confirmUnsetAsPrimary', { static: true }) confirmUnsetAsPrimary: ConfirmDialogComponent;
     @ViewChild('successString', { static: true }) successString: StringComponent;
     @ViewChild('createString', { static: false }) createString: StringComponent;
     @ViewChild('createErrString', { static: false }) createErrString: StringComponent;
@@ -41,6 +42,8 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
     @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent;
     @ViewChild('setAsPrimarySuccessString', { static: true }) setAsPrimarySuccessString: StringComponent;
     @ViewChild('setAsPrimaryFailedString', { static: true }) setAsPrimaryFailedString: StringComponent;
+    @ViewChild('unsetAsPrimarySuccessString', { static: true }) unsetAsPrimarySuccessString: StringComponent;
+    @ViewChild('unsetAsPrimaryFailedString', { static: true }) unsetAsPrimaryFailedString: StringComponent;
 
     @Output('desireSummarize') summarize: EventEmitter<number> = new EventEmitter<number>();
 
@@ -51,7 +54,8 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
     canCreate: boolean;
     canDelete: boolean;
     deleteSelected: (rows: IdlObject[]) => void;
-    notOneSelectedRow: (rows: IdlObject[]) => boolean;
+    cannotSetPrimaryContact: (rows: IdlObject[]) => boolean;
+    cannotUnsetPrimaryContact: (rows: IdlObject[]) => boolean;
 
     permissions: {[name: string]: boolean};
 
@@ -76,7 +80,8 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
     ngOnInit() {
         this.gridSource = this.getDataSource()
         this.cellTextGenerator = {};
-        this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
+        this.cannotSetPrimaryContact = (rows: IdlObject[]) => (rows.length !== 1 || (rows.length == 1 && rows[0]._is_primary));
+        this.cannotUnsetPrimaryContact = (rows: IdlObject[]) => (rows.length !== 1 || (rows.length == 1 && !rows[0]._is_primary));
         this.deleteSelected = (idlThings: IdlObject[]) => {
             idlThings.forEach(idlThing => idlThing.isdeleted(true));
             this.providerRecord.batchUpdate(idlThings).subscribe(
@@ -288,4 +293,33 @@ export class ProviderContactsComponent implements OnInit, AfterViewInit {
             });
         });
     }
+
+    unsetAsPrimary(providerContacts: IdlObject[]) {
+        this.selectedContact = providerContacts[0];
+        this.confirmUnsetAsPrimary.open().subscribe(confirmed => {
+            if (!confirmed) { return; }
+            this.providerRecord.refreshCurrent().then(() => {
+                this.provider.primary_contact(null);
+                this.provider.ischanged(true);
+                this.providerRecord.batchUpdate(this.provider).subscribe(
+                    val => {
+                        this.unsetAsPrimarySuccessString.current()
+                            .then(str => this.toast.success(str));
+                    },
+                    err => {
+                        this.unsetAsPrimaryFailedString.current()
+                            .then(str => this.toast.danger(str));
+                    },
+                    () => {
+                        this.providerRecord.refreshCurrent().then(
+                            () => {
+                                this.providerContactsGrid.reload();
+                                this.summarize.emit(this.provider.id());
+                            }
+                        );
+                    }
+                );
+            });
+        });
+    }
 }