PluginProbe
Subscriptions for WooCommerce with Stripe Recurring Payments / 1.10.2
Subscriptions for WooCommerce with Stripe Recurring Payments v1.10.2
2.0.0 1.11.2 1.11.1 1.11.0 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.6 1.9.5 trunk 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 All 61 releases
subscription / assets / js / admin.js

admin.js in Subscriptions for WooCommerce with Stripe Recurring Payments 1.10.2, at assets/js/admin.js

192 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(() => {
2 let sdevs_enable_subscription = jQuery("input#subscrpt_enable");
3 sdevs_enable_subscription.change(() => {
4 if (sdevs_enable_subscription.is(":checked")) {
5 jQuery(".show_if_subscription").show();
6 } else {
7 jQuery(".show_if_subscription").hide();
8 }
9 });
10 if (sdevs_enable_subscription.is(":checked")) {
11 jQuery(".show_if_subscription").show();
12 } else {
13 jQuery(".show_if_subscription").hide();
14 }
15
16 jQuery(document).on("woocommerce_variations_loaded", () => {
17 let total_variations = JSON.parse(jQuery(".woocommerce_variations").attr("data-total"));
18 for (let index = 0; index < total_variations; index++) {
19 let element = document.getElementById("subscrpt_enable[" + index + "]");
20 if (element && element.checked) {
21 jQuery(".show_if_subscription_" + index).show();
22 } else {
23 jQuery(".show_if_subscription_" + index).hide();
24 }
25 }
26 });
27
28 let subscrpt_renewal_process = jQuery("#subscrpt_renewal_process");
29 subscrpt_renewal_process.change(() => {
30 if (subscrpt_renewal_process.val() === "manual") {
31 jQuery("#sdevs_renewal_cart_tr").show();
32 jQuery("#subscrpt_stripe_auto_renew_tr").hide();
33 jQuery("#subscrpt_auto_renewal_toggle_tr").hide();
34 } else {
35 jQuery("#sdevs_renewal_cart_tr").hide();
36 jQuery("#subscrpt_stripe_auto_renew_tr").show();
37 jQuery("#subscrpt_auto_renewal_toggle_tr").show();
38 }
39 });
40 if (subscrpt_renewal_process.val() === "manual") {
41 jQuery("#sdevs_renewal_cart_tr").show();
42 jQuery("#subscrpt_stripe_auto_renew_tr").hide();
43 jQuery("#subscrpt_auto_renewal_toggle_tr").hide();
44 } else {
45 jQuery("#sdevs_renewal_cart_tr").hide();
46 jQuery("#subscrpt_stripe_auto_renew_tr").show();
47 jQuery("#subscrpt_auto_renewal_toggle_tr").show();
48 }
49
50 // Handle "select all" checkbox for subscription list
51 jQuery("#cb-select-all-1").on("change", function () {
52 jQuery('input[name="subscription_ids[]"]').prop("checked", this.checked);
53 });
54
55 // Update "select all" checkbox when individual checkboxes change
56 jQuery('input[name="subscription_ids[]"]').on("change", function () {
57 var totalCheckboxes = jQuery('input[name="subscription_ids[]"]').length;
58 var checkedCheckboxes = jQuery('input[name="subscription_ids[]"]:checked').length;
59
60 if (checkedCheckboxes === 0) {
61 jQuery("#cb-select-all-1").prop("indeterminate", false).prop("checked", false);
62 } else if (checkedCheckboxes === totalCheckboxes) {
63 jQuery("#cb-select-all-1").prop("indeterminate", false).prop("checked", true);
64 } else {
65 jQuery("#cb-select-all-1").prop("indeterminate", true);
66 }
67 });
68
69 // Handle bulk action form submission
70 jQuery("#subscriptions-form").on("submit", function (e) {
71 // Check if this is a bulk action submission by checking the submitter
72 var submitter = e.originalEvent ? e.originalEvent.submitter : null;
73 var isBulkAction = submitter && (submitter.name === "bulk_action" || submitter.name === "bulk_action2");
74
75 if (!isBulkAction) {
76 // This is a filter submission, allow it to proceed
77 return true;
78 }
79
80 // Prevent default form submission for bulk actions
81 e.preventDefault();
82
83 // Support both native <select> and hidden <input> (adv-select component)
84 var action = jQuery('[name="action"]').val();
85 var action2 = jQuery('[name="action2"]').val();
86 var selectedAction = action && action !== "-1" ? action : action2;
87
88 if (!selectedAction || selectedAction === "-1") {
89 alert("Please select a bulk action.");
90 return false;
91 }
92
93 var checkedBoxes = jQuery('input[name="subscription_ids[]"]:checked');
94 if (checkedBoxes.length === 0) {
95 alert("Please select at least one subscription.");
96 return false;
97 }
98
99 // Handle bulk action via AJAX (confirm already handled by adv-select data-confirm)
100 handleBulkAction(selectedAction, checkedBoxes);
101 });
102
103 // AJAX function to handle bulk actions
104 function handleBulkAction(action, checkedBoxes) {
105 var subscriptionIds = [];
106 checkedBoxes.each(function () {
107 subscriptionIds.push(jQuery(this).val());
108 });
109
110 // Show loading state
111 var submitButton = jQuery('input[name="bulk_action"]:focus, input[name="bulk_action2"]:focus');
112 var originalText = submitButton.val();
113 submitButton.val("Processing...").prop("disabled", true);
114
115 // Make AJAX request
116 jQuery.ajax({
117 url: wp_subscription_ajax.ajaxurl,
118 type: "POST",
119 data: {
120 action: "subscrpt_bulk_action",
121 bulk_action: action,
122 subscription_ids: subscriptionIds,
123 nonce: wp_subscription_ajax.nonce,
124 },
125 success: function (response) {
126 if (response.success) {
127 // Show success message
128 showAdminNotice(response.data.message, "success");
129 // Reload the page to reflect changes
130 setTimeout(function () {
131 window.location.reload();
132 }, 1000);
133 } else {
134 // Show error message
135 showAdminNotice(response.data.message || "An error occurred while processing the bulk action.", "error");
136 }
137 },
138 error: function () {
139 showAdminNotice("An error occurred while processing the bulk action.", "error");
140 },
141 complete: function () {
142 // Reset button state
143 submitButton.val(originalText).prop("disabled", false);
144 },
145 });
146 }
147
148 // Function to show admin notices
149 function showAdminNotice(message, type) {
150 var noticeClass = type === "success" ? "notice-success" : "notice-error";
151 var notice = jQuery('<div class="notice ' + noticeClass + ' is-dismissible"><p>' + message + "</p></div>");
152
153 // Insert notice at the top of the page
154 jQuery(".wp-subscription-admin-content").prepend(notice);
155
156 // Auto-dismiss after 5 seconds
157 setTimeout(function () {
158 notice.fadeOut(function () {
159 jQuery(this).remove();
160 });
161 }, 5000);
162 }
163 });
164
165 function hellochange(index) {
166 if (document.getElementById("subscrpt_enable[" + index + "]").checked) {
167 jQuery(".show_if_subscription_" + index).show();
168 } else {
169 jQuery(".show_if_subscription_" + index).hide();
170 }
171 }
172
173 let subscrpt_product_type = jQuery("#product-type");
174 let latest_value_of_subscrpt_product_type = subscrpt_product_type.val();
175
176 subscrpt_product_type.change(() => {
177 if (
178 "simple" === latest_value_of_subscrpt_product_type &&
179 "simple" !== subscrpt_product_type.val() &&
180 "variable" !== subscrpt_product_type.val()
181 ) {
182 const confirmTypeChange = confirm(
183 "Are you sure to change the product type ? If product type changed then You'll lose related subscriptions beacuse of they can't be renewed !",
184 );
185 if (confirmTypeChange) {
186 latest_value_of_subscrpt_product_type = subscrpt_product_type.val();
187 } else {
188 subscrpt_product_type.val("simple");
189 }
190 }
191 });
192