No Description

script.js 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var orden = new Map();
  2. var menu = new Map();
  3. menu.set('Pasta',[
  4. "Gardenia",
  5. "Primavera",
  6. "Carbonara",
  7. "Carnivorum",
  8. "Primavera con pollo",
  9. "Chicken carbonara",
  10. "Al pesto",
  11. "Pollo marsala",
  12. "Chicken and shrimp"
  13. ]);
  14. menu.set('Pizzeta', [
  15. "Simply Cheese",
  16. "Carbonara",
  17. "Al pesto",
  18. "Beef & Onion",
  19. "Pepperoni",
  20. "Bacon & Mushroom",
  21. "Churrasco Hollandaise",
  22. "Mr Wedge",
  23. "BBQ Meatlovers"
  24. ]);
  25. function add_item(item, category, num){
  26. var val = parseInt(document.getElementsByName(category + 'qty' + num)[0].value);
  27. var selection = category + " " + item;
  28. if (!orden.get(selection)){
  29. orden.set(selection, val);
  30. }
  31. else{
  32. orden.set(selection, orden.get(selection) + val);
  33. }
  34. localStorage.orden_local = JSON.stringify(Array.from(orden.entries()));
  35. console.log(orden);
  36. }
  37. function item_display(category){
  38. var cat_list = menu.get(category);
  39. var page = document.getElementById(category + "Div");
  40. var card_collection = "";
  41. for(var i = 0; i < cat_list.length; i++){
  42. card_collection += `<div class="card" style="width: 18rem;">
  43. <img class="card-img-top" src="img/` + category + `.png" alt="Image of ` + category + `">
  44. <div class="card-body">
  45. <h5 class="card-title">` + cat_list[i] + `</h5>
  46. <div style = "width: 100px; display: table; margin: 4px; padding: 1px;">
  47. <div style = "display: table-cell; width: 100%;">
  48. <input style = "width: 100%; margin: 1px;" type = "number" min = "1" value = "1" name = "`+ category + `qty` + i + `">
  49. </div>
  50. <div style = "padding: 5px">
  51. <button class="btn btn-primary btn-sm" onclick = "add_item('` + cat_list[i] + `', '` + category + `', `+ i + `)">Add</buton>
  52. </div>
  53. </div>
  54. </div>
  55. </div>`;
  56. }
  57. card_collection += "<br>";
  58. page.innerHTML = card_collection;
  59. }
  60. function order_summary(){
  61. try{
  62. orden = new Map(JSON.parse(localStorage.orden_local));
  63. }
  64. catch(err){
  65. alert("ERROR: Orden invalida")
  66. window.location.href = "index.html";
  67. }
  68. localStorage.orden_local = []
  69. var page = document.getElementById("rows");
  70. var orden_table = "";
  71. for(let [key,value] of orden){
  72. orden_table += `<tr>
  73. <td>` + key + `</td>
  74. <td>` + value + `</td>
  75. </tr>`
  76. }
  77. page.innerHTML = orden_table;
  78. }