| 1 |
document.addEventListener("DOMContentLoaded", function () { |
| 2 |
const buttons = document.querySelectorAll(".basalam-action-button[data-url]"); |
| 3 |
|
| 4 |
buttons.forEach((button) => { |
| 5 |
button.addEventListener("click", function (event) { |
| 6 |
event.preventDefault(); |
| 7 |
|
| 8 |
const dataAttributes = [...button.getAttributeNames()].filter((name) => |
| 9 |
name.startsWith("data-") |
| 10 |
); |
| 11 |
|
| 12 |
const attributes = {}; |
| 13 |
dataAttributes.forEach((attr) => { |
| 14 |
const cleanAttr = attr |
| 15 |
.replace("data-", "") |
| 16 |
.replace(/-/g, "_") |
| 17 |
.toLowerCase(); |
| 18 |
attributes[cleanAttr] = button.getAttribute(attr); |
| 19 |
}); |
| 20 |
|
| 21 |
const formData = new FormData(); |
| 22 |
Object.keys(attributes).forEach((key) => { |
| 23 |
formData.append(key, attributes[key]); |
| 24 |
}); |
| 25 |
|
| 26 |
const url = attributes["url"]; |
| 27 |
|
| 28 |
if (confirm("آیا � |
| 29 |
ط� |
| 30 |
ئن هستید که � |
| 31 |
یخواهید این ع� |
| 32 |
ل را انجا� |
| 33 |
دهید؟")) { |
| 34 |
const originalText = this.innerText; |
| 35 |
this.innerText = "در حال پردازش..."; |
| 36 |
this.disabled = true; |
| 37 |
|
| 38 |
fetch(url, { |
| 39 |
method: "POST", |
| 40 |
body: formData, |
| 41 |
}) |
| 42 |
.then((response) => response.json()) |
| 43 |
.then((data) => { |
| 44 |
if (data.success) { |
| 45 |
window.BasalamToast.success(data.data.message || "ع� |
| 46 |
لیات با � |
| 47 |
وفقیت انجا� |
| 48 |
شد."); |
| 49 |
location.reload(); |
| 50 |
} else { |
| 51 |
window.BasalamToast.error(data.data?.message || "خطا در انجا� |
| 52 |
ع� |
| 53 |
لیات."); |
| 54 |
} |
| 55 |
}) |
| 56 |
.catch((error) => { |
| 57 |
window.BasalamToast.error("خطا در انجا� |
| 58 |
ع� |
| 59 |
لیات: " + error); |
| 60 |
}) |
| 61 |
.finally(() => { |
| 62 |
this.innerText = originalText; |
| 63 |
this.disabled = false; |
| 64 |
}); |
| 65 |
} |
| 66 |
}); |
| 67 |
}); |
| 68 |
}); |
| 69 |
|