-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
101 lines (93 loc) · 2.76 KB
/
script.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
const searchRestaurant = document.querySelector('#searchrestaurant')
if (searchRestaurant) {
searchRestaurant.addEventListener('input', async function() {
const response = await fetch('../Api/restaurants.api.php?search=' + escapeHtml(this.value))
const restaurants = await response.json()
const section = document.querySelector('#restaurants')
section.innerHTML = ''
for (const restaurant of restaurants) {
const article = document.createElement('article')
const img = document.createElement('img')
img.src = restaurant.image
const link = document.createElement('a')
link.href = '../Pages/restaurant.php?id=' + restaurant.id
link.textContent = restaurant.name
article.appendChild(img)
article.appendChild(link)
section.appendChild(article)
}
})
}
const entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
"'": ''',
"/": '/'
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function(s) {
return entityMap[s];
});
}
function refresh() {
window.location.href = "refresh.php";
}
function deleteOrder(r, order) {
var i = r.parentNode.parentNode.rowIndex
document.getElementById("ordersTable").deleteRow(i)
$.ajax({
url: "../Api/removeOrder.api.php",
type: "POST",
data: {
order: order
},
cache: false,
success: function(response) {
console.log(response)
}
});
refresh()
}
function addOrder(restaurant, dish) {
var quantity = $('#quantity').val()
$.ajax({
url: "../Api/addOrders.api.php",
type: "POST",
data: {
quantity: quantity,
restaurant: restaurant,
dish: dish
},
cache: false,
success: function(response) {
console.log(response)
}
});
refresh()
}
$(document).ready(function() {
$('#submitReview').on('click', function() {
$("#submitReview").attr("disabled", "disabled")
var score = $('#score').val()
var comment = $('#reviewText').val()
var url = escapeHtml(window.location.search);
var restaurantid = url.substring(url.lastIndexOf('/') + 5)
$.ajax({
url: "../Api/saveReview.api.php",
type: "POST",
data: {
score: score,
comment: comment,
restaurantid: restaurantid
},
cache: false,
success: function(response) {
console.log(response)
}
});
refresh()
//$("#userReview").load(location.href + " p");
});
});