SaveAndAdd Button
parent
46b4e1dcd0
commit
67d9ce7802
|
|
@ -7,6 +7,7 @@ import { MatDialog } from '@angular/material';
|
|||
import { AddTransactionPopupComponent, ValDisplay } from './add-transaction-popup/add-transaction-popup.component';
|
||||
import { TransactionType } from './transaction-type';
|
||||
import { Fund } from './fund';
|
||||
import { OkPopupComponent } from '../popups/ok-popup/ok-popup.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-transaction-page',
|
||||
|
|
@ -65,17 +66,20 @@ export class AddTransactionPageComponent implements OnInit {
|
|||
}
|
||||
});
|
||||
|
||||
ref.afterClosed().subscribe((trans: Transaction) => {
|
||||
if (trans) {
|
||||
let contrib = this.contributions.find(c => c.contributorId === trans.contributorId);
|
||||
ref.afterClosed().subscribe((res: {transaction:Transaction,saveAndAdd:boolean}) => {
|
||||
if (res) {
|
||||
let contrib = this.contributions.find(c => c.contributorId === res.transaction.contributorId);
|
||||
if (!contrib) {
|
||||
contrib = new Contribution();
|
||||
contrib.contributorId = trans.contributorId;
|
||||
contrib.date = trans.date;
|
||||
contrib.contributorId = res.transaction.contributorId;
|
||||
contrib.date = res.transaction.date;
|
||||
contrib.transactions = [];
|
||||
this.contributions.push(contrib);
|
||||
}
|
||||
contrib.transactions.push(trans);
|
||||
contrib.transactions.push(res.transaction);
|
||||
if (res.saveAndAdd === true) {
|
||||
this.addTransaction(contrib.contributorId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -139,11 +143,18 @@ export class AddTransactionPageComponent implements OnInit {
|
|||
}
|
||||
}
|
||||
|
||||
console.log(transactions);
|
||||
this.transactionService.createFromArray(transactions).subscribe(x =>{
|
||||
this.submitButtonText = 'Submit Transactions';
|
||||
this.submitButtonDisabled = false;
|
||||
}, e => console.log(e));
|
||||
this.contributions = [];
|
||||
}, e => {
|
||||
this.dialogService.open(OkPopupComponent,{
|
||||
data: {
|
||||
title: 'Error Saving Transactions',
|
||||
message: e.toString()
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
.w-100 {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.m-10 {
|
||||
margin: 10px;
|
||||
}
|
||||
|
|
@ -41,8 +41,9 @@
|
|||
<input matInput placeholder="Description" type="text" formControlName="description" >
|
||||
</mat-form-field>
|
||||
<br>
|
||||
<button mat-raised-button type="button" (click)="cancel()" >Cancel</button>
|
||||
<button mat-raised-button type="submit" [disabled]="!form.valid || saveBtnDisabled">{{ saveBtnTxt }}</button>
|
||||
<button mat-raised-button class="m-10" type="button" (click)="cancel()" >Cancel</button>
|
||||
<button mat-raised-button class="m-10" type="submit" [disabled]="!form.valid || saveBtnDisabled">{{ saveBtnTxt }}</button>
|
||||
<button mat-raised-button class="m-10" type="button" (click)="onSubmit(true)" [disabled]="!form.valid || saveBtnDisabled">{{ saveAndAddBtnTxt }}</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ export class AddTransactionPopupComponent implements OnInit {
|
|||
|
||||
saveBtnDisabled: boolean = false;
|
||||
saveBtnTxt: string = 'Save';
|
||||
saveAndAddBtnTxt: string = 'Save and Add';
|
||||
contributors: ValDisplay[] = [];
|
||||
filteredContributors: ValDisplay[]
|
||||
funds: ValDisplay[];
|
||||
|
|
@ -63,7 +64,6 @@ export class AddTransactionPopupComponent implements OnInit {
|
|||
}
|
||||
|
||||
contributorDisplayFn(contributor?: {value:number,display:string}): string | undefined {
|
||||
console.log(contributor);
|
||||
return contributor ? contributor.display : undefined;
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ export class AddTransactionPopupComponent implements OnInit {
|
|||
}
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
onSubmit(saveAndAdd: boolean = false) {
|
||||
const trans = new Transaction();
|
||||
trans.amount = this.form.value.amount;
|
||||
trans.checkNumber = this.form.value.checkNumber;
|
||||
|
|
@ -91,7 +91,7 @@ export class AddTransactionPopupComponent implements OnInit {
|
|||
trans.fundId = this.form.value.fundId;
|
||||
trans.taxYear = this.form.value.taxYear;
|
||||
trans.typeId = this.form.value.typeId;
|
||||
this.dialogRef.close(trans);
|
||||
this.dialogRef.close({transaction:trans,saveAndAdd:saveAndAdd});
|
||||
}
|
||||
|
||||
cancel() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue