aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-ui/src/app/components/funding-basket/funding-basket.component.ts')
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.ts28
1 files changed, 27 insertions, 1 deletions
diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
index 061e3fa..a7a38b8 100644
--- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
+++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
@@ -1,4 +1,4 @@
-import {Component, OnInit} from '@angular/core';
+import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {User} from '../../models/User';
import { UsersService } from '../../services/users.service';
import { Need } from '../../models/Need';
@@ -21,6 +21,9 @@ export class FundingBasketComponent implements OnInit {
protected usersService: UsersService
) {}
+ @ViewChild("contribution") contribution?: Input;
+ @Input() isValid: boolean = true;
+
// this is for login rerouting
ngOnInit(): void {
if (!this.usersService.getCurrentUser()) {
@@ -32,6 +35,29 @@ export class FundingBasketComponent implements OnInit {
// this.usersService.removeNeed(); <- call this to remove
}
+ async checkout() {
+ this.isValid = true;
+ for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
+ var contribution = c as HTMLInputElement;
+ console.log(contribution.value, contribution.id);
+ contribution.setAttribute("style","");
+ if ( contribution.value == '' || contribution.valueAsNumber < 0) {
+ this.isValid = false;
+ contribution.setAttribute("style","color: #ff0000");
+ }
+ }
+ if (this.isValid) {
+ for (let c of document.getElementById("funding-basket")?.querySelectorAll('.contribution')!) {
+ var contribution = c as HTMLInputElement;
+ var need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));
+ need.current +=+ contribution.value;
+ console.log(need);
+ this.cupboardService.updateNeed(+contribution.id, need);
+ this.usersService.removeNeed(+contribution.id);
+ }
+ }
+ }
+
}