DmitrMakeev commited on
Commit
5b2c600
·
verified ·
1 Parent(s): afc4f6a

Update nutri_call.html

Browse files
Files changed (1) hide show
  1. nutri_call.html +105 -42
nutri_call.html CHANGED
@@ -12,7 +12,11 @@
12
  <!-- Основные стили PNotify -->
13
  <link href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css" rel="stylesheet">
14
  <script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script>
 
 
15
 
 
 
16
 
17
  <meta charset="UTF-8">
18
  <title>Калькулятор удобрений</title>
@@ -1513,36 +1517,37 @@ function showCalculationStatus(response) {
1513
 
1514
  <script>
1515
  // Предустановленные профили (JSON)
 
1516
  const predefinedProfiles = {
1517
- "profiles": [
1518
  {
1519
- "name": "Профиль 1",
1520
- "values": {
1521
- "profile_p": 31,
1522
- "profile_k": 210,
1523
- "profile_mg": 24,
1524
- "profile_ca": 82,
1525
- "profile_s": 57.5,
1526
- "profile_no3": 8.25,
1527
- "profile_n": 125,
1528
- "liters": 100,
1529
- "fert_fe_chelate_mass": 2.0,
1530
- "fert_fe_complex_mass": 1.0
1531
  }
1532
  },
1533
  {
1534
- "name": "Профиль 2",
1535
- "values": {
1536
- "profile_p": 40,
1537
- "profile_k": 250,
1538
- "profile_mg": 30,
1539
- "profile_ca": 90,
1540
- "profile_s": 60,
1541
- "profile_no3": 10,
1542
- "profile_n": 150,
1543
- "liters": 150,
1544
- "fert_fe_chelate_mass": 3.0,
1545
- "fert_fe_complex_mass": 2.0
1546
  }
1547
  }
1548
  ]
@@ -1608,6 +1613,7 @@ function updateProfileFields(selectedProfile) {
1608
  document.getElementById("fert_fe_complex_mass").value = selectedProfile.values.fert_fe_complex_mass || 0;
1609
  }
1610
 
 
1611
  document.getElementById("profile-selector").addEventListener("change", function () {
1612
  const selectedProfileName = this.value;
1613
  const allProfiles = loadAllProfiles();
@@ -1619,10 +1625,25 @@ document.getElementById("profile-selector").addEventListener("change", function
1619
  });
1620
 
1621
  // Сохранение нового профиля
1622
- document.getElementById("save-profile").addEventListener("click", function () {
1623
- const profileName = prompt("Введите название профиля:");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1624
  if (!profileName) return;
1625
 
 
1626
  const newProfile = {
1627
  name: profileName,
1628
  values: {
@@ -1639,6 +1660,7 @@ document.getElementById("save-profile").addEventListener("click", function () {
1639
  }
1640
  };
1641
 
 
1642
  let userProfiles = JSON.parse(localStorage.getItem("userProfiles")) || [];
1643
  userProfiles.push(newProfile);
1644
  localStorage.setItem("userProfiles", JSON.stringify(userProfiles));
@@ -1648,10 +1670,14 @@ document.getElementById("save-profile").addEventListener("click", function () {
1648
  });
1649
 
1650
  // Удаление выбранного профиля
1651
- document.getElementById("delete-profile").addEventListener("click", function () {
1652
  const selectedProfileName = document.getElementById("profile-selector").value;
1653
  if (!selectedProfileName) {
1654
- alert("Выберите профиль для удаления!");
 
 
 
 
1655
  return;
1656
  }
1657
 
@@ -1660,24 +1686,61 @@ document.getElementById("delete-profile").addEventListener("click", function ()
1660
  const profileIndex = userProfiles.findIndex(profile => profile.name === selectedProfileName);
1661
 
1662
  if (profileIndex === -1) {
1663
- alert("Невозможно удалить предустановленный профиль!");
 
 
 
 
1664
  return;
1665
  }
1666
 
1667
- // Удаляем профиль
1668
- userProfiles.splice(profileIndex, 1);
1669
- localStorage.setItem("userProfiles", JSON.stringify(userProfiles));
 
 
 
 
 
1670
 
1671
- // Обновляем выпадающий список
1672
- populateProfileSelector();
 
 
 
 
 
 
 
1673
 
1674
- // Выбираем первый профиль по умолчанию
1675
- const allProfiles = loadAllProfiles();
1676
- if (allProfiles.length > 0) {
1677
- document.getElementById("profile-selector").value = allProfiles[0].name;
1678
- updateProfileFields(allProfiles[0]);
1679
- } else {
1680
- alert("Все профили удалены!");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1681
  }
1682
  });
1683
 
 
12
  <!-- Основные стили PNotify -->
13
  <link href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css" rel="stylesheet">
14
  <script src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js"></script>
15
+ <!-- SweetAlert2 CSS -->
16
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2 @11/dist/sweetalert2.min.css">
17
 
18
+ <!-- SweetAlert2 JS -->
19
+ <script src="https://cdn.jsdelivr.net/npm/sweetalert2 @11"></script>
20
 
21
  <meta charset="UTF-8">
22
  <title>Калькулятор удобрений</title>
 
1517
 
1518
  <script>
1519
  // Предустановленные профили (JSON)
1520
+ // Предустановленные профили (JSON)
1521
  const predefinedProfiles = {
1522
+ profiles: [
1523
  {
1524
+ name: "Профиль 1",
1525
+ values: {
1526
+ profile_p: 31,
1527
+ profile_k: 210,
1528
+ profile_mg: 24,
1529
+ profile_ca: 82,
1530
+ profile_s: 57.5,
1531
+ profile_no3: 8.25,
1532
+ profile_n: 125,
1533
+ liters: 100,
1534
+ fert_fe_chelate_mass: 2.0,
1535
+ fert_fe_complex_mass: 1.0
1536
  }
1537
  },
1538
  {
1539
+ name: "Профиль 2",
1540
+ values: {
1541
+ profile_p: 40,
1542
+ profile_k: 250,
1543
+ profile_mg: 30,
1544
+ profile_ca: 90,
1545
+ profile_s: 60,
1546
+ profile_no3: 10,
1547
+ profile_n: 150,
1548
+ liters: 150,
1549
+ fert_fe_chelate_mass: 3.0,
1550
+ fert_fe_complex_mass: 2.0
1551
  }
1552
  }
1553
  ]
 
1613
  document.getElementById("fert_fe_complex_mass").value = selectedProfile.values.fert_fe_complex_mass || 0;
1614
  }
1615
 
1616
+ // Слушатель события изменения выбранного профиля
1617
  document.getElementById("profile-selector").addEventListener("change", function () {
1618
  const selectedProfileName = this.value;
1619
  const allProfiles = loadAllProfiles();
 
1625
  });
1626
 
1627
  // Сохранение нового профиля
1628
+ document.getElementById("save-profile").addEventListener("click", async function () {
1629
+ // Используем SweetAlert2 для ввода имени профиля
1630
+ const { value: profileName } = await Swal.fire({
1631
+ title: "Введите название профиля",
1632
+ input: "text",
1633
+ inputPlaceholder: "Название профиля",
1634
+ showCancelButton: true,
1635
+ confirmButtonText: "Сохранить",
1636
+ cancelButtonText: "Отмена",
1637
+ inputValidator: (value) => {
1638
+ if (!value) {
1639
+ return "Название профиля не может быть пустым!";
1640
+ }
1641
+ }
1642
+ });
1643
+
1644
  if (!profileName) return;
1645
 
1646
+ // Создаём новый профиль
1647
  const newProfile = {
1648
  name: profileName,
1649
  values: {
 
1660
  }
1661
  };
1662
 
1663
+ // Добавляем профиль в localStorage
1664
  let userProfiles = JSON.parse(localStorage.getItem("userProfiles")) || [];
1665
  userProfiles.push(newProfile);
1666
  localStorage.setItem("userProfiles", JSON.stringify(userProfiles));
 
1670
  });
1671
 
1672
  // Удаление выбранного профиля
1673
+ document.getElementById("delete-profile").addEventListener("click", async function () {
1674
  const selectedProfileName = document.getElementById("profile-selector").value;
1675
  if (!selectedProfileName) {
1676
+ Swal.fire({
1677
+ icon: "error",
1678
+ title: "Ошибка",
1679
+ text: "Выберите профиль для удаления!"
1680
+ });
1681
  return;
1682
  }
1683
 
 
1686
  const profileIndex = userProfiles.findIndex(profile => profile.name === selectedProfileName);
1687
 
1688
  if (profileIndex === -1) {
1689
+ Swal.fire({
1690
+ icon: "error",
1691
+ title: "Ошибка",
1692
+ text: "Невозможно удалить предустановленный профиль!"
1693
+ });
1694
  return;
1695
  }
1696
 
1697
+ // Показываем SweetAlert2 для подтверждения удаления
1698
+ const swalWithBootstrapButtons = Swal.mixin({
1699
+ customClass: {
1700
+ confirmButton: "btn btn-success",
1701
+ cancelButton: "btn btn-danger"
1702
+ },
1703
+ buttonsStyling: false
1704
+ });
1705
 
1706
+ const result = await swalWithBootstrapButtons.fire({
1707
+ title: "Вы уверены?",
1708
+ text: "Это действие нельзя отменить!",
1709
+ icon: "warning",
1710
+ showCancelButton: true,
1711
+ confirmButtonText: "Да, удалить!",
1712
+ cancelButtonText: "Нет, отмена!",
1713
+ reverseButtons: true
1714
+ });
1715
 
1716
+ if (result.isConfirmed) {
1717
+ // Удаляем профиль
1718
+ userProfiles.splice(profileIndex, 1);
1719
+ localStorage.setItem("userProfiles", JSON.stringify(userProfiles));
1720
+
1721
+ // Обновляем выпадающий список
1722
+ populateProfileSelector();
1723
+
1724
+ // Выбираем первый профиль по умолчанию
1725
+ const allProfiles = loadAllProfiles();
1726
+ if (allProfiles.length > 0) {
1727
+ document.getElementById("profile-selector").value = allProfiles[0].name;
1728
+ updateProfileFields(allProfiles[0]);
1729
+ }
1730
+
1731
+ // Показываем сообщение об успешном удалении
1732
+ swalWithBootstrapButtons.fire({
1733
+ title: "Удалено!",
1734
+ text: "Профиль успешно удалён.",
1735
+ icon: "success"
1736
+ });
1737
+ } else if (result.dismiss === Swal.DismissReason.cancel) {
1738
+ // Показываем сообщение об отмене
1739
+ swalWithBootstrapButtons.fire({
1740
+ title: "Отменено",
1741
+ text: "Профиль не был удалён.",
1742
+ icon: "error"
1743
+ });
1744
  }
1745
  });
1746