-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oibek Khashimov
committed
Feb 7, 2024
1 parent
9bcf60d
commit 5c2f9b2
Showing
2 changed files
with
216 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,191 +1,189 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script> | ||
<script src="https://telegram.org/js/telegram-web-app.js"></script> | ||
<script src="https://unpkg.com/@dotlottie/player-component@latest/dist/dotlottie-player.mjs" type="module"></script> | ||
<script src="./js/dropDowns.js"></script> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="stylesheet" type="text/css" href="./styles.css" /> | ||
</head> | ||
<script> | ||
$(document).ready(function () { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
const chatId = searchParams.get("chatId"); | ||
|
||
const dropdownButton = $('.select-button') | ||
const dropdownMenu = $('.select-options') | ||
const dropdownInput = $('.hidden-input') | ||
|
||
dropdownButton.on('click', function () { | ||
dropdownMenu.toggleClass('select-options-visible'); | ||
$(this).toggleClass('dropdown__button_active'); | ||
}); | ||
|
||
// $(document).on('click', function (e) { | ||
// if ( e.target !== dropdownButton ){ | ||
// dropdownButton.classList.remove('dropdown__button_active'); | ||
// dropdownMenu.classList.remove('dropdown__list_visible'); | ||
// } | ||
// }) | ||
|
||
$(document).on('keydown', function (e) { | ||
if( e.key === 'Tab' || e.key === 'Escape' ) { | ||
dropdownButton.removeClass('dropdown__button_active'); | ||
dropdownMenu.removeClass('select-options-visible'); | ||
} | ||
}) | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script> | ||
<script src="https://telegram.org/js/telegram-web-app.js"></script> | ||
<script src="https://unpkg.com/@dotlottie/player-component@latest/dist/dotlottie-player.mjs" type="module"></script> | ||
<script src="./js/dropDowns.js"></script> | ||
|
||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="stylesheet" type="text/css" href="./styles.css" /> | ||
</head> | ||
<script> | ||
$(document).ready(function () { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
const chatId = searchParams.get("chatId"); | ||
|
||
const dropdownButton = $('.select-button') | ||
const dropdownMenu = $('.select-options') | ||
const dropdownInput = $('.hidden-input') | ||
|
||
dropdownButton.on('click', function () { | ||
dropdownMenu.toggleClass('select-options-visible'); | ||
$(this).toggleClass('dropdown__button_active'); | ||
}); | ||
|
||
fetch(`https://spendbook.ru/categories?chatId=${chatId}`) | ||
.then((response) => response.json()) | ||
.then((userCategories) => { | ||
const categoriesFiltered = categories.filter( | ||
(c) => !userCategories.includes(c) | ||
); | ||
const finalCategories = userCategories.concat(categoriesFiltered); | ||
$.each(finalCategories, function (key, str) { | ||
// $("#category").append(`<option value="${str}">${str}</option>`); | ||
$('#custom-dropdown').append(`<li class="select-option" data-value="${str}">${str}</li>`) | ||
}); | ||
}) | ||
.catch((error) => { | ||
$.each(categories, function (key, str) { | ||
// $("#category").append(`<option value="${str}">${str}</option>`); | ||
$('#custom-dropdown').append(`<li class="select-option" data-value="${str}">${str}</li>`) | ||
}) | ||
// $(document).on('click', function (e) { | ||
// if ( e.target !== dropdownButton ){ | ||
// dropdownButton.classList.remove('dropdown__button_active'); | ||
// dropdownMenu.classList.remove('dropdown__list_visible'); | ||
// } | ||
// }) | ||
|
||
$(document).on('keydown', function (e) { | ||
if (e.key === 'Tab' || e.key === 'Escape') { | ||
dropdownButton.removeClass('dropdown__button_active'); | ||
dropdownMenu.removeClass('select-options-visible'); | ||
} | ||
}) | ||
|
||
fetch(`https://spendbook.ru/categories?chatId=${chatId}`) | ||
.then((response) => response.json()) | ||
.then((userCategories) => { | ||
const categoriesFiltered = categories.filter( | ||
(c) => !userCategories.includes(c) | ||
); | ||
const finalCategories = userCategories.concat(categoriesFiltered); | ||
$.each(finalCategories, function (key, str) { | ||
// $("#category").append(`<option value="${str}">${str}</option>`); | ||
$('#custom-dropdown').append(`<li class="select-option" data-value="${str}">${str}</li>`) | ||
}); | ||
|
||
$(document).on('click', '.select-option', function() { | ||
$('.select-options .select-option').each(function (){ | ||
if ($(this).hasClass('selected')) { | ||
$(this).removeClass('selected') | ||
} | ||
}) | ||
.catch((error) => { | ||
$.each(categories, function (key, str) { | ||
// $("#category").append(`<option value="${str}">${str}</option>`); | ||
$('#custom-dropdown').append(`<li class="select-option" data-value="${str}">${str}</li>`) | ||
}) | ||
|
||
$(this).addClass('selected') | ||
dropdownButton.html($(this).text()) | ||
dropdownInput.val($(this).attr('data-value')) | ||
dropdownMenu.removeClass('select-options-visible') | ||
|
||
if (dropdownInput.val() === categories[categories.length-1]) { | ||
$(".custom-category").show(); | ||
// $("#custom_input").show(); | ||
} else { | ||
$(".custom-category").hide(); | ||
// $("#custom_input").hide(); | ||
} | ||
|
||
collectData() | ||
}); | ||
|
||
function collectData() { | ||
var category = $(".hidden-input").val(); | ||
if (category === categories[categories.length-1]) { | ||
category = $("#custom_input").val(); | ||
$(document).on('click', '.select-option', function () { | ||
$('.select-options .select-option').each(function () { | ||
if ($(this).hasClass('selected')) { | ||
$(this).removeClass('selected') | ||
} | ||
const rawAmountValue = parseInt($("#amount").val(), 10); | ||
const absAmountValue = Math.abs(rawAmountValue) | ||
$("#amount").val(absAmountValue); | ||
const data = { | ||
category: category, | ||
amount: absAmountValue, | ||
description: $("#text").val(), | ||
date: $("#date_input").val(), | ||
timeOffset: new Date().getTimezoneOffset(), | ||
}; | ||
Object.keys(data).forEach( | ||
(key) => | ||
(data[key] = | ||
data[key] === "any" || data[key] === "" ? null : data[key]) | ||
); | ||
if (data.category && data.amount) { | ||
enableSubmit(true); | ||
} else { | ||
enableSubmit(false); | ||
} | ||
return data; | ||
}) | ||
|
||
$(this).addClass('selected') | ||
dropdownButton.html($(this).text()) | ||
dropdownInput.val($(this).attr('data-value')) | ||
dropdownMenu.removeClass('select-options-visible') | ||
|
||
if (dropdownInput.val() === categories[categories.length - 1]) { | ||
$(".custom-category").show(); | ||
// $("#custom_input").show(); | ||
} else { | ||
$(".custom-category").hide(); | ||
// $("#custom_input").hide(); | ||
} | ||
|
||
function formatDate(date) { | ||
var d = new Date(date), | ||
collectData() | ||
}); | ||
|
||
function collectData() { | ||
var category = $(".hidden-input").val(); | ||
if (category === categories[categories.length - 1]) { | ||
category = $("#custom_input").val(); | ||
} | ||
const rawAmountValue = parseInt($("#amount").val(), 10); | ||
const absAmountValue = Math.abs(rawAmountValue) | ||
$("#amount").val(absAmountValue); | ||
const data = { | ||
category: category, | ||
amount: absAmountValue, | ||
description: $("#text").val(), | ||
date: $("#date_input").val(), | ||
timeOffset: new Date().getTimezoneOffset(), | ||
}; | ||
Object.keys(data).forEach( | ||
(key) => | ||
(data[key] = | ||
data[key] === "any" || data[key] === "" ? null : data[key]) | ||
); | ||
if (data.category && data.amount) { | ||
enableSubmit(true); | ||
} else { | ||
enableSubmit(false); | ||
} | ||
return data; | ||
} | ||
|
||
function formatDate(date) { | ||
var d = new Date(date), | ||
month = "" + (d.getMonth() + 1), | ||
day = "" + d.getDate(), | ||
year = d.getFullYear(); | ||
|
||
if (month.length < 2) month = "0" + month; | ||
if (day.length < 2) day = "0" + day; | ||
if (month.length < 2) month = "0" + month; | ||
if (day.length < 2) day = "0" + day; | ||
|
||
return [year, month, day].join("-"); | ||
} | ||
|
||
$("#date_input").val(formatDate(new Date())); | ||
|
||
// $(".dropdown__input_hidden").on("change", collectData); | ||
$("#custom_input").on("input", collectData); | ||
$("#amount").on("input", collectData); | ||
$("#date_input").on("change", collectData); | ||
|
||
$(".custom-category").hide(); | ||
// $("#custom_input").hide(); | ||
|
||
const mainButton = window.Telegram.WebApp.MainButton; | ||
mainButton.text = "Отправить"; | ||
mainButton.enable(); | ||
mainButton.onClick(function () { | ||
window.Telegram.WebApp.sendData(JSON.stringify(collectData())); | ||
}); | ||
return [year, month, day].join("-"); | ||
} | ||
|
||
function enableSubmit(activate) { | ||
if (activate) { | ||
mainButton.show(); | ||
} else { | ||
mainButton.hide(); | ||
} | ||
} | ||
$("#date_input").val(formatDate(new Date())); | ||
|
||
// $(".dropdown__input_hidden").on("change", collectData); | ||
$("#custom_input").on("input", collectData); | ||
$("#amount").on("input", collectData); | ||
$("#date_input").on("change", collectData); | ||
|
||
$(".custom-category").hide(); | ||
// $("#custom_input").hide(); | ||
|
||
const mainButton = window.Telegram.WebApp.MainButton; | ||
mainButton.text = "Отправить"; | ||
mainButton.enable(); | ||
mainButton.onClick(function () { | ||
window.Telegram.WebApp.sendData(JSON.stringify(collectData())); | ||
}); | ||
</script> | ||
|
||
<body> | ||
function enableSubmit(activate) { | ||
if (activate) { | ||
mainButton.show(); | ||
} else { | ||
mainButton.hide(); | ||
} | ||
} | ||
}); | ||
</script> | ||
|
||
<body> | ||
|
||
<dotlottie-player src="https://lottie.host/31eb8f50-5493-47de-939a-adffa6bd4317/wbaxE0xVId.json" background="transparent" speed="1" style="width: 100%; height: 100px; text-align: center;" loop autoplay></dotlottie-player> | ||
<dotlottie-player src="https://lottie.host/31eb8f50-5493-47de-939a-adffa6bd4317/wbaxE0xVId.json" | ||
background="transparent" speed="1" style="width: 100%; height: 100px; text-align: center;" loop | ||
autoplay></dotlottie-player> | ||
|
||
<form class="form"> | ||
<div class="field-wrapper"> | ||
<span class="label">Категория</span> | ||
<button class="select-button" type="button">Категория</button> | ||
</div> | ||
<ul id="custom-dropdown" class="select-options"></ul> | ||
|
||
<label class="hidden-input-label" for="select-value"> | ||
<input id="select-value" class="hidden-input" type="text" name="select-category" value=""/> | ||
</label> | ||
|
||
<div class="field-wrapper custom-category"> | ||
<label id="custom_label" for="custom_input" class="label">Своя категория</label> | ||
<input id="custom_input" type="text" name="custom" placeholder="Своя категория" class="text-field"/> | ||
</div> | ||
|
||
<div class="field-wrapper"> | ||
<label for="amount" class="label">Сумма траты</label> | ||
<input type="number" id="amount" name="amount" placeholder="Сумма" class="text-field" /> | ||
</div> | ||
|
||
<div class="field-wrapper"> | ||
<label for="text" class="label">Комментарий</label> | ||
<textarea | ||
id="text" | ||
name="text" | ||
placeholder="Комментарий" | ||
rows="3" | ||
class="text-field" | ||
></textarea> | ||
</div> | ||
|
||
<div class="field-wrapper"> | ||
<label for="amount" class="label">Дата</label> | ||
<input type="date" id="date_input" class="text-field"> | ||
</div> | ||
<div class="field-wrapper"> | ||
<span class="label">Категория</span> | ||
<button class="select-button" type="button">Категория</button> | ||
</div> | ||
<ul id="custom-dropdown" class="select-options"></ul> | ||
|
||
<label class="hidden-input-label" for="select-value"> | ||
<input id="select-value" class="hidden-input" type="text" name="select-category" value="" /> | ||
</label> | ||
|
||
<div class="field-wrapper custom-category"> | ||
<label id="custom_label" for="custom_input" class="label">Своя категория</label> | ||
<input id="custom_input" type="text" name="custom" placeholder="Своя категория" class="text-field" /> | ||
</div> | ||
|
||
<div class="field-wrapper"> | ||
<label for="amount" class="label">Сумма траты</label> | ||
<input type="number" id="amount" name="amount" placeholder="Сумма" class="text-field" /> | ||
</div> | ||
|
||
<div class="field-wrapper"> | ||
<label for="text" class="label">Комментарий</label> | ||
<textarea id="text" name="text" placeholder="Комментарий" rows="3" class="text-field"></textarea> | ||
</div> | ||
|
||
<div class="field-wrapper"> | ||
<label for="amount" class="label">Дата</label> | ||
<input type="date" id="date_input" class="text-field"> | ||
</div> | ||
</form> | ||
</body> | ||
</html> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.