zoho_admin_order_ajax.js
159 lines
| 1 | /** |
| 2 | * @description function for making ajax call. |
| 3 | * @param {string} action_type - Action for which we call ajax |
| 4 | */ |
| 5 | function zoho_admin_order_ajax(data, nonce) { |
| 6 | |
| 7 | let action_name = 'zoho_admin_order_sync'; |
| 8 | var data = { |
| 9 | 'action': action_name, |
| 10 | 'arg_order_data': data, |
| 11 | 'nonce': nonce |
| 12 | }; |
| 13 | |
| 14 | jQuery.post(ajaxurl, data, function (_data, status) { |
| 15 | console.log(status); |
| 16 | if (status === 'success') { |
| 17 | location.hash = 'synced'; |
| 18 | location.reload(); |
| 19 | } else { |
| 20 | Swal.fire({ |
| 21 | icon: 'error', |
| 22 | title: 'Oops...', |
| 23 | text: 'Something wrong. Please contact Support', |
| 24 | }); |
| 25 | } |
| 26 | }); |
| 27 | |
| 28 | } |
| 29 | |
| 30 | window.onload = function () { |
| 31 | if (location.hash == "#synced") { |
| 32 | swal("Check Order Notes", { |
| 33 | icon: "success", |
| 34 | }); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @description function for making ajax call of Product sync. |
| 40 | * @param {string} action_type - Action for which we call ajax |
| 41 | */ |
| 42 | function zoho_admin_product_ajax(post_id, nonce) { |
| 43 | // Perform the AJAX request |
| 44 | jQuery.ajax({ |
| 45 | url: ajaxurl, |
| 46 | method: 'POST', |
| 47 | data: { |
| 48 | action: 'zoho_admin_product_sync', |
| 49 | post_id: post_id, |
| 50 | nonce: nonce |
| 51 | }, |
| 52 | success: function(response) { |
| 53 | // Handle success |
| 54 | console.log(response); |
| 55 | swal({ |
| 56 | icon: 'success', |
| 57 | title: 'Product sync successful!', |
| 58 | }); |
| 59 | location.reload(); |
| 60 | }, |
| 61 | error: function(error) { |
| 62 | // Handle error |
| 63 | console.log(error); |
| 64 | location.reload(); |
| 65 | } |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * @description function for making ajax call of Product unmapping. |
| 72 | * @param {string} productId - product Id |
| 73 | */ |
| 74 | function zoho_admin_unmap_product_ajax(productId, nonce) { |
| 75 | |
| 76 | let action_name = 'zi_product_unmap_hook'; |
| 77 | var data = { |
| 78 | 'action': action_name, |
| 79 | 'product_id': productId, |
| 80 | 'nonce': nonce |
| 81 | }; |
| 82 | |
| 83 | jQuery.post(ajaxurl, data, function (_data, status) { |
| 84 | console.log(status); |
| 85 | if (status === 'success') { |
| 86 | location.reload(); |
| 87 | } else { |
| 88 | swal({ |
| 89 | icon: 'error', |
| 90 | title: 'Oops...', |
| 91 | text: status, |
| 92 | }); |
| 93 | } |
| 94 | }); |
| 95 | |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @description function for making ajax call of Customer unmapping. |
| 100 | * @param {string} orderId - order Id |
| 101 | */ |
| 102 | function zoho_admin_customer_unmap(orderId, nonce) { |
| 103 | |
| 104 | let action_name = 'zi_customer_unmap_hook'; |
| 105 | var data = { |
| 106 | 'action': action_name, |
| 107 | 'order_id': orderId, |
| 108 | 'nonce': nonce |
| 109 | }; |
| 110 | |
| 111 | jQuery.post(ajaxurl, data, function (_data, status) { |
| 112 | console.log(status); |
| 113 | if (status === 'success') { |
| 114 | location.reload(); |
| 115 | } else { |
| 116 | swal({ |
| 117 | icon: 'error', |
| 118 | title: 'Oops...', |
| 119 | text: status, |
| 120 | }); |
| 121 | } |
| 122 | }); |
| 123 | |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * All code related to ReviewRequestNotice |
| 128 | */ |
| 129 | function cmbirdHideReviewRequestNotice(elem){ |
| 130 | var wrapper = jQuery(elem).closest('div.thpladmin-notice'); |
| 131 | var nonce = wrapper.data("nonce"); |
| 132 | var data = { |
| 133 | cmbird_security_review_notice: nonce, |
| 134 | action: 'skip_cmbird_review_request_notice', |
| 135 | }; |
| 136 | jQuery.post( ajaxurl, data, function(_data, status) { |
| 137 | console.log(status); |
| 138 | |
| 139 | }); |
| 140 | jQuery(wrapper).hide(50); |
| 141 | }; |
| 142 | |
| 143 | jQuery( document ).on( 'click', '.thpladmin-notice .notice-dismiss', function($) { |
| 144 | var wrapper = $(this).closest('div.thpladmin-notice'); |
| 145 | var nonce = wrapper.data("cmbird_review_request_notice"); |
| 146 | var data = { |
| 147 | cmbird_security_review_notice: nonce, |
| 148 | action: 'dismiss_cmbird_review_request_notice', |
| 149 | }; |
| 150 | $.post( ajaxurl, data, function() { |
| 151 | |
| 152 | }); |
| 153 | }) |
| 154 | |
| 155 | jQuery(document).ready(function($){ |
| 156 | setTimeout(function(){ |
| 157 | $("#cmbird_review_request_notice").fadeIn(500); |
| 158 | }, 2000); |
| 159 | }); |