parent
203664e1ca
commit
3dcbeb9284
@ -0,0 +1,105 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<title>Title</title> |
||||
</head> |
||||
<body> |
||||
<table> |
||||
{% for category_name,category in categories.items %} |
||||
<tr> |
||||
<td colspan="2"> |
||||
<h3>{{ category_name }}</h3> |
||||
</td> |
||||
{% for type_name,type in category.items %} |
||||
<tr> |
||||
<td> |
||||
<label for="{{ type_name }}">{{ type_name }}[{{ type.price }}]:</label> |
||||
</td> |
||||
<td> |
||||
<select name="{{ type_name }}" id="{{ type_name }}" onchange="change(value, '{{ type_name }}')"> |
||||
{% for m in ms %} |
||||
<option value="{{ m }}">{{ m }}</option> |
||||
{% endfor %} |
||||
</select> |
||||
</td> |
||||
</tr> |
||||
{% endfor %} |
||||
|
||||
{% endfor %} |
||||
</table> |
||||
<h3 id="sum_h">0</h3> |
||||
<button onclick="confirm_choice()" id="confirm_button">Подтвердить</button> |
||||
</body> |
||||
<script> |
||||
function getCookie(name) { |
||||
let cookieValue = null; |
||||
if (document.cookie && document.cookie !== '') { |
||||
const cookies = document.cookie.split(';'); |
||||
for (let i = 0; i < cookies.length; i++) { |
||||
const cookie = cookies[i].trim(); |
||||
// Does this cookie string begin with the name we want? |
||||
if (cookie.substring(0, name.length + 1) === (name + '=')) { |
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return cookieValue; |
||||
} |
||||
|
||||
const csrftoken = getCookie('csrftoken'); |
||||
choice = {} |
||||
a = { |
||||
{% for category_name,category in categories.items %} |
||||
{% for type_name,type in category.items %} |
||||
"{{ type_name }}": { |
||||
{% for key,item in type.items%} |
||||
"{{ key }}": "{{ item }}", |
||||
{% endfor %} |
||||
}, |
||||
{% endfor %} |
||||
{% endfor %} |
||||
} |
||||
|
||||
function change(value, type) { |
||||
choice[type] = parseInt(value) |
||||
sum_price() |
||||
} |
||||
|
||||
function sum_price() { |
||||
s = 0 |
||||
for (let tea in choice) { |
||||
s += choice[tea] / 50 * parseInt(a[tea].price) |
||||
} |
||||
const butt = document.getElementById('confirm_button'); |
||||
const sum_h = document.getElementById('sum_h'); |
||||
sum_h.innerText = s |
||||
if (s > 7000) { |
||||
butt.disabled = true |
||||
sum_h.style.color = "red" |
||||
} else { |
||||
butt.disabled = false |
||||
sum_h.style.color = "black" |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
function confirm_choice() { |
||||
const request = new Request( |
||||
'confirm-choice', |
||||
{ |
||||
method: 'POST', |
||||
headers: {'X-CSRFToken': csrftoken}, |
||||
mode: 'same-origin', |
||||
body: JSON.stringify(choice) |
||||
} |
||||
); |
||||
fetch(request).then((response) => response.json()) |
||||
.then((data) => { |
||||
console.log(data); |
||||
}) |
||||
} |
||||
</script> |
||||
</html> |
||||
Loading…
Reference in new issue