From ba678f0ba9a4340f26f77d107ea13f1feddf4962 Mon Sep 17 00:00:00 2001 From: Katerina881 Date: Mon, 27 Feb 2023 15:08:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=BE=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LabOne/node_modules/items.js | 81 ------------------- 1 file changed, 81 deletions(-) delete mode 100644 spring_online_calculator/LabOne/node_modules/items.js diff --git a/spring_online_calculator/LabOne/node_modules/items.js b/spring_online_calculator/LabOne/node_modules/items.js deleted file mode 100644 index de865d4..0000000 --- a/spring_online_calculator/LabOne/node_modules/items.js +++ /dev/null @@ -1,81 +0,0 @@ -'use strict' - -function addItemToTable(item, price, count) { - console.info('Try to add item'); - - const table = document.querySelector("#tbl-items tbody"); - if (table == null) { - throw 'Table is not found'; - } - - const linesCount = document.querySelectorAll("#tbl-items tbody tr").length; - - const id = 'item-' + Date.now(); - const tableHtml = - '\ - ' + (linesCount + 1) + '\ - ' + item +'\ - ' + price.toFixed(2) + '\ - ' + count + '\ - ' + (price * count).toFixed(2) + '\ - \ - '; - table.innerHTML += tableHtml; - - console.info('Added'); -} - -function removeItemFromTable(id) { - console.info('Try to remove item'); - - if (!confirm('Do you really want to remove this item?')) { - console.info('Canceled'); - return; - } - - const item = document.querySelector('#' + id); - if (item == null) { - throw 'Item with id [' + id + '] is not found'; - } - item.remove(); - - const numbers = document.querySelectorAll("#tbl-items tbody tr th"); - for (let i = 0; i < numbers.length; i++) { - numbers[i].innerHTML = i + 1; - } - - console.info('Removed'); -} - -document.addEventListener('DOMContentLoaded', function () { - console.info('Loaded'); - - const form = document.querySelector("#frm-items"); - if (form !== null) { - form.addEventListener('submit', function(event) { - console.info('Form onsubmit'); - event.preventDefault(); - - const item = document.querySelector("#item"); - if (item == null) { - throw 'Item control is not found'; - } - - const price = document.querySelector("#price"); - if (price == null) { - throw 'Price control is not found'; - } - - const count = document.querySelector("#count"); - if (count == null) { - throw 'Count control is not found'; - } - - addItemToTable(item.value, parseFloat(price.value), parseInt(count.value)); - - item.value = ''; - price.value = 0; - count.value = 0; - }); - } -}); \ No newline at end of file