Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
oybek committed Sep 30, 2023
1 parent a85c83a commit 1562063
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
23 changes: 22 additions & 1 deletion spendbook/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
<script>
$(document).ready(function () {
function collectData() {
var category = $("#category").val();
if (category === categories[categories.length-1]) {
category = $("#custom_input").val();
}
const data = {
category: $("#category").val(),
category: category,
amount: parseInt($("#amount").val(), 10),
description: $("#text").val(),
};
Expand All @@ -29,6 +33,19 @@
$("#category").on("change", collectData);
$("#amount").on("input", collectData);

$("#custom_label").hide();
$("#custom_input").hide();
$("#category").on("change", function() {
const category = $("#category").val();
if (category === categories[categories.length-1]) {
$("#custom_label").show();
$("#custom_input").show();
} else {
$("#custom_label").hide();
$("#custom_input").hide();
}
});

const mainButton = window.Telegram.WebApp.MainButton;
mainButton.text = "Отправить";
mainButton.enable();
Expand All @@ -51,6 +68,10 @@
<form>
<label for="category">Категория траты</label>
<select id="category" name="category"></select>

<label id="custom_label" for="custom">Своя категория</label>
<input id="custom_input" type="text" name="custom" placeholder="Своя категория"/>

<label for="amount">Сумма траты</label>
<input type="number" id="amount" name="amount" placeholder="Сумма" />
<textarea
Expand Down
45 changes: 23 additions & 22 deletions spendbook/js/dropDowns.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
const categories = [
{ text: "Прочее", value: "other" },
{ text: "Автомобиль", value: "car" },
{ text: "ЖКХ", value: "hcs" },
{ text: "Квартира", value: "apartment" },
{ text: "Красота", value: "beauty" },
{ text: "Образование", value: "education" },
{ text: "Одежда", value: "clothes" },
{ text: "Подарки", value: "gifts" },
{ text: "Путешествия", value: "travel" },
{ text: "Рестораны", value: "restaurant" },
{ text: "Благотворительность", value: "charity" },
{ text: "Связь", value: "communication" },
{ text: "Спорт", value: "sport" },
{ text: "Супермаркеты", value: "supermarket" },
{ text: "Техника", value: "appliances" },
{ text: "Транспорт", value: "transport" },
{ text: "Хобби", value: "hobby" },
{ text: "Развлечения", value: "entertainment" },
{ text: "Аптеки", value: "pharmacies" },
{ text: "Медицина", value: "medicine" },
"Аптеки",
"Аренда квартиры",
"ЖКХ",
"Красота",
"Кредиты",
"Медицина",
"Образование",
"Одежда",
"Подарки",
"Подписки",
"Путешествия",
"Развлечения",
"Ремонт",
"Рестораны",
"Супермаркеты",
"Техника",
"Транспорт",
"Хобби",

// Должно быть последним
"Ввести свою категорию",
];

const months = [
Expand All @@ -37,8 +38,8 @@ const months = [
];

$(document).ready(function () {
$.each(categories, function (key, obj) {
$("#category").append(`<option value="${obj.value}">${obj.text}</option>`);
$.each(categories, function (key, str) {
$("#category").append(`<option value="${str}">${str}</option>`);
});
$.each(months, function (key, obj) {
$("#month").append(`<option value="${obj.value}">${obj.text}</option>`);
Expand Down

0 comments on commit 1562063

Please sign in to comment.