From cccf382818b9b735d3109484b9951ef666c22651 Mon Sep 17 00:00:00 2001 From: Nurs Date: Wed, 16 Sep 2026 12:07:10 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20addEquipment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.js | 76 +++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/script.js b/script.js index b730af8..936657a 100644 --- a/script.js +++ b/script.js @@ -367,19 +367,19 @@ function updateCounts() { } } -async function addEquipment(event) { +function addEquipment(event) { event.preventDefault(); const form = event.target; const formData = new FormData(form); - const lastCheck = formData.get('lastCheck'); - const period = parseInt(formData.get('period')); - const nextCheck = calculateNextDateValue(lastCheck, period); - + // Если режим редактирования - обрабатываем отдельно if (editingId) { - // Edit existing item const index = equipment.findIndex(e => e.id === editingId); if (index !== -1) { + const lastCheck = formData.get('lastCheck'); + const period = parseInt(formData.get('period')); + const nextCheck = calculateNextDateValue(lastCheck, period); + equipment[index] = { ...equipment[index], name: formData.get('name'), @@ -392,45 +392,39 @@ async function addEquipment(event) { nextCheck: nextCheck, note: formData.get('note') || '' }; - await saveEquipment(); + saveEquipment(); updateAll(); resetForm(); switchTab('all'); } editingId = null; - } else { - // Add new item - add to local array first - const newItem = { - id: Date.now(), - name: formData.get('name'), - category: formData.get('category'), - inventoryNumber: formData.get('inventoryNumber'), - location: formData.get('location'), - responsible: formData.get('responsible'), - lastCheck: lastCheck, - period: period, - nextCheck: nextCheck, - note: formData.get('note') || '', - status: 'ok' - }; - - equipment.push(newItem); - updateAll(); - - // Then save to server - try { - await fetch('api/items', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(equipment) - }); - } catch (e) { - console.error('Save error:', e); - } - - resetForm(); - switchTab('all'); + return; } + + // Добавление нового оборудования (как работало раньше) + const lastCheck = formData.get('lastCheck'); + const period = parseInt(formData.get('period')); + const nextCheck = calculateNextDateValue(lastCheck, period); + + const newItem = { + id: Date.now(), + name: formData.get('name'), + category: formData.get('category'), + inventoryNumber: formData.get('inventoryNumber'), + location: formData.get('location'), + responsible: formData.get('responsible'), + lastCheck: lastCheck, + period: period, + nextCheck: nextCheck, + note: formData.get('note') || '', + status: 'ok' + }; + + equipment.push(newItem); + saveEquipment(); + resetForm(); + updateAll(); + switchTab('all'); } function calculateNextDateValue(lastCheck, periodMonths) { @@ -706,9 +700,9 @@ function escapeHtml(text) { .replace(/"/g, '"'); } -async async function saveEquipment() { +async function saveEquipment() { try { - await fetch('api/items', { + fetch('api/items', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(equipment)