-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProductrec.html
470 lines (410 loc) · 18.5 KB
/
Productrec.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<!-- Note from Aneesh: -->
<!-- Right now printing to Console (Ctrl-F console.log) -->
<!-- Can change this to instead print on a screen/store easily -->
<form id="survey-form" action="">
<div id = "container">
<h1 id="title">Product Finder</h1>
<div id="description">Answer the 4 questions below, and we will recommend a Mighty Well Product and blog posts just for you!</div>
<!-- ------------------Gender---------------------------- -->
<div class = "tab">
<h3 class= "number"> - 1 - </h3>
<h2 class = "question"> What is your gender? </h2><br>
<div class="inputContainer">
<p>
<span class = "radio"><input type="radio" name="gender" value="male" >Male<br></span>
<span class = "radio"><input type="radio" name="gender" value="female">Female<br></span>
<span class = "radio"><input type="radio" name="gender" value="other">Other</span>
</p>
</div>
</div>
<!-- ------------------Medical Condition-------------------------------- -->
<div class = "tab">
<h3 class = "number"> - 2 - </h3>
<h2 class = "question"> Select all that apply to you! </h2> <br>
<label class = "checkbox-label">
<p>
<ul>
<li><input type="checkbox" name="medcon" value="aplasticAnemia">Aplastic Anemia<br></li>
<li><input type="checkbox" name="medcon" value="behcets">Behcet's Syndrome<br></li>
<li><input type="checkbox" name="medcon" value="caps">CAPS<br></li>
<li><input type="checkbox" name="medcon" value="cysticFibrosis" >Cystic Fibrosis<br></li>
<li><input type="checkbox" name="medcon" value="diabetes" >Diabetes<br></li>
<li><input type="checkbox" name="medcon" value="dysautonomia">Dysautonomia<br></li>
<li><input type="checkbox" name="medcon" value="eds">Ehlers-Danlos Syndrome (EDS)<br></li>
<li><input type="checkbox" name="medcon" value="fibromyalgia">Fibromyalgia<br></li>
<li><input type="checkbox" name="medcon" value="gp" >Gastroparesis (GP)<br></li>
<li><input type="checkbox" name="medcon" value="hrt" >HRT<br></li>
<li><input type="checkbox" name="medcon" value="lyme" >Lyme Disease<br></li>
<li><input type="checkbox" name="medcon" value="marfan" >Marfan Syndrome<br></li>
<li><input type="checkbox" name="medcon" value="mcas" >MCAS<br></li>
<li><input type="checkbox" name="medcon" value="osteomyelitis">Osteomyelitis<br></li>
<!--<li><input type="checkbox" name="medcon" value="partialEmptySella">Partial Empty Sella<br></li>-->
<li><input type="checkbox" name="medcon" value="polyarthralgia">Polyarthralgia<br></li>
<li><input type="checkbox" name="medcon" value="pcos" >Polycystic Ovary Syndrome (PCOS)<br></li>
<li><input type="checkbox" name="medcon" value="pots" >Postural Orthostatic Tachycardia Syndrome (POTS)<br></li>
<!-- <li><input type="checkbox" name="medcon" value="thyroidcancer" >Thyroid Cancer<br></li> -->
<li><input type="checkbox" name="medcon" value="uc" >Ulcerative Colitis (UC)<br></li>
<li><input type="checkbox" name="medcon" value="other" >Other<br></li>
</ul>
</p>
</label>
</div>
<!-- ------------------Medical Devices-------------------------------- -->
<div class="tab">
<h3 class="number"> - 3 - </h3>
<h2 class="question"> What medical devices do you use?</h2><br>
<label class = "checkbox-label">
<span class="checkbox-custom">
<p>
<ul>
<!--<input type="checkbox" name="meddev" value="diabeticPumps">Diabetic Pumps<br>-->
<li><input type="checkbox" name="meddev" value="EpiPen (Allergies)">EpiPen<br></li>
<li><input type="checkbox" name="meddev" value="Diabetic Supplies">Diabetic Supplies<br></li>
<!--input <input type="checkbox" name="meddev" value="hickmanLines">Hickman Lines (CVCs)<br> -->
<!-- <input type="checkbox" name="meddev" value="inhalers">Inhalers<br> -->
<li><input type="checkbox" name="meddev" value="Mastectomy Drains">Mastectomy Drains<br></li>
<li><input type="checkbox" name="meddev" value="midlines">Midlines<br></li>
<li> <input type="checkbox" name="meddev" value="Peripheral I.V.s">Peripheral IVs<br></li>
<li><input type="checkbox" name="meddev" value="PICC Lines">PICC Lines<br></li>
<li><input type="checkbox" name="meddev" value="pills and Other Medications">Pills and Other Medications<br></li>
<li><input type="checkbox" name="meddev" value="Port">Port<br></li>
<!-- <input type="checkbox" name="meddev" value="vitamins">Vitamins<br> -->
<li><input type="checkbox" name="meddev" value="Wheelchairs/Mobility Aids">Wheelchairs/Mobility Aids<br></li>
<li><input type="checkbox" name="meddev" value="other">Other<br></li>
</ul>
</p>
</span>
</label>
</div>
<!-- -----------------Use Case--------------------------------- -->
<div class="tab">
<h3 class="number"> - 4 - </h3>
<h2 class="question"> What are you looking to use Mighty Well products for? </h2><br>
<label class = "checkbox-label">
<span class="checkbox-custom">
<p>
<ul>
<li><input type="checkbox" name="usecase" value="antibioticInfusion">Antibiotic Infusion<br></li>
<li><input type="checkbox" name="usecase" value="chemotherapy">Chemotherapy<br></li>
<li><input type="checkbox" name="usecase" value="glucoseMonitoring">Glucose Monitoring<br></li>
<li><input type="checkbox" name="usecase" value="holdMedicalSupplies">Hold Medical Supplies/Items<br></li>
<li><input type="checkbox" name="usecase" value="IVInfusion">IV Infusion<br></li>
<li><input type="checkbox" name="usecase" value="lookingGood">Looking Good/Feeling Proud!<br></li>
<li><input type="checkbox" name="usecase" value="organizeMedications">Organize Medications<br></li>
<li><input type="checkbox" name="usecase" value="raisingAwareness">Raising Awareness<br></li>
<li><input type="checkbox" name="usecase" value="salineTreatment">Saline Treatment<br></li>
<li><input type="checkbox" name="usecase" value="subcutaneousInjection">Subcutaneous Injection<br></li>
<li><input type="checkbox" name="usecase" value="TPNInjection">TPN Injection<br></li>
<li><input type="checkbox" name="usecase" value="transfusion">Transfusion<br></li>
<li><input type="checkbox" name="usecase" value="tubeFeeding">Tube Feeding<br></li>
<li><input type="checkbox" name="usecase" value="other">Other<br></li>
</ul>
</p>
</span>
</label>
</div>
<div class="tab" id="productRecContainer">
<h1>Your Results!</h1>
<h3>Enjoy these Mighty Well products and specially curated blog posts just for you!</h3>
<a href="" class = "productLink">
<h2 id="productName" style="float: left;"> Product Name </h2><br>
<img src="https://bit.ly/2SEVDwz" id= "productPicture" alt = "Product Picture">
</a>
<a href = "" class="blogLink">
<h2 id="blogName" style="float: right;"></h2><br>
<img src="" id="blogPicture" alt = "blog Picture" style="float: right;">
</a>
</div>
<div style="overflow:auto;">
<div style = "float:left;"></div>
<p id="demo"></p>
<div style = "text-align: center;">
<button class ="formBtn" type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button>
<button class ="formBtn" type="button" id="nextBtn" onclick="nextPrev(1)">Next</button>
<button class ="formBtn" type="button" id="startOverBtn" onclick="location.reload()">Start Over</button>
<button class = "formBtn" type="submit" id="finalsub" onclick="nextPrev(1)" form="survey-form" value="Submit">Get Your Results!</button>
</div>
</div>
<!-- Circles which indicates the steps of the form: -->
<div style="text-align:center;margin-top:40px;">
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
<span class="step"></span>
</div>
</div>
</form>
<style>
ul {
columns: 300px;
list-style: none;
}
p{
margin:0 10px 0 10px;
display: inline-block;
text-align:left;
}
#regForm {
background-color: #ffffff;
margin: 100px auto;
padding: 40px;
width: 70%;
min-width: 300px;
}
#container{
background-color:#edf9fc;
padding:100px;
}
#title{
margin-left:auto;
margin-right:auto;
text-align: center;
font-size:35px;
}
#description {
text-align: center;
padding:10px;
max-width:400px;
margin-left:auto;
margin-right:auto;
font: Lato;
font-size: 14px;
color: grey;
}
#productRecContainer{
background-color:#ffffff;
padding:100px;
}
#productPicture{
padding: 20px;
max-width: 40%;
height: auto;
}
.radio{
background-color: white;
padding: 7px;
}
ul.checkbox {
margin-left: auto;
background-color: color;
margin-right:auto;
list-style: none;
}
li{
background-color: white;
padding: 7px;
}
ul.checkbox li {
border: 1px black;
float: left;
min-width: 400px;
}
.number {
text-align: center;
}
.question{
text-align: center;
padding-top: 10px;
}
.inputContainer{
text-align : center;
}
.formBtn{
width: 10em;
height: 2.2em;
text-align: center;
color: white;
text-align:center;
background-color: black;
}
/* Style the input fields */
input {
text-align: center;
font-size: 17px;
font-family: Raleway;
padding-bottom: 20px;
}
/* Mark input boxes that gets an error on validation: */
input.invalid {
background-color: #ffdddd;
}
/* Hide all steps by default: */
.tab {
display: none;
}
/* Make circles that indicate the steps of the form: */
.step {
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbbbbb;
border: none;
border-radius: 50%;
display: inline-block;
opacity: 0.5;
}
/* Mark the active step: */
.step.active {
opacity: 1;
}
/* Mark the steps that are finished and valid: */
.step.finish {
background-color: #4CAF50;
}
</style>
<!------------------SCRIPT---------------------------->
<script>
const CATALOG ={
"PICC Perfect": ["https://mighty-well.com/products/picc-line-cover-piccperfect-mighty-well?_pos=5&_sid=db99fc554&_ss=r", "https://blog.mighty-well.com/2017/07/adapting-to-the-picc-life/"],
"Med Planner": ["https://mighty-well.com/collections/all/products/mighty-medplanner-medical-organizer","https://blog.mighty-well.com/2019/06/trying-out-the-mighty-medplanner-your-new-medical-organizer/"],
"Mighty Pack": ["https://mighty-well.com/collections/all/products/medical-iv-infusion-backpack-for-patients","https://blog.mighty-well.com/2018/12/travel-without-worries-with-the-mighty-pack-the-best-backpack-for-friends-in-the-fight/"],
"Mighty Wrap": ["https://mighty-well.com/collections/all/products/the-mighty-jacket","https://blog.mighty-well.com/2017/06/learning-to-love-your-tube/"],
"Undefeated Wear":["https://mighty-well.com/collections/all/products/undefeated-t-shirt-heather-gray","https://blog.mighty-well.com/2019/11/mighty-well-fall-photoshoot/"]
}
const scriptURL = "https://script.google.com/macros/s/AKfycbxx4_QDeXS7AqXlU9WkYvDTvdY_dYHUMbZ-YdQK4SslU54ihug/exec"
const form = document.forms[0]
const proxyurl = "https://cors-anywhere.herokuapp.com/";
form.addEventListener("submit", e => {
e.preventDefault()
fetch(scriptURL, {
method: "POST",
body: new FormData(form)
})
.then(response => console.log("Success!", response))
.catch(error => console.error("Error!", error.message))
})
var currentTab = 0; // Current tab is set to be the first tab (0)
var productRec = "";
var productImg = "";
showTab(currentTab); // Display the current tab
function showTab(n) {
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if(n == x.length-1){
document.getElementById("prevBtn").style.display = "none";
document.getElementById("nextBtn").style.display = "none";
document.getElementById("finalsub").style.display = "none";
document.getElementById("startOverBtn").style.display="inline";
}
else{
document.getElementById("startOverBtn").style.display="none";
if (n == 0) {
document.getElementById("prevBtn").style.display = "none";
} else {
document.getElementById("prevBtn").style.display = "inline";
}
if (n == (x.length - 2)) {
document.getElementById("finalsub").style.display = "inline";
document.getElementById("nextBtn").style.display = "none";
} else {
document.getElementById("nextBtn").style.display = "inline";
document.getElementById("finalsub").style.display = "none";
}}
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
}
function nextPrev(n) {
// This function will figure out which tab to display
var x = document.getElementsByClassName("tab");
// Exit the function if any field in the current tab is invalid:
if (n == 1 && !validateForm()) return false;
// Hide the current tab:
x[currentTab].style.display = "none";
// Increase or decrease the current tab by 1:
currentTab = currentTab + n;
// if you have reached the end of the form... :
if (currentTab >= x.length) {
//...the form gets submitted:
document.getElementById("demo").innerHTML = "check";
//document.getElementById("survey-form").submit();
return false;
}
if(currentTab>=x.length-2){ // Last question page
//document.getElementById("nextBtn").onclick = function() {calculateProduct();}
//const result = await calculateProduct();
getProductInfo();
}
// Otherwise, display the correct tab:
showTab(currentTab);
}
function validateForm() {
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
if (valid) {
document.getElementsByClassName("step")[currentTab].className += " finish";
}
return valid; // return the valid status
}
function fixStepIndicator(n) {
// This function removes the "active" class of all steps...
var i, x = document.getElementsByClassName("step");
for (i = 0; i < x.length+1; i++) {
x[i].className = x[i].className.replace(" active", "");
}
//... and adds the "active" class to the current step:
x[n].className += " active";
}
function calculateProduct() {
var deviceChecks = document.getElementsByName("meddev");
var deviceUsed;
for (i = 0; i < deviceChecks.length; i++) {
// If a field is empty...
if (deviceChecks[i].checked) {
deviceUsed = deviceChecks[i].value;
console.log("Device used:" + deviceUsed);
// document.getElementById("demo").innerHTML = "Device used: " + deviceUsed;
}
}
// https://api.jsonbin.io/b/5eb23bd48284f36af7b645fc
let req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (req.readyState == XMLHttpRequest.DONE) {
var jsonData = JSON.parse(req.responseText);
console.log("Recommended devices: "+ jsonData[deviceUsed])
console.log("All jSON Data: " + req.responseText);
productRec = jsonData[deviceUsed];
}
};
req.open("GET", "https://api.jsonbin.io/b/5eb23bd48284f36af7b645fc/1", true);
req.send();
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
function getImgURL(url){
var urls = [];
$.get(proxyurl+url, function(data) {
var imgs = $('<div class= "product-single__photos" style="user-select: auto;">').html(data).find('img');
imgs.each(function(i, img) {
//alert(img.src);
//console.log(img.src);
urls.push(img.src);
});
productImg = urls[3];
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});});}
async function getProductInfo(){
await calculateProduct();
//console.log(result);
let productURLs = CATALOG[productRec];
await getImgURL(productURLs[0]);
//class="product-single__photo product-single__photo"
//let productName =productURLs[0]; // TODO: take url and extract name text referring to product name
//console.log(productName);
// let productPicture =productURLs[0]; // TODO: take url and extract src referring to product photo
// let blogName = productURLs[1]; // TODO: take url and extract name text referring to blog name
//let blogPicture = productURLs[1]; // TODO: take url and extract src referring to blog photo
//document.querySelectorAll("productLink").setAttribute("href", recProduct[0]);
//document.getElementById("productName").innerText = productName;
//document.getElementById("productPicture").setAttribute("src", productPicture);
}
</script>