-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
206 lines (185 loc) · 8.84 KB
/
app.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//Author: Vipul Anand, 20June2020, Simple Attempt for farmer community to connect with urban customers directly!!
//Have I succeeded or not, these attempts will tell in time, I am sure that overhead cost of app development is brought down for farmers to afford and adopt technology!!
var clickedItem = document.getElementById("order"),
enTxt,
dozen,
oneTray,
twoTray,
twoLtrs,
threeLtrs,
fourLtrs,
vegGhiya,
vegMint,
vegDhania,
vegAloo,
vegOnion,
vegTomatoes,
vegMirchi,
orderItem = document.querySelectorAll(".orderListItem"),
orderCart = document.getElementById("orderCart"),
itemsToOrder,
itemsAvailable = document.querySelectorAll(".available"),
listDozen = `<div id="eggs12" class="orderListItem">
<div>${itemsAvailable[0].value}</div>
</div>`,
listOneTray = `<div id="oneTray" class="orderListItem">
<div>${itemsAvailable[1].value}</div>
</div>`,
listTwoTray = `<div id="twoTray" class="orderListItem">
<div>${itemsAvailable[2].value}</div>
</div>`,
listTwoLtrs = `<div id="twoLtrs" class="orderListItem">
<div>${itemsAvailable[3].value}</div>
</div>`,
listThreeLtrs = `<div id="threeLtrs" class="orderListItem">
<div>${itemsAvailable[4].value}</div>
</div>`,
listFourLtrs = `<div id="fourLtrs" class="orderListItem">
<div>${itemsAvailable[5].value}</div>
</div>`,
listVegGhiya = `<div id="vegGhiya" class="orderListItem">
<div title="You can edit this on WhatsApp screen">${itemsAvailable[6].value}</div>
</div>`,
listVegMint = `<div id="vegMint" class="orderListItem">
<div title="You can edit this on WhatsApp screen">${itemsAvailable[7].value}</div>
</div>`,
listVegDhania = `<div id="vegDhania" class="orderListItem">
<div title="You can edit this on WhatsApp screen">${itemsAvailable[8].value}</div>
</div>`,
listVegAloo = `<div id="vegAloo" class="orderListItem">
<div title="You can edit this on WhatsApp screen">${itemsAvailable[9].value}</div>
</div>`
listVegOnion = `<div id="vegOnion" class="orderListItem">
<div title="You can edit this on WhatsApp screen">${itemsAvailable[10].value}</div>
</div>`
listVegTomatoes = `<div id="vegTomato" class="orderListItem">
<div title="You can edit this on WhatsApp screen">${itemsAvailable[11].value}</div>
</div>`
listVegMirchi = `<div id="vegMirchi" class="orderListItem">
<div title="You can edit this on WhatsApp screen">${itemsAvailable[12].value}</div>
</div>`
itemsAvailable[0].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[0].classList.toggle('added')
dozen = document.getElementById("eggs12")
clickedItem.contains(dozen) ? clickedItem.removeChild(dozen) : clickedItem.insertAdjacentHTML('afterBegin', listDozen)
placeOrder()
})
itemsAvailable[1].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[1].classList.toggle('added')
oneTray = document.getElementById("oneTray")
clickedItem.contains(oneTray) ? clickedItem.removeChild(oneTray) : clickedItem.insertAdjacentHTML('afterBegin', listOneTray)
placeOrder()
})
itemsAvailable[2].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[2].classList.toggle('added')
twoTray = document.getElementById("twoTray")
clickedItem.contains(twoTray) ? clickedItem.removeChild(twoTray) : clickedItem.insertAdjacentHTML('afterBegin', listTwoTray)
placeOrder()
})
itemsAvailable[3].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[3].classList.toggle('added')
twoLtrs = document.getElementById("twoLtrs")
clickedItem.contains(twoLtrs) ? clickedItem.removeChild(twoLtrs) : clickedItem.insertAdjacentHTML('afterBegin', listTwoLtrs)
placeOrder()
})
itemsAvailable[4].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[4].classList.toggle('added')
threeLtrs = document.getElementById("threeLtrs")
clickedItem.contains(threeLtrs) ? clickedItem.removeChild(threeLtrs) : clickedItem.insertAdjacentHTML('afterBegin', listThreeLtrs)
placeOrder()
})
itemsAvailable[5].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[5].classList.toggle('added')
fourLtrs = document.getElementById("fourLtrs")
clickedItem.contains(fourLtrs) ? clickedItem.removeChild(fourLtrs) : clickedItem.insertAdjacentHTML('afterBegin', listFourLtrs)
placeOrder()
})
itemsAvailable[6].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[6].classList.toggle('added')
vegGhiya = document.getElementById("vegGhiya")
clickedItem.contains(vegGhiya) ? clickedItem.removeChild(vegGhiya) : clickedItem.insertAdjacentHTML('afterBegin', listVegGhiya)
placeOrder()
})
itemsAvailable[7].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[7].classList.toggle('added')
vegMint = document.getElementById("vegMint")
clickedItem.contains(vegMint) ? clickedItem.removeChild(vegMint) : clickedItem.insertAdjacentHTML('afterBegin', listVegMint)
placeOrder()
})
itemsAvailable[8].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[8].classList.toggle('added')
vegDhania = document.getElementById("vegDhania")
clickedItem.contains(vegDhania) ? clickedItem.removeChild(vegDhania) : clickedItem.insertAdjacentHTML('afterBegin', listVegDhania)
placeOrder()
})
itemsAvailable[9].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[9].classList.toggle('added')
vegAloo = document.getElementById("vegAloo")
clickedItem.contains(vegAloo) ? clickedItem.removeChild(vegAloo) : clickedItem.insertAdjacentHTML('afterBegin', listVegAloo)
placeOrder()
})
itemsAvailable[10].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[10].classList.toggle('added')
vegOnion = document.getElementById("vegOnion")
clickedItem.contains(vegOnion) ? clickedItem.removeChild(vegOnion) : clickedItem.insertAdjacentHTML('afterBegin', listVegOnion)
placeOrder()
})
itemsAvailable[11].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[11].classList.toggle('added')
vegTomato = document.getElementById("vegTomato")
clickedItem.contains(vegTomato) ? clickedItem.removeChild(vegTomato) : clickedItem.insertAdjacentHTML('afterBegin', listVegTomatoes)
placeOrder()
})
itemsAvailable[12].addEventListener('click', (e) => {
e.preventDefault()
orderCart.classList.remove('disabled')
itemsAvailable[12].classList.toggle('added')
vegMirchi = document.getElementById("vegMirchi")
clickedItem.contains(vegMirchi) ? clickedItem.removeChild(vegMirchi) : clickedItem.insertAdjacentHTML('afterBegin', listVegMirchi)
placeOrder()
})
//The Only Function that does the job for placing order
let placeOrder = () => {
enTxt = encodeURI(clickedItem.innerText)
document.getElementById("order").contains(document.getElementById("eggs12")) ||
document.getElementById("order").contains(document.getElementById("oneTray")) ||
document.getElementById("order").contains(document.getElementById("twoTray")) ||
document.getElementById("order").contains(document.getElementById("twoLtrs")) ||
document.getElementById("order").contains(document.getElementById("threeLtrs"))||
document.getElementById("order").contains(document.getElementById("fourLtrs")) ||
document.getElementById("order").contains(document.getElementById("vegGhiya")) ||
document.getElementById("order").contains(document.getElementById("vegMint")) ||
document.getElementById("order").contains(document.getElementById("vegDhania"))||
document.getElementById("order").contains(document.getElementById("vegAloo")) ||
document.getElementById("order").contains(document.getElementById("vegOnion")) ||
document.getElementById("order").contains(document.getElementById("vegTomato"))||
document.getElementById("order").contains(document.getElementById("vegMirchi"))?
orderCart.innerHTML = `<a href="https://wa.me/918683000497?text=${enTxt}">Kindly Deliver It</a>` : orderCart.innerText = "Cart Empty";
if (orderCart.innerText === "Cart Empty") {
orderCart.classList.add("disabled")
} else return
}