aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/cupboard/cupboard.component.ts
blob: cc0939356ecf4ee3f9df474b6b14806c766f58f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Component, OnInit } from '@angular/core';
import { CupboardService } from '../../services/cupboard.service';
import { NeedListComponent } from '../need-list/need-list.component';
import { Need, GoalType } from '../../models/Need';

@Component({
  selector: 'app-cupboard',
  standalone: false,
  templateUrl: './cupboard.component.html',
  styleUrl: './cupboard.component.css'
})
export class CupboardComponent implements 
  OnInit {
  need: Need = {
    id: 0,
    name: '',
    maxGoal: 0,
    type: GoalType.MONETARY,
    filterAttributes: [],
    current: 0
  };

  
    constructor(private cupboardService: CupboardService) { }
    ngOnInit(): void {
      this.close();
    }
    
    open() {
      const formElement = document.getElementById('create-form');
      if (formElement) {
        formElement.style.visibility = 'visible';
        formElement.style.position = 'relative';
      }
      const buttonElement = document.getElementById('create-button');
      if (buttonElement) {
        buttonElement.style.visibility = 'hidden';
        buttonElement.style.position = 'absolute';
      }
    }

    close() {
      const formElement = document.getElementById('create-form');
      if (formElement) {
        formElement.style.visibility = 'hidden';
        formElement.style.position = 'absolute';
      }
      const buttonElement = document.getElementById('create-button');
      if (buttonElement) {
        buttonElement.style.visibility = 'visible';
        buttonElement.style.position = 'relative';
      }
    }

    submit(form: any) {
      console.log(form);
      this.need.name = form.name;
      this.need.id = form.id;
      this.need.maxGoal = form.maxGoal;
      this.need.type = GoalType[form.type as keyof typeof GoalType];
      console.log(this.cupboardService.createNeed(this.need));
    }
  }