forked from kjonathante/whattoeat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.html
176 lines (159 loc) · 7.32 KB
/
input.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
<!DOCTYPE html>
<html>
<head>
<title>Input</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
</head>
<body>
<div id="input-div">
<div class="container">
<form id="inputForm">
<h1>What Do You Wanna Eat?!</h1>
<div id="nameInputDiv">
<input id="inputFirstNameInput" type="text" placeholder="First Name">
<input id="inputLastNameInput" type="text" placeholder="Last Name">
</div>
<!-- <br> -->
<!-- <input type="email" placeholder="Email" id="email">
<input type="password" placeholder="Password" id="ps"><br> -->
<!-- <p>Are you diabetic?</p>
<input type="radio" value="yes"> Yes
<input type="radio" value="no"> No -->
<div id="proteinDiv">
<h2>Prefer Proteins:</h2>
<input type="checkbox" id="protein1" class="meats" value="Beef"> Beef
<input type="checkbox" id="protein2" class="meats" value="Chicken"> Chicken
<input type="checkbox" id="protein3" class="meats" value="Fish"> Fish
<input type="checkbox" id="protein4" class="meats" value="Shellfish">Shellfish <br>
</div>
<div id="vegPref">
<h2>Prefer Vegan/Vegetarian:</h2>
<input type="checkbox" id="protein5" class="veg" value="Tofu"> Tofu
<input type="checkbox" id="protein6" class="veg" value="Eggs"> Eggs
<input type="checkbox" id="protein7" class="veg" value="Lentil"> Lentils
<input type="checkbox" id="protein8" class="veg" value="Tempeh"> Tempeh
</div>
<div id="dietRestrictions">
<h2>Dietary Restrictions:</h2>
<div id="inputContainer">
<div class="inputBox">
<input type="checkbox" id="restriction1" class="restrictions" value="dairy-free">
<label for="restriction1">Dairy-free</label>
<input type="checkbox" id="restriction2" class="restrictions" value="peanut-free">
<label for="restriction2">Peanut-free</label>
<input type="checkbox" id="restriction3" class="restrictions" value="wheat-free">
<label for="restriction3">Wheat-free</label>
<input type="checkbox" id="restriction4" class="restrictions" value="soy-free">
<label for="restriction4">Soy-free</label>
</div>
<div class="inputBox">
<input type="checkbox" id="restriction5" class="restrictions" value="fish-free">
<label for="restriction5">Fish-free</label>
<input type="checkbox" id="restriction6" class="restrictions" value="shellfish-free">
<label for="restriction6">Shellfish-free</label>
<input type="checkbox" id="restriction7" class="restrictions" value="tree-nut-free">
<label for="restriction7">Tree-Nut-free</label>
<input type="checkbox" id="restriction8" class="restrictions" value="gluten-free">
<label for="restriction8">Gluten-free</label>
</div>
<div class="inputBox">
<input type="checkbox" id="restriction9" class="restrictions" value="egg-free">
<label for="restriction9">Egg-free</label>
<input type="checkbox" id="restriction10" class="restrictions" value="fat-free">
<label for="restriction10">Fat-free</label>
<input type="checkbox" id="restriction11" class="restrictions" value="low-sugar">
<label for="restriction11">Low-sugar</label>
</div>
</div>
</div>
<div>
<button class="decideButtons" id="input-submit-btn" type="submit">Submit</button>
<button class="decideButtons" id="input-cancel-btn" type="cancel">Cancel</button>
</div>
<!-- <input type="reset" value="Reset"> -->
</form>
</div>
</div>
<script src="https://www.gstatic.com/firebasejs/5.2.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyCeEfjqDlvTZ9eHxtgANgsdAdPby1opHs0",
authDomain: "what-do-you-wanna-eat.firebaseapp.com",
databaseURL: "https://what-do-you-wanna-eat.firebaseio.com",
projectId: "what-do-you-wanna-eat",
storageBucket: "",
messagingSenderId: "746879320609"
};
firebase.initializeApp(config);
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$("#inputSubmitBtn").on("click", function () {
event.preventDefault();
var fn = $("#inputFirstNameInput").val();
var ln = $("#inputLastNameInput").val();
var meatArray = [];
$(".meats:checked").each(function() {
meatArray.push($(this).val());
});
var vegArray = [];
$(".veg:checked").each(function() {
vegArray.push($(this).val());
});
var restrictionsArray = [];
$(".restrictions:checked").each(function() {
restrictionsArray.push($(this).val());
});
console.log(fn, ln, meatArray, vegArray, restrictionsArray);
var db = firebase.database();
db.ref("x").push({
firstName: fn,
lastName: ln,
meat: meatArray,
veg: vegArray,
restrictions: restrictionsArray
})
db.ref("y/z").set({
firstName: fn,
lastName: ln,
meat: meatArray,
veg: vegArray,
restrictions: restrictionsArray
})
});
$("#inputCancelBtn").on("click", function () { //reset btn
event.preventDefault();
var fn = $("#firstName").val("");
var ln = $("#lastName").val("");
var db = firebase.database();
console.log('hello');
var ref = db.ref("y").orderByKey().equalTo("z");
ref.once("value")
.then (function(snap){
console.log(snap.val());
var obj = snap.val();
console.log(obj.z.restrictions);
})
});
function searchEdemam(food, count=2) {
var appId = '94109746';
var appKey = '987f9b2768860ef9a7e37737bb3ced9f';
var endPoint = 'https://api.edamam.com/search';
var param = $.param({
q: food,
healthLabels: "",
to: count,
app_id: appId,
app_key: appKey
});
$.ajax({
url: endPoint + '?' + param,
})
.then(function(res){
console.log(res);
});
};
</script>
</body>
</html>