-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
160 lines (149 loc) · 4.8 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
function capitalize_inputs(str) {
return str.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
function placeOrder() {
var name = capitalize_inputs($("input#name").val());
var flavor = $("#pizza-flavor").val();
var size = $("#pizza-size").val();
var crust = $("#pizza-crust").val();
var toppings = [];
$.each($('input[name="toppings"]:checked'),
function() {
toppings.push($(this).val());
});
var number = $("#pizza-number").val();
var sizeCost;
if (flavor === "Bbq Beef" || flavor === "Bbq Chicken" || flavor === "Hawaiian" || flavor === "Pulled Pork") {
if (size === "Small") {
sizeCost = 420;
} else if (size === "Medium") {
sizeCost = 670;
} else if (size === "Large") {
sizeCost = 920;
}
} else if (flavor === "Bbq Pork" || flavor === "Grilled Pork" || flavor === "Margharita" || flavor === "Marinara" || flavor === "Pepperoni") {
if (size === "Small") {
sizeCost = 470;
} else if (size === "Medium") {
sizeCost = 720;
} else if (size === "Large") {
sizeCost = 970;
}
} else if (flavor === "Chicken Tikka" || flavor === "Gamberi" || flavor === "Mushroom" || flavor === "Oyster" || flavor === "Spicy Veggie" || flavor === "Original Veggie") {
if (size === "Small") {
sizeCost = 520;
} else if (size === "Medium") {
sizeCost = 770;
} else if (size === "Large") {
sizeCost = 1120;
}
}
var crustCost;
if (crust === "Gluten Free") {
crustCost = 250;
} else if (crust === "Hand Tossed") {
crustCost = 220;
} else if (crust === "Original") {
crustCost = 170;
} else if (crust === "Pan") {
crustCost = 200;
} else if (crust === "Stuffed") {
crustCost = 270;
} else if (crust === "Thin") {
crustCost = 120;
}
var checkboxes = $('input[name="toppings"]:checked').length;
if (checkboxes <= 3) {
if (size === "Small") {
var toppingsCost = checkboxes * 90;
} else if (size === "Medium") {
var toppingsCost = checkboxes * 120;
} else if (size === "Large") {
var toppingsCost = checkboxes * 150;
}
$("input[type='checkbox']:not(:checked)").prop({
disabled: true
});
$('#placeorder').prop('disabled', true);
$("#yourorder").show();
var price = (sizeCost + crustCost + toppingsCost);
var totalPrice = parseInt(price * number);
$(".salutation").text("Hey" + " " + name + ". Here's your order:");
$(".pizza-size").append('<tr><td id="pizza-size">' + size);
$(".number").append('<tr><td id="number">' + number);
$(".pizza-crust").append('<tr><td id="pizza-crust">' + crust);
$(".pizza-flavor").append('<tr><td id="pizza-flavor">' + flavor);
$(".pizzaTotal1").append('<tr><td id="pizzaTotal1">' + totalPrice);
arrayTotal.push(totalPrice);
if (toppings == "") {
$(".toppings").append('<tr><td id="pizza-toppings">' + "-");
}
if (toppings != "") {
$(".toppings").append('<tr><td id="pizza-toppings">' + toppings);
}
$(".name").text(name);
} else {
document.getElementById("pizza-toppings-help").innerHTML = "Please select a maximum of 3!";
document.getElementById("pizza-toppings-help").style.cssText = 'color:red !important'
}
}
function makeDelivery() {
$("#deliveryConfirmation").show();
var location = capitalize_inputs($("input#location").val());
var phone = $("input#phone").val();
$(".location").text(location);
$(".phone").text(phone);
$("#delivery").hide();
}
$(document).ready(function() {
$("#orders").submit(function(event) {
event.preventDefault();
placeOrder();
});
$("#deliveryDetails").submit(function(event) {
event.preventDefault();
makeDelivery();
});
});
function cancelOrders() {
location.reload();
}
var arrayTotal = [];
function deliveryOptions() {
$("#deliveryOptions").show();
$("#orderDetails").hide();
document.getElementById("orders").reset();
$('#placeorder').prop('disabled', false);
var checkoutTotal = 0;
arrayTotal.forEach(function(index) {
checkoutTotal = checkoutTotal + index;
});
$(".totalPick").text(checkoutTotal);
var checkoutTotalDel = checkoutTotal + 200;
$(".totalDel").text(checkoutTotalDel);
}
function pickUp() {
$("#pickUpConfirmation").show();
$("#yourorder").hide();
}
function deliver() {
$("#delivery").show();
$("#yourorder").hide();
}
function reloadPage() {
location.reload();
}
function clearTextarea() {
$("#messageForm").reset();
}
function addOrder() {
$('#placeorder').prop('disabled', false);
$("input[type='checkbox']").prop({
disabled: false
});
$("input[type='checkbox']").prop({
checked: false
});
}