product_all_rents.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { formscreen } from "./formscreen";
  2. import { product_give_back_request } from "./product_give_back_request.js";
  3. import { product_reservations_request } from "./product_reservations_request";
  4. import { searcher } from "./searcher.js";
  5. export class product_all_rents extends formscreen {
  6. #target;
  7. constructor(target) {
  8. super();
  9. this.#target = target;
  10. }
  11. get _name() {
  12. return _("all-rents");
  13. }
  14. get _has_submit() {
  15. return false;
  16. }
  17. #create_single(target) {
  18. const container = document.createElement("div");
  19. container.classList.add("reservation-info");
  20. if (target.phone_number !== null) {
  21. const phone_icon = document.createElement("span");
  22. phone_icon.classList.add("material-icons");
  23. phone_icon.innerText = "phone";
  24. const phone_number = document.createElement("span");
  25. phone_number.classList.add("numbers")
  26. phone_number.innerText = target.phone_number;
  27. const phone_number_container = document.createElement("p");
  28. phone_number_container.appendChild(phone_icon);
  29. phone_number_container.appendChild(phone_number);
  30. container.appendChild(phone_number_container);
  31. }
  32. if (target.email !== null) {
  33. const email_icon = document.createElement("span");
  34. email_icon.classList.add("material-icons");
  35. email_icon.innerText = "mail";
  36. const email = document.createElement("span");
  37. email.innerText = target.email;
  38. const email_container = document.createElement("p");
  39. email_container.appendChild(email_icon);
  40. email_container.appendChild(email);
  41. container.appendChild(email_container);
  42. }
  43. return container;
  44. }
  45. #create_single_button(target) {
  46. const button = document.createElement("button");
  47. button.classList.add("material-icons");
  48. button.classList.add("give-back-button");
  49. button.innerText = "save_alt";
  50. button.addEventListener("click", async () => {
  51. try {
  52. this._info = _("processing");
  53. const request = new product_give_back_request(target);
  54. const response = await request.connect();
  55. if (!response.result) {
  56. throw new Error(_(response.cause));
  57. }
  58. this._refresh();
  59. searcher.reload();
  60. } catch (error) {
  61. this._error = String(error);
  62. }
  63. });
  64. return button;
  65. }
  66. _process() {
  67. return;
  68. }
  69. async _build_form() {
  70. try {
  71. this._info = _("loading");
  72. const request = new product_reservations_request(this.#target);
  73. const response = await request.connect();
  74. const list = document.createElement("div");
  75. list.classList.add("reservations-list");
  76. let empty = true;
  77. response.collection.forEach(count => {
  78. const item = document.createElement("div");
  79. item.classList.add("reservation");
  80. const left = this.#create_single(count);
  81. const right = this.#create_single_button(count);
  82. empty = false;
  83. item.appendChild(left);
  84. item.appendChild(right);
  85. list.appendChild(item);
  86. });
  87. this._append_child(list);
  88. if (empty) {
  89. this._success = "not-found-any-reservations";
  90. } else {
  91. this._clear_results();
  92. }
  93. } catch (error) {
  94. this._error = String(error);
  95. }
  96. }
  97. }