-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributor.html
222 lines (215 loc) · 7.57 KB
/
distributor.html
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Restaurant Admin</title>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<style>
#addRestaurant {
position: absolute;
top: 50px;
left: 300px;
}
input {
width: 200px;
height: 30px;
border-radius: 10px;
border: 1px solid #483434;
text-align: justify;
padding: 0 20px;
margin: 10px;
overflow: hidden;
}
button {
margin: 20px 100px;
}
#food {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
}
#food label {
width: 100px;
}
</style>
<body>
<ul>
<li><a class="active" href="#">Restaurant Admin</a></li>
<li><a href="./index.html">Logout</a></li>
</ul>
<div id="addRestaurant" style="margin-left: 5%; padding: 1px 16px">
<form autocomplete="off">
<div id="form">
<div id="food">
<label class="form-label" for="resLoc">Restaurant Location</label>
<input
style="width: 300px"
id="resLoc"
list="locList"
placeholder="Location"
/>
<datalist id="locList"> </datalist>
</div>
<div id="food">
<label class="form-label" for="resName">Restaurant Name</label>
<input
style="width: 300px"
id="resName"
list="rList"
placeholder="Restuarant Name"
/>
<datalist id="rList"></datalist>
</div>
<div id="food">
<label class="form-label" for="item1">Item 1</label>
<input type="text" id="item1" placeholder="Item 1" />
<label class="form-label" for="item1Url">Image URL</label>
<input type="url" id="item1Url" placeholder="URL" />
<input type="number" id="price1" placeholder="Price per item/1Kg" />
</div>
<div id="food">
<label class="form-label" for="item2">Item 2</label>
<input type="text" id="item2" placeholder="Item 2" />
<label class="form-label" for="item2Url">Image URL</label>
<input type="url" id="item2Url" placeholder="URL" />
<input type="number" id="price2" placeholder="Price per item/1Kg" />
</div>
<div id="food">
<label class="form-label" for="item3">Item 3</label>
<input type="text" id="item3" placeholder="Item 3" />
<label class="form-label" for="item3Url">Image URL</label>
<input type="url" id="item3Url" placeholder="URL" />
<input type="number" id="price3" placeholder="Price per item/1Kg" />
</div>
<div id="food">
<label class="form-label" for="item4">Item 4</label>
<input type="text" id="item4" placeholder="Item 4" />
<label class="form-label" for="item4Url">Image URL</label>
<input type="url" id="item4Url" placeholder="URL" />
<input type="number" id="price4" placeholder="Price per item/1Kg" />
</div>
<div id="btn">
<button id="addBtn" class="btn-dark" type="button">ADD</button>
<button type="reset" class="btn-dark">Reset</button>
</div>
<p>Note: set zero to empty field</p>
</div>
</form>
</div>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script>
jQuery(function () {
for (i = 0; i < localStorage.length; i++) {
$("#locList").append(`<option value="${localStorage.key(i)}">`);
}
$("#resName").on({
blur: function () {
checkResName();
},
focus: function () {
$("#rList").html("");
let resNameValue = $("#resLoc").val().toLowerCase();
let resList = JSON.parse(localStorage.getItem(resNameValue));
for (i = 0; i < resList.length; i++) {
$("#rList").append(`<option value="${resList[i].resName}">`);
}
},
});
$("#resLoc").on("blur", function () {
checkLoc();
});
$("#addBtn").click(function () {
let item1 = $("#item1");
let item1url = $("#item1Url");
let price1 = $("#price1");
let resIndex;
let resName = $("#resName").val().toLowerCase();
let resLocation = $("#resLoc").val().toLowerCase();
let resDetails = JSON.parse(localStorage.getItem(resLocation));
checkResName();
checkLoc();
if (checkLoc() == true && checkResName() == true) {
for (let i = 0; i < resDetails.length; i++) {
if (resName == resDetails[i].resName) {
resIndex = i;
}
}
resDetails[resIndex] = {
resName: resDetails[resIndex].resName,
contractFrom: resDetails[resIndex].contractFrom,
contractTo: resDetails[resIndex].contractTo,
item1: {
item: $("#item1").val(),
url: $("#item1Url").val(),
price: $("#price1").val(),
},
item2: {
item: $("#item2").val(),
url: $("#item2Url").val(),
price: $("#price2").val(),
},
item3: {
item: $("#item3").val(),
url: $("#item3Url").val(),
price: $("#price3").val(),
},
item4: {
item: $("#item4").val(),
url: $("#item4Url").val(),
price: $("#price4").val(),
},
};
localStorage.setItem(resLocation, JSON.stringify(resDetails));
alert("Restaurant Added");
}
});
function checkResName() {
let flag = 0;
let resName = $("#resName").val().toLowerCase();
let resLoc = $("#resLoc").val().toLowerCase();
let resList = JSON.parse(localStorage.getItem(resLoc));
for (i = 0; i < resList.length; i++) {
if (resName == resList[i].resName) {
flag = 1;
}
}
if (flag == 0) {
alert("Select Restaurant from List");
return false;
} else return true;
}
function checkLoc() {
let flag;
for (i = 0; i < localStorage.length; i++) {
if ($("#resLoc").val() == localStorage.key(i))
flag = localStorage.key(i);
}
if (flag == null || $("#resLoc").val() == null) {
alert("Select Location from List");
return false;
} else return true;
}
});
</script>
</body>
</html>