orders.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. let orders = {
  2. orders: [],
  3. isPopulated: false,
  4. display: function(){
  5. if(this.isPopulated === false){
  6. document.getElementById("orderFilterBtn").onclick = ()=>{controller.openSidebar("orderFilter")};
  7. document.getElementById("newOrderBtn").onclick = ()=>{controller.openSidebar("newOrder")};
  8. this.displayOrders();
  9. }
  10. },
  11. displayOrders: function(){
  12. let orderList = document.getElementById("orderList");
  13. let template = document.getElementById("order").content.children[0];
  14. while(orderList.children.length > 0){
  15. orderList.removeChild(orderList.firstChild);
  16. }
  17. for(let i = 0; i < this.orders.length; i++){
  18. let orderDiv = template.cloneNode(true);
  19. orderDiv.order = this.orders[i];
  20. orderDiv.children[0].innerText = this.orders[i].name;
  21. orderDiv.children[1].innerText = `${this.orders[i].ingredients.length} ingredients`;
  22. orderDiv.children[2].innerText = this.orders[i].date.toLocaleDateString("en-US");
  23. orderDiv.children[3].innerText = `$${this.orders[i].getTotalCost().toFixed(2)}`;
  24. orderDiv.onclick = ()=>{
  25. controller.openSidebar("orderDetails", this.orders[i]);
  26. orderDiv.classList.add("active");
  27. }
  28. orderList.appendChild(orderDiv);
  29. }
  30. }
  31. }
  32. module.exports = orders;