CreateIncome.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Page from "./Page.js";
  2. import Elem from "../Elem.js";
  3. export default class CreateIncome extends Page{
  4. constructor(){
  5. super("CreateIncome");
  6. this.render();
  7. }
  8. async submit(event){
  9. event.preventDefault();
  10. await user.account.addIncome(
  11. this.container.querySelector(".name").value,
  12. this.container.querySelector(".amount").value
  13. );
  14. changePage("home");
  15. }
  16. render(){
  17. new Elem("form")
  18. .addClass("standardForm")
  19. .onsubmit(this.submit.bind(this))
  20. .append(new Elem("h1")
  21. .text("Create Income")
  22. )
  23. .append(new Elem("label")
  24. .text("Name")
  25. .append(new Elem("input")
  26. .type("text")
  27. .addClass("name")
  28. .placeholder("Name")
  29. .required()
  30. .focus()
  31. )
  32. )
  33. .append(new Elem("label")
  34. .text("Amount")
  35. .append(new Elem("input")
  36. .type("number")
  37. .addClass("amount")
  38. .placeholder("Amount")
  39. .min("0")
  40. .step("0.01")
  41. .required()
  42. )
  43. )
  44. .append(new Elem("button")
  45. .text("Create")
  46. )
  47. .append(new Elem("button")
  48. .text("Cancel")
  49. .addClass("cancel")
  50. .type("button")
  51. .onclick(()=>{changePage("home")})
  52. )
  53. .appendTo(this.container);
  54. }
  55. }