| @@ -208,14 +208,45 @@ | ||
| 208 | 208 | }); |
| 209 | 209 | |
| 210 | 210 | const select = document.getElementById("basalam-sync-type"); |
| 211 | 211 | if (select) { |
| 212 | + const customFields = document.getElementById("Basalam-custom-fields"); | |
| 213 | + const settingsForm = select.closest("form"); | |
| 214 | + const validationMessage = | |
| 215 | + "در حالت سفارشی باید حداقل یک فیلد را برای بروزرسانی انتخاب کنید."; | |
| 216 | + | |
| 212 | 217 | const toggleFields = (val) => { |
| 213 | - document.getElementById("Basalam-custom-fields").style.display = | |
| 214 | - val === "custom" ? "block" : "none"; | |
| 218 | + if (customFields) { | |
| 219 | + customFields.style.display = val === "custom" ? "block" : "none"; | |
| 220 | + } | |
| 215 | 221 | }; |
| 222 | + | |
| 223 | + const hasSelectedCustomField = () => | |
| 224 | + customFields && | |
| 225 | + Array.from( | |
| 226 | + customFields.querySelectorAll('input[type="checkbox"]') | |
| 227 | + ).some((checkbox) => checkbox.checked); | |
| 228 | + | |
| 216 | 229 | toggleFields(select.value); |
| 217 | 230 | select.addEventListener("change", (e) => toggleFields(e.target.value)); |
| 231 | + | |
| 232 | + if (settingsForm) { | |
| 233 | + settingsForm.addEventListener("submit", (event) => { | |
| 234 | + if (select.value !== "custom" || hasSelectedCustomField()) return; | |
| 235 | + | |
| 236 | + event.preventDefault(); | |
| 237 | + event.stopImmediatePropagation(); | |
| 238 | + | |
| 239 | + if (window.BasalamToast) { | |
| 240 | + window.BasalamToast.error(validationMessage); | |
| 241 | + } | |
| 242 | + | |
| 243 | + if (customFields) { | |
| 244 | + customFields.scrollIntoView({ behavior: "smooth", block: "center" }); | |
| 245 | + customFields.querySelector('input[type="checkbox"]')?.focus(); | |
| 246 | + } | |
| 247 | + }, true); | |
| 248 | + } | |
| 218 | 249 | } |
| 219 | 250 | |
| 220 | 251 | // Tab functionality for settings modal |
| 221 | 252 | const initTabs = () => { |
| @@ -867,15 +898,15 @@ | ||
| 867 | 898 | } |
| 868 | 899 | }); |
| 869 | 900 | }; |
| 870 | 901 | |
| 871 | - const syncIncreaseVisibility = () => { | |
| 902 | + const syncPriceChangeVisibility = () => { | |
| 872 | 903 | document |
| 873 | - .querySelectorAll('select[name="sync_basalam_bulk_increase_action"]') | |
| 904 | + .querySelectorAll('select[name="sync_basalam_bulk_price_change_action"]') | |
| 874 | 905 | .forEach((select) => { |
| 875 | 906 | const field = select |
| 876 | 907 | .closest(".sync-basalam-bulk-edit") |
| 877 | - ?.querySelector(".sync-basalam-bulk-increase-value"); | |
| 908 | + ?.querySelector(".sync-basalam-bulk-price-change-value"); | |
| 878 | 909 | |
| 879 | 910 | if (field) { |
| 880 | 911 | field.style.display = select.value === "set" ? "block" : "none"; |
| 881 | 912 | } |
| @@ -905,9 +936,9 @@ | ||
| 905 | 936 | |
| 906 | 937 | window.requestAnimationFrame(() => { |
| 907 | 938 | setBulkEditMode("basalam"); |
| 908 | 939 | syncTypeVisibility(); |
| 909 | - syncIncreaseVisibility(); | |
| 940 | + syncPriceChangeVisibility(); | |
| 910 | 941 | }); |
| 911 | 942 | }; |
| 912 | 943 | |
| 913 | 944 | document.addEventListener("change", (event) => { |
| @@ -919,10 +950,10 @@ | ||
| 919 | 950 | if (target.name === "sync_basalam_bulk_product_type_action") { |
| 920 | 951 | syncTypeVisibility(); |
| 921 | 952 | } |
| 922 | 953 | |
| 923 | - if (target.name === "sync_basalam_bulk_increase_action") { | |
| 924 | - syncIncreaseVisibility(); | |
| 954 | + if (target.name === "sync_basalam_bulk_price_change_action") { | |
| 955 | + syncPriceChangeVisibility(); | |
| 925 | 956 | } |
| 926 | 957 | }); |
| 927 | 958 | |
| 928 | 959 | document.addEventListener("click", (event) => { |
| @@ -967,9 +998,9 @@ | ||
| 967 | 998 | |
| 968 | 999 | setBulkEditMode("default"); |
| 969 | 1000 | |
| 970 | 1001 | syncTypeVisibility(); |
| 971 | - syncIncreaseVisibility(); | |
| 1002 | + syncPriceChangeVisibility(); | |
| 972 | 1003 | }; |
| 973 | 1004 | |
| 974 | 1005 | initBulkEditFields(); |
| 975 | 1006 | |