Finalize the backend for each coupon, customer and access functionalities
This commit is contained in:
@@ -1,49 +1,3 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const choices = new Choices('#products', {
|
||||
searchEnabled: true,
|
||||
searchChoices: false, // Prevent Choices.js from filtering the local list
|
||||
searchResultLimit: 10, // Optional: Limit visible results
|
||||
placeholder: true,
|
||||
placeholderValue: formipay_coupons_page.filter_form.products.placeholder,
|
||||
noResultsText: formipay_coupons_page.filter_form.products.noresult_text,
|
||||
itemSelectText: '',
|
||||
});
|
||||
|
||||
const searchInput = document.querySelector('.choices__input--cloned');
|
||||
let typingTimer;
|
||||
|
||||
searchInput.addEventListener('input', function () {
|
||||
const query = searchInput.value;
|
||||
|
||||
if (query.length >= 3) {
|
||||
clearTimeout(typingTimer);
|
||||
typingTimer = setTimeout(() => {
|
||||
fetchChoices(query);
|
||||
}, 300); // Add a debounce delay
|
||||
}
|
||||
});
|
||||
|
||||
function fetchChoices(query) {
|
||||
fetch(formipay_coupons_page.ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'formipay_coupon_get_products',
|
||||
search: query,
|
||||
_wpnonce: formipay_coupons_page.nonce
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
choices.clearChoices();
|
||||
choices.setChoices(data, 'value', 'label', false);
|
||||
})
|
||||
.catch((error) => console.error('Error:', error));
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
let formipay_coupon_table_grid = new gridjs.Grid({
|
||||
@@ -56,7 +10,7 @@ jQuery(function($){
|
||||
}
|
||||
|
||||
return data.results.map(
|
||||
coupon => [coupon.ID, coupon.ID, coupon.code, coupon.products, coupon.value, coupon.type, coupon.usages, coupon.date_limit, coupon.status, coupon.case_sensitive]
|
||||
coupon => [coupon.ID, coupon.ID, coupon.code, coupon.value, coupon.type, coupon.usages, coupon.date_limit, coupon.status, coupon.case_sensitive]
|
||||
);
|
||||
},
|
||||
total: data => data.total
|
||||
@@ -83,40 +37,23 @@ jQuery(function($){
|
||||
</span>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_coupons_page.columns.products,
|
||||
formatter: (products, row) => {
|
||||
|
||||
let html = '';
|
||||
|
||||
// Loop through each product in the products array
|
||||
if(products.length > 0){
|
||||
products.forEach(product => {
|
||||
if (product) {
|
||||
const currencyDetails = product.currency.split(':::');
|
||||
const currencyCode = currencyDetails[0];
|
||||
const currencySymbol = currencyDetails[2];
|
||||
|
||||
html += `
|
||||
<span class="product_related">
|
||||
${product.title}<hr>
|
||||
<span class="country-currency">
|
||||
${product.flag ? `<img src="${product.flag}" height="18">` : ''}
|
||||
<span class="currency-in-use">${currencyCode} (${currencySymbol})</span>
|
||||
</span>
|
||||
</span>
|
||||
`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return gridjs.html(html);
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
name: formipay_coupons_page.columns.amount,
|
||||
formatter: (_, row) => numberFormat(_)
|
||||
formatter: (_, row) => {
|
||||
var amount = 'unset';
|
||||
if(row.cells[4].data === 'Percentage') {
|
||||
amount = numberFormat(_)+'%';
|
||||
}
|
||||
if(row.cells[4].data === 'Fixed'){
|
||||
amount = '';
|
||||
_.forEach(function(currency){
|
||||
const splitRaw = currency.raw.split(':::');
|
||||
const symbol = splitRaw[2] ? splitRaw[2] : splitRaw[0];
|
||||
amount += `<span class="coupon-each-amount"><img src="${currency.flag}" width="18"><span class="amount-value">${symbol} ${currency.amount}</span></span>`;
|
||||
})
|
||||
}
|
||||
return gridjs.html(amount);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: formipay_coupons_page.columns.type,
|
||||
@@ -215,16 +152,16 @@ jQuery(function($){
|
||||
function refresh_table_with_filter() {
|
||||
formipay_coupon_table_grid.updateConfig({
|
||||
server: {
|
||||
url: formipay_coupons_page.ajax_url+'?action=formipay-tabledata-coupons&product='+document.getElementById('products').value+'&search='+document.getElementById('keyword').value+'&_wpnonce='+formipay_coupons_page.nonce,
|
||||
url: formipay_coupons_page.ajax_url+'?action=formipay-tabledata-coupons&search='+document.getElementById('keyword').value+'&_wpnonce='+formipay_coupons_page.nonce,
|
||||
then: data => data.results.map(
|
||||
coupon => [coupon.ID, coupon.ID, coupon.code, coupon.products, coupon.value, coupon.type, coupon.usages, coupon.date_limit, coupon.status, coupon.case_sensitive]
|
||||
coupon => [coupon.ID, coupon.ID, coupon.code, coupon.value, coupon.type, coupon.usages, coupon.date_limit, coupon.status, coupon.case_sensitive]
|
||||
),
|
||||
total: data => data.total
|
||||
}
|
||||
}).forceRender();
|
||||
}
|
||||
|
||||
$('.form-tool, #products, #post_status').on('change', function(){
|
||||
$('.form-tool, #post_status').on('change', function(){
|
||||
refresh_table_with_filter();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user