PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.8.5
ووسلام – همگام سازی ووکامرس و باسلام v1.8.5
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 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / assets / js / map-category-option.js

map-category-option.js in ووسلام – همگام سازی ووکامرس و باسلام 1.8.5, at assets/js/map-category-option.js

126 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function ($) {
2 function getDeleteNonce() {
3 return (
4 $(".options_mapping_section").data("delete-nonce") ||
5 $(".Basalam-delete-option").first().data("_wpnonce") ||
6 ""
7 );
8 }
9
10 function submitMapOption() {
11 const wooName = $("#woo-option-name").val().trim();
12 const basalamName = $("#Basalam-option-name").val().trim();
13 const nonce = $("#basalam_add_map_option_nonce").val();
14
15 if (!wooName || !basalamName) {
16 alert("لطفاً هر دو �
17 قدار را وارد کنید.");
18 return;
19 }
20
21 $.ajax({
22 url: ajaxurl,
23 type: "POST",
24 data: {
25 action: "basalam_add_map_option",
26 "woo-option-name": wooName,
27 "basalam-option-name": basalamName,
28 _wpnonce: nonce,
29 },
30 success: function (response) {
31 if (response.success) {
32 $("#Basalam-map-option-result").text("ویژگی با �
33 وفقیت ذخیره شد.");
34 $(".options_mapping_section").show();
35 $("#woo-option-name").val("");
36 $("#Basalam-option-name").val("");
37
38 const deleteNonce = getDeleteNonce();
39 const newRow = `
40 <tr data-woo="${wooName}" data-basalam="${basalamName}">
41 <td>${wooName}</td>
42 <td>${basalamName}</td>
43 <td>
44 <button type="button" class="Basalam-delete-option basalam-primary-button basalam-delete-option-auto" data-_wpnonce="${deleteNonce}">حذف</button>
45 </td>
46 </tr>
47 `;
48
49 const $tableBody = $(".basalam-table tbody");
50 if ($tableBody.length > 0) {
51 $tableBody.append(newRow);
52 }
53 } else {
54 const errorMessage = response.data?.message || "خطا در ذخیره‌سازی.";
55 alert(errorMessage);
56 $("#Basalam-map-option-result").text(errorMessage);
57 }
58 },
59 error: function (xhr) {
60 const errorMessage =
61 xhr.responseJSON?.data?.message || "خطا در ارسال درخواست.";
62 alert(errorMessage);
63 $("#Basalam-map-option-result").text(errorMessage);
64 },
65 });
66 }
67
68 $(document).on("click", ".Basalam-delete-option", function (e) {
69 e.preventDefault();
70
71 if (!window.confirm("آیا �
72 ط�
73 ئن هستید؟")) {
74 return;
75 }
76
77 const $row = $(this).closest("tr");
78 const woo_name = $row.data("woo");
79 const basalam_name = $row.data("basalam");
80 const nonce = $(this).data("_wpnonce") || getDeleteNonce();
81
82 $.ajax({
83 url: ajaxurl,
84 method: "POST",
85 data: {
86 action: "basalam_delete_mapped_option",
87 woo_name: woo_name,
88 basalam_name: basalam_name,
89 _wpnonce: nonce,
90 },
91 success: function (response) {
92 if (response.success) {
93 $row.remove();
94 if ($(".basalam-table tbody tr").length === 0) {
95 $(".options_mapping_section").hide();
96 }
97 } else {
98 alert("ع�
99 لیات نا�
100 وفق بود");
101 }
102 },
103 error: function () {
104 alert("خطایی در ارسال درخواست رخ داد.");
105 location.reload();
106 },
107 });
108 });
109
110 $(document).on("click", "#Basalam-map-option-submit", function (e) {
111 e.preventDefault();
112 submitMapOption();
113 });
114
115 $(document).on("keydown", "#Basalam-map-option-form input", function (e) {
116 if (e.key === "Enter") {
117 e.preventDefault();
118 submitMapOption();
119 }
120 });
121
122 if ($(".basalam-table tbody tr").length === 0) {
123 $(".options_mapping_section").hide();
124 }
125 });
126