-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.js
117 lines (98 loc) · 3.32 KB
/
new.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
'use strict';
var form = document.getElementById('add_restaurant');
var cuisineType1 = document.getElementById('cuisine1');
var cuisineType2 = document.getElementById('cuisine2');
var cuisineType3 = document.getElementById('cuisine3');
var autocomplete;
function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
{types: ['establishment']});
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
var place = autocomplete.getPlace();
console.dir(place);
document.getElementById('rest_name').value = place.name;
document.getElementById('rest_addy').value = place.formatted_address;
document.getElementById('rest_phone').value = place.formatted_phone_number;
}
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
function handleAddRest(event) {
event.preventDefault();
var cuisinesArray = [];
console.log(event);
console.log('this is a string');
var newName = event.target.rest_name.value;
var newAddress = event.target.rest_addy.value;
var newPhone = event.target.rest_phone.value;
var newVegan = event.target.vegan_check.checked;
var addType1 = event.target.cuisine1.value;
var addType2 = event.target.cuisine2.value;
var addType3 = event.target.cuisine3.value;
var newType = event.target.new_cuisine.value;
if(!checkVsFoodTypes(newType) && newType !== '') {
cuisinesArray.push(newType);
};
if(addType2 === addType1) {
if(addType1 && addType1 !== 'Add a kind of food') {
cuisinesArray.push(addType1);
};
} else {
if(addType1 && addType1 !== 'Add a kind of food') {
cuisinesArray.push(addType1);
}
if(addType2 && addType2 !== 'Add a kind of food'){
cuisinesArray.push(addType2);
}
}
if(addType3 !== addType1 && addType3 !== addType2) {
if(addType3 && addType3 !== 'Add a kind of food') {
cuisinesArray.push(addType3);
}
}
cuisinesArray.sort();
console.log('cuisinesArray', cuisinesArray);
if(cuisinesArray.length < 1) {
alert('Add at least one food type, you lazy bum!');
} else {
addNewRest(newName, newAddress, newPhone, cuisinesArray, newVegan, 'img/delicious.jpg');
window.location.href = 'location.html';
}
};
//Build food type dropdowns
var populateTypeList = function(target) {
typesOfFood.sort();
for(var i = 0; i < typesOfFood.length; i++) {
buildNewElement('option', typesOfFood[i], target, 'value', typesOfFood[i]);
}
};
// Check if a type of food is already in the typesOfFood array
var checkVsFoodTypes = function(input) {
for(var i = 0; i < typesOfFood.length; i++) {
if(typesOfFood[i] === input.toLowerCase()) {
return true;
}
}
return false;
};
form.addEventListener('submit', handleAddRest);
populateTypeList(cuisineType1);
populateTypeList(cuisineType2);
populateTypeList(cuisineType3);