EditIncome.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import Page from "./Page.js";
  2. import Elem from "../Elem.js";
  3. import Format from "../Format.js";
  4. export default class EditIncome extends Page{
  5. constructor(income){
  6. super("EditIncome", ["home", "back-viewIncome", "logout"]);
  7. this.render(income);
  8. }
  9. submit(income){
  10. event.preventDefault();
  11. income.name = this.container.querySelector(".name").value;
  12. income.amount = this.container.querySelector(".amount").value;
  13. user.account.save();
  14. changePage("viewIncome");
  15. }
  16. archive(income){
  17. income.active = !income.active;
  18. user.account.save();
  19. changePage("viewIncome");
  20. }
  21. render(income){
  22. new Elem("form")
  23. .addClass("standardForm")
  24. .onsubmit(()=>{this.submit(income)})
  25. .append(new Elem("h1")
  26. .text(income.name)
  27. )
  28. .append(new Elem("h3")
  29. .text("Income")
  30. )
  31. .append(new Elem("label")
  32. .text("Name")
  33. .append(new Elem("input")
  34. .type("text")
  35. .addClass("name")
  36. .value(income.name)
  37. .required()
  38. .focus()
  39. )
  40. )
  41. .append(new Elem("label")
  42. .text("Amount")
  43. .append(new Elem("input")
  44. .type("number")
  45. .addClass("amount")
  46. .value(Format.centsToDollars(income.amount))
  47. .step("0.01")
  48. .min("0")
  49. .required()
  50. )
  51. )
  52. .append(new Elem("button")
  53. .text("Update")
  54. )
  55. .append(new Elem("button")
  56. .text(income.active ? "Archive" : "Restore")
  57. .addClass("archive")
  58. .type("button")
  59. .onclick(()=>{this.archive(income)})
  60. )
  61. .appendTo(this.container);
  62. }
  63. }