PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.28
ووسلام – همگام سازی ووکامرس و باسلام v1.10.28
1.10.28 1.1.26 1.10.27 1.10.24 1.10.25 1.10.23 1.10.22 1.10.21 1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 All 61 releases
sync-basalam / assets / js / check-sync.js

check-sync.js in ووسلام – همگام سازی ووکامرس و باسلام 1.10.28, at assets/js/check-sync.js

190 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function ($) {
2 // Toggle dropdown on arrow click
3 $(document).on("click", ".basalam-dropdown-arrow-btn", function (e) {
4 e.preventDefault();
5 e.stopPropagation();
6 const $wrapper = $(this).closest(".basalam-orders-fetch-wrapper");
7 const $dropdown = $wrapper.find(".basalam-orders-fetch-dropdown");
8 $dropdown.toggle();
9 });
10
11 // Toggle product synchronization options from the split-button arrow.
12 $(document).on("click", ".basalam-product-sync-arrow-btn", function (e) {
13 e.preventDefault();
14 e.stopPropagation();
15
16 const $btn = $(this);
17 const $wrapper = $btn.closest(".basalam-product-sync-wrapper");
18 const $dropdown = $wrapper.find(".basalam-product-sync-dropdown");
19 const isOpen = $dropdown.is(":visible");
20
21 $(".basalam-product-sync-dropdown").hide();
22 $(".basalam-product-sync-arrow-btn").attr("aria-expanded", "false");
23
24 if (!isOpen) {
25 $dropdown.show();
26 $btn.attr("aria-expanded", "true");
27 }
28 });
29
30 // Close dropdown when clicking outside
31 $(document).on("click", function (e) {
32 if (!$(e.target).closest(".basalam-orders-fetch-wrapper").length) {
33 $(".basalam-orders-fetch-dropdown").hide();
34 }
35
36 if (!$(e.target).closest(".basalam-product-sync-wrapper").length) {
37 $(".basalam-product-sync-dropdown").hide();
38 $(".basalam-product-sync-arrow-btn").attr("aria-expanded", "false");
39 }
40 });
41
42 // Fetch orders with default 7 days
43 $(document).on("click", ".basalam-fetch-orders-btn", function (e) {
44 e.preventDefault();
45 const $btn = $(this);
46 const $wrapper = $btn.closest(".basalam-orders-fetch-wrapper");
47 const nonce = $btn.data("nonce");
48
49 $btn.prop("disabled", true).find(".basalam-btn-text").text("در حال شروع...");
50
51 $.ajax({
52 url: ajaxurl,
53 type: "POST",
54 data: {
55 action: "add_unsync_orders_from_basalam",
56 _wpnonce: nonce,
57 days: 7,
58 },
59 success: function (response) {
60 if (response.success) {
61 window.BasalamToast.success(response.data?.message || "ع�
62 لیات با �
63 وفقیت انجا�
64 شد.");
65 location.reload();
66 } else {
67 window.BasalamToast.error(response.data?.message || "خطایی رخ داده است.");
68 $btn.prop("disabled", false).find(".basalam-btn-text").text("بررسی سفارشات باسلا�
69 ");
70 }
71 },
72 error: function (jqXHR) {
73 let message = "خطایی در ارتباط با سرور رخ داد.";
74 try {
75 const response = JSON.parse(jqXHR.responseText);
76 message = response.data?.message || message;
77 } catch (e) {}
78 window.BasalamToast.error(message);
79 $btn.prop("disabled", false).find(".basalam-btn-text").text("بررسی سفارشات باسلا�
80 ");
81 },
82 });
83 });
84
85 // Submit fetch orders with custom days
86 $(document).on("click", ".basalam-dropdown-submit", function (e) {
87 e.preventDefault();
88
89 const $btn = $(this);
90 const $wrapper = $btn.closest(".basalam-orders-fetch-wrapper");
91 const $dropdown = $wrapper.find(".basalam-orders-fetch-dropdown");
92 const $daysInput = $dropdown.find(".basalam-dropdown-input");
93 const $mainBtn = $wrapper.find(".basalam-fetch-orders-btn");
94 const nonce = $btn.data("nonce");
95 let days = parseInt($daysInput.val());
96
97 // Validate days
98 if (isNaN(days) || days < 1 || days > 30) {
99 window.BasalamToast.warning("عدد وارد شده باید بین ۱ تا ۳۰ باشد.");
100 $daysInput.focus();
101 return;
102 }
103
104 $btn.text("در حال بررسی...").prop("disabled", true);
105 $mainBtn.prop("disabled", true).find(".basalam-btn-text").text("در حال بررسی...");
106
107 $.ajax({
108 url: ajaxurl,
109 type: "POST",
110 data: {
111 action: "add_unsync_orders_from_basalam",
112 _wpnonce: nonce,
113 days: days,
114 },
115 success: function (response) {
116 if (response.success) {
117 window.BasalamToast.success(response.data?.message || "ع�
118 لیات با �
119 وفقیت انجا�
120 شد.");
121 location.reload();
122 } else {
123 window.BasalamToast.error(response.data?.message || "خطایی رخ داده است.");
124 $btn.text("بررسی سفارشات").prop("disabled", false);
125 $mainBtn.prop("disabled", false).find(".basalam-btn-text").text("بررسی سفارشات باسلا�
126 ");
127 }
128 },
129 error: function (jqXHR) {
130 let message = "خطایی در ارتباط با سرور رخ داد.";
131 try {
132 const response = JSON.parse(jqXHR.responseText);
133 message = response.data?.message || message;
134 } catch (e) {}
135 window.BasalamToast.error(message);
136 $btn.text("بررسی سفارشات").prop("disabled", false);
137 $mainBtn.prop("disabled", false).find(".basalam-btn-text").text("بررسی سفارشات باسلا�
138 ");
139 },
140 });
141 });
142
143 // Cancel fetch orders
144 $(document).on("click", ".basalam-cancel-orders-btn", function (e) {
145 e.preventDefault();
146
147 const $btn = $(this);
148 const nonce = $btn.data("nonce");
149
150 if (!confirm("آیا �
151 ط�
152 ئن هستید که �
153 ی‌خواهید ه�
154 گا�
155 ‌سازی سفارشات را لغو کنید؟")) {
156 return;
157 }
158
159 $btn.prop("disabled", true);
160
161 $.ajax({
162 url: ajaxurl,
163 type: "POST",
164 data: {
165 action: "cancel_fetch_orders",
166 _wpnonce: nonce,
167 },
168 success: function (response) {
169 if (response.success) {
170 window.BasalamToast.info(response.data?.message || "ع�
171 لیات لغو شد.");
172 location.reload();
173 } else {
174 window.BasalamToast.error(response.data?.message || "خطایی رخ داده است.");
175 $btn.prop("disabled", false);
176 }
177 },
178 error: function (jqXHR) {
179 let message = "خطایی در ارتباط با سرور رخ داد.";
180 try {
181 const response = JSON.parse(jqXHR.responseText);
182 message = response.data?.message || message;
183 } catch (e) {}
184 window.BasalamToast.error(message);
185 $btn.prop("disabled", false);
186 },
187 });
188 });
189 });
190