<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
<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>
@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;
@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>();
canCreate: boolean;
canDelete: boolean;
deleteSelected: (rows: IdlObject[]) => void;
- notOneSelectedRow: (rows: IdlObject[]) => boolean;
+ cannotSetPrimaryContact: (rows: IdlObject[]) => boolean;
+ cannotUnsetPrimaryContact: (rows: IdlObject[]) => boolean;
permissions: {[name: string]: boolean};
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(
});
});
}
+
+ 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());
+ }
+ );
+ }
+ );
+ });
+ });
+ }
}