first commit
This commit is contained in:
14
admin/assets/js/admin-all-post-type.js
Normal file
14
admin/assets/js/admin-all-post-type.js
Normal file
@@ -0,0 +1,14 @@
|
||||
jQuery(function($){
|
||||
|
||||
$('#wpbody-content').prepend(`
|
||||
<div class="formipay-screen-menu">
|
||||
<img src="`+formipay_admin.site_url+`/wp-content/plugins/formipay/admin/assets/img/formipay-logo-circle-white_256.png" alt="Formipay">
|
||||
<div class="screen-title">
|
||||
<h1>`+formipay_admin.page_title+`</h1>
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
$('form.search-form.wp-clearfix').appendTo('.tablenav.top');
|
||||
$('.wp-heading-inline, .page-title-action').hide();
|
||||
|
||||
});
|
||||
78
admin/assets/js/admin-customers.js
Normal file
78
admin/assets/js/admin-customers.js
Normal file
@@ -0,0 +1,78 @@
|
||||
jQuery(function($){
|
||||
|
||||
let formipay_table_grid = new gridjs.Grid({
|
||||
server: {
|
||||
url: formipay_customers_page.ajax_url+'?action=formipay-tabledata-customers&limit='+document.getElementById('limit').value+'&keyword='+document.getElementById('keyword').value,
|
||||
then: data => {
|
||||
|
||||
// if(data.posts_report){
|
||||
// processPostsReport(data.posts_report);
|
||||
// }
|
||||
|
||||
return data.results.map(
|
||||
form => [form.ID, form.name, form.email, form.phone, form.total_order]
|
||||
);
|
||||
},
|
||||
total: data => data.total
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
name: formipay_customers_page.columns.id,
|
||||
width: '75px'
|
||||
},
|
||||
{
|
||||
name: formipay_customers_page.columns.name,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<b>${_}</b>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_customers_page.columns.email,
|
||||
},
|
||||
{
|
||||
name: formipay_customers_page.columns.phone,
|
||||
},
|
||||
{
|
||||
name: formipay_customers_page.columns.total_order,
|
||||
formatter: (total_order, row) => gridjs.html(`<span class="status-label ${total_order}">${total_order}</span>`)
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
limit: document.getElementById('limit').value,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
|
||||
},
|
||||
summary: false
|
||||
},
|
||||
className: {
|
||||
table: 'formipay-grid-table'
|
||||
}
|
||||
}).render(document.getElementById('formipay-customers'));
|
||||
|
||||
$('#limit, #keyword').on('change', function(){
|
||||
formipay_table_grid.updateConfig({
|
||||
server: {
|
||||
url: formipay_customers_page.ajax_url+'?action=formipay-tabledata-customers&limit='+document.getElementById('limit').value+'&keyword='+document.getElementById('keyword').value,
|
||||
then: data => data.results.map(
|
||||
form => [form.ID, form.name, form.email, form.phone, form.total_order]
|
||||
),
|
||||
total: data => data.total
|
||||
},
|
||||
pagination: {
|
||||
limit: document.getElementById('limit').value,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
|
||||
},
|
||||
summary: false
|
||||
},
|
||||
}).forceRender();
|
||||
});
|
||||
|
||||
$(document).on('mouseover', 'td[data-column-id=form]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'visible');
|
||||
});
|
||||
$(document).on('mouseleave', 'td[data-column-id=form]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'hidden');
|
||||
});
|
||||
|
||||
});
|
||||
946
admin/assets/js/admin-editor.js
Normal file
946
admin/assets/js/admin-editor.js
Normal file
@@ -0,0 +1,946 @@
|
||||
jQuery(function($){
|
||||
|
||||
let wpcftoLoaded = false;
|
||||
|
||||
var checkWpcftoLoaded = setInterval(() => {
|
||||
const container = $('.wpcfto-tab');
|
||||
if(container.length > 0){
|
||||
wpcftoLoaded = true;
|
||||
$(document).trigger('wpcftoLoaded');
|
||||
clearInterval(checkWpcftoLoaded);
|
||||
}
|
||||
}, 250);
|
||||
|
||||
$(document).on('wpcftoLoaded', function(){
|
||||
update_option_to_data_mapping('initial');
|
||||
});
|
||||
|
||||
function all_active_payments() {
|
||||
|
||||
var items = $('.payment_gateways #active .list-group-item');
|
||||
var active_payments = [];
|
||||
|
||||
if(items.length > 0){
|
||||
$.each(items, function(i, item){
|
||||
var gateway = $(item).attr('id');
|
||||
if(gateway.indexOf(':::') !== -1){
|
||||
gateway = gateway.split(':::')[0];
|
||||
gateway = gateway.replace('_', '-');
|
||||
}
|
||||
// $('[data-submenu=payments_'+gateway+']').show();
|
||||
active_payments.push(gateway);
|
||||
});
|
||||
}
|
||||
|
||||
return active_payments;
|
||||
|
||||
}
|
||||
|
||||
function hide_inactive_payment_submenu() {
|
||||
|
||||
var div = $('[data-section=payments]').siblings('.wpcfto-submenus').find('[data-submenu]:not([data-submenu=payments_general])');
|
||||
var active_payments = all_active_payments();
|
||||
|
||||
if(div.length > 0) {
|
||||
$.each(div, function(x, y){
|
||||
var gateway = $(y).attr('data-submenu').replace('payments_', '');
|
||||
if(jQuery.inArray(gateway, active_payments) !== -1){
|
||||
$(y).slideDown();
|
||||
}else{
|
||||
$(y).slideUp();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
hide_inactive_payment_submenu();
|
||||
}, 1000);
|
||||
|
||||
|
||||
$(document).on('mouseleave', '.payment_gateways .list-group', function(){
|
||||
|
||||
hide_inactive_payment_submenu();
|
||||
|
||||
});
|
||||
|
||||
$(document).on('click', '.formipay-editor-nav .nav-link', function(){
|
||||
$('.formipay-editor-nav').find('.nav-link').removeClass('active');
|
||||
$(this).addClass('active');
|
||||
$('.formipay-editor-tab-content.nav-content-section').addClass('d-none');
|
||||
var tab_content = $(this).data('tab-content');
|
||||
$('.formipay-editor-tab-content'+tab_content).removeClass('d-none');
|
||||
});
|
||||
|
||||
$('.formipay-editor-nav .nav-item:first-child > .nav-link').trigger('click');
|
||||
|
||||
$(document).on('click', '#is_required', function(){
|
||||
if($(this).is(':checked')) {
|
||||
$(this).val('yes');
|
||||
}else{
|
||||
$(this).val('no');
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('blur change', '#add_field_form .field select.form-select', function(){
|
||||
var array = ['divider', 'page_break'];
|
||||
if( $.inArray( $(this).val(), array ) !== -1 ) {
|
||||
$('#add_field_form .field:not(.main-field)').slideUp();
|
||||
}else{
|
||||
$('#add_field_form .field:not(.main-field):not(.has-conditional)').slideDown();
|
||||
}
|
||||
});
|
||||
|
||||
function formipay_sortable(){
|
||||
$('#preview-wrapper').sortable({
|
||||
opacity: 0.75,
|
||||
items: '> .preview-field',
|
||||
handle: 'span.grab',
|
||||
change: function(event, ui) {
|
||||
ui.placeholder.css({
|
||||
visibility: 'visible',
|
||||
border : '2px dashed #8c8f94',
|
||||
borderRadius: '10px'
|
||||
});
|
||||
},
|
||||
stop: function(event, ui){
|
||||
update_option_to_data_mapping('update');
|
||||
}
|
||||
});
|
||||
$('.repeater-child-wrapper').sortable({
|
||||
opacity: 0.75,
|
||||
items: '> .repeater-child-input',
|
||||
handle: 'span.grab',
|
||||
change: function(event, ui) {
|
||||
ui.placeholder.css({
|
||||
visibility: 'visible',
|
||||
border : '2px dashed #cccccc',
|
||||
borderRadius: '5px'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
formipay_sortable();
|
||||
|
||||
$(document).on('change blur', '#add_field_form [name=label]', function(){
|
||||
$('#add_field_form [name=field_id]').val($(this).val().toLowerCase().replace(' ', '_'));
|
||||
});
|
||||
|
||||
$(document).on('click', '.add-option', function(e){
|
||||
e.preventDefault();
|
||||
var content = $(this).closest('.repeater-child-input').html();
|
||||
$(this).closest('.repeater-child-wrapper').append(`
|
||||
<div class="repeater-child-input d-flex justify-content-start align-items-start gap-2 my-2">`+content+`
|
||||
</div>`);
|
||||
$('.repeater-child-input:last-child').find('input').val('');
|
||||
$('.repeater-child-input:last-child').find('.add-thumbnail').removeClass('text-info').addClass('text-white');
|
||||
});
|
||||
|
||||
$(document).on('click', '.delete-option', function(e){
|
||||
e.preventDefault();
|
||||
$(this).closest('.repeater-child-input').remove();
|
||||
});
|
||||
|
||||
$(document).on('click', 'input.option-field-toggle', function(){
|
||||
var target = $(this).attr('data-child-field');
|
||||
if($(this).is(':checked')){
|
||||
$('.child-field-'+target).show();
|
||||
}else{
|
||||
$('.child-field-'+target).hide();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '#add_field_form .formipay-builder-field:not(.formipay-builder-option-field, [type=checkbox], [type=checkbox])', function(){
|
||||
var value = $(this).val();
|
||||
var name = $(this).attr('name');
|
||||
var the_dependent = $('#add_field_form [data-if-'+name+']');
|
||||
if('' !== value && the_dependent.length > 0){
|
||||
// var all_dependents = $('.has-conditional');
|
||||
$.each(the_dependent, function(x, y){
|
||||
var decoded_value = JSON.parse($(y).attr('data-if-'+name));
|
||||
if($.inArray(value, decoded_value) !== -1){
|
||||
$(y).slideDown();
|
||||
}else{
|
||||
$(y).slideUp();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '.add-field', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var option_image_toggle = 'no';
|
||||
if($('#repeater-child-0_thumbnail').is(':checked')){
|
||||
option_image_toggle = 'yes';
|
||||
}
|
||||
var option_value_toggle = 'no';
|
||||
if($('#repeater-child-2_value').is(':checked')){
|
||||
option_value_toggle = 'yes';
|
||||
}
|
||||
var option_amount_toggle = 'no';
|
||||
if($('#repeater-child-3_amount').is(':checked')){
|
||||
option_amount_toggle = 'yes';
|
||||
}
|
||||
|
||||
var setup = {
|
||||
'label' : $('#add_field_form [name=label]').val(),
|
||||
'field_id' : $('#add_field_form [name=field_id]').val(),
|
||||
'field_type' : $('#add_field_form [name=field_type]').val(),
|
||||
'options_type' : $('#add_field_form [name=options_type]').val(),
|
||||
'placeholder' : $('#add_field_form [name=placeholder]').val(),
|
||||
'default_value' : $('#add_field_form [name=default_value]').val(),
|
||||
'description' : $('#add_field_form [name=description]').val(),
|
||||
'is_required' : $('#add_field_form [name=is_required]').val(),
|
||||
'show_toggle' : {
|
||||
'image' : option_image_toggle,
|
||||
'value' : option_value_toggle,
|
||||
'amount': option_amount_toggle
|
||||
},
|
||||
'layout' : $('#option_grid_columns').val()
|
||||
};
|
||||
|
||||
var options = [];
|
||||
var calculable_field = ['select', 'radio', 'checkbox'];
|
||||
if($.inArray(setup.field_type, calculable_field) !== -1){
|
||||
var single_option = $('.repeater-child-input');
|
||||
if(single_option.length > 0){
|
||||
$.each(single_option, function(a, b){
|
||||
var check_qty;
|
||||
if($(b).find('.repeater-child-input-qty').is(':checked')){
|
||||
check_qty = 'yes';
|
||||
}else{
|
||||
check_qty = 'no';
|
||||
}
|
||||
var option = {
|
||||
'image_id': $(b).find('.field-image-id').val(),
|
||||
'image_url': $(b).find('.field-image-url').val(),
|
||||
'label': $(b).find('.repeater-child-input-label').find('input').val(),
|
||||
'value': $(b).find('.repeater-child-input-value').find('input').val(),
|
||||
'amount': $(b).find('.repeater-child-input-amount').find('input').val(),
|
||||
'weight': $(b).find('.repeater-child-input-weight').find('input').val(),
|
||||
'qty': check_qty
|
||||
}
|
||||
options.push(option);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setup.field_options = options;
|
||||
|
||||
// console.log(setup);
|
||||
|
||||
var setup_string = JSON.stringify(setup);
|
||||
var not_input = ['select', 'checkbox', 'radio'];
|
||||
var is_required = '';
|
||||
var asterisk = '';
|
||||
if(setup.is_required == 'yes'){
|
||||
is_required = '';
|
||||
asterisk = ' <span style="color:red;">(*)</span>';
|
||||
}
|
||||
var hidden = '';
|
||||
if(setup.field_type == 'hidden'){
|
||||
hidden = ' style="opacity: .75;"'
|
||||
}
|
||||
if(!setup.calc_value){
|
||||
setup.calc_value = 0;
|
||||
}
|
||||
|
||||
var preview_content = '';
|
||||
if($.inArray(setup.field_type, not_input) == -1){
|
||||
if($.inArray(setup.field_type, ['divider', 'page_break']) !== -1){
|
||||
preview_content = `
|
||||
<div class="formipay-field w-100"`+hidden+`>
|
||||
<div class="d-flex justify-content-between field-controls">
|
||||
<label for="`+setup.field_id+`" class="label-`+setup.field_type+`">`+setup.label+`</label>
|
||||
<div class="field-icons d-flex gap-2 align-items-center the_buttons">
|
||||
<button class="btn btn-sm edit-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M5 19h1.425L16.2 9.225L14.775 7.8L5 17.575zm-2 2v-4.25L16.2 3.575q.3-.275.663-.425t.762-.15t.775.15t.65.45L20.425 5q.3.275.438.65T21 6.4q0 .4-.137.763t-.438.662L7.25 21zM19 6.4L17.6 5zm-3.525 2.125l-.7-.725L16.2 9.225z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-sm delete-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M7 21q-.825 0-1.412-.587T5 19V6H4V4h5V3h6v1h5v2h-1v13q0 .825-.587 1.413T17 21zm2-4h2V8H9zm4 0h2V8h-2z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="`+setup.field_id+`_config" class="formipay-field-setup" value='`+setup_string+`'>
|
||||
<span class="divider-line"></span>
|
||||
<p class="formipay-inline-desc">`+setup.description+`</p>
|
||||
</div>`;
|
||||
}else if(setup.field_type == 'country_list') {
|
||||
var country_json = formipay_admin.preset.country_list;
|
||||
// Check if country_json is a string (indicating it might need to be parsed)
|
||||
if (typeof country_json === 'string') {
|
||||
try {
|
||||
country_json = JSON.parse(country_json); // Parse the JSON string into an object
|
||||
} catch (e) {
|
||||
console.error('Error parsing JSON:', e); // Log any parsing errors
|
||||
country_json = []; // Fallback to an empty array
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the data type
|
||||
if (!Array.isArray(country_json)) {
|
||||
console.error('Expected an array but got:', country_json);
|
||||
country_json = []; // Fallback to an empty array if not an array
|
||||
}
|
||||
|
||||
var options_html = `<option>-- ${setup.placeholder}</option>`;
|
||||
|
||||
// Loop through each country object
|
||||
$.each(country_json, function(index, country) {
|
||||
// Assuming each country object has 'id' for the value and 'name' for the display text
|
||||
options_html += `<option value="${country.name}">${country.name}</option>`;
|
||||
});
|
||||
|
||||
preview_content = `
|
||||
<div class="formipay-field w-100"`+hidden+`>
|
||||
<div class="d-flex justify-content-between field-controls">
|
||||
<label for="`+setup.field_id+`">`+setup.label+asterisk+`</label>
|
||||
<div class="field-icons d-flex gap-2 align-items-center the_buttons">
|
||||
<button class="btn btn-sm edit-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M5 19h1.425L16.2 9.225L14.775 7.8L5 17.575zm-2 2v-4.25L16.2 3.575q.3-.275.663-.425t.762-.15t.775.15t.65.45L20.425 5q.3.275.438.65T21 6.4q0 .4-.137.763t-.438.662L7.25 21zM19 6.4L17.6 5zm-3.525 2.125l-.7-.725L16.2 9.225z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-sm delete-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M7 21q-.825 0-1.412-.587T5 19V6H4V4h5V3h6v1h5v2h-1v13q0 .825-.587 1.413T17 21zm2-4h2V8H9zm4 0h2V8h-2z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="`+setup.field_id+`_config" class="formipay-field-setup" value='`+setup_string+`'>
|
||||
<select id="`+setup.field_id+`" class="formipay-input formipay-form-field" `+is_required+`>
|
||||
`+options_html+`
|
||||
</select>
|
||||
<p class="formipay-inline-desc">`+setup.description+`</p>
|
||||
</div>`;
|
||||
}else if(setup.field_type !== 'textarea'){
|
||||
preview_content = `
|
||||
<div class="formipay-field w-100"`+hidden+`>
|
||||
<div class="d-flex justify-content-between field-controls">
|
||||
<label for="`+setup.field_id+`">`+setup.label+asterisk+`</label>
|
||||
<div class="field-icons d-flex gap-2 align-items-center the_buttons">
|
||||
<button class="btn btn-sm edit-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M5 19h1.425L16.2 9.225L14.775 7.8L5 17.575zm-2 2v-4.25L16.2 3.575q.3-.275.663-.425t.762-.15t.775.15t.65.45L20.425 5q.3.275.438.65T21 6.4q0 .4-.137.763t-.438.662L7.25 21zM19 6.4L17.6 5zm-3.525 2.125l-.7-.725L16.2 9.225z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-sm delete-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M7 21q-.825 0-1.412-.587T5 19V6H4V4h5V3h6v1h5v2h-1v13q0 .825-.587 1.413T17 21zm2-4h2V8H9zm4 0h2V8h-2z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="`+setup.field_id+`_config" class="formipay-field-setup" value='`+setup_string+`'>
|
||||
<input type="`+setup.field_type+`" id="`+setup.field_id+`" class="formipay-input formipay-form-field" placeholder="`+setup.placeholder+`" data-calc-value="`+setup.calc_value+`" `+is_required+` />
|
||||
<p class="formipay-inline-desc">`+setup.description+`</p>
|
||||
</div>`;
|
||||
}else{
|
||||
preview_content = `
|
||||
<div class="formipay-field w-100"`+hidden+`>
|
||||
<div class="d-flex justify-content-between field-controls">
|
||||
<label for="`+setup.field_id+`">`+setup.label+asterisk+`</label>
|
||||
<div class="field-icons d-flex gap-2 align-items-center the_buttons">
|
||||
<button class="btn btn-sm edit-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M5 19h1.425L16.2 9.225L14.775 7.8L5 17.575zm-2 2v-4.25L16.2 3.575q.3-.275.663-.425t.762-.15t.775.15t.65.45L20.425 5q.3.275.438.65T21 6.4q0 .4-.137.763t-.438.662L7.25 21zM19 6.4L17.6 5zm-3.525 2.125l-.7-.725L16.2 9.225z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-sm delete-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M7 21q-.825 0-1.412-.587T5 19V6H4V4h5V3h6v1h5v2h-1v13q0 .825-.587 1.413T17 21zm2-4h2V8H9zm4 0h2V8h-2z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="`+setup.field_id+`_config" class="formipay-field-setup" value='`+setup_string+`'>
|
||||
<textarea rows="4" id="`+setup.field_id+`" class="formipay-input formipay-form-field" placeholder="`+setup.placeholder+`" data-calc-value="`+setup.calc_value+`" `+is_required+`></textarea>
|
||||
<p class="formipay-inline-desc">`+setup.description+`</p>
|
||||
</div>`;
|
||||
}
|
||||
}else{
|
||||
if(setup.field_type == 'select'){
|
||||
var options = setup.field_options;
|
||||
var options_html = '';
|
||||
if(setup.placeholder !== ''){
|
||||
options_html = '<option>'+setup.placeholder+'</option>';
|
||||
}
|
||||
$.each(options, function(j, k){
|
||||
var label = k.label;
|
||||
var value = label;
|
||||
if('' !== k.value && setup.show_toggle.value == 'yes'){
|
||||
value = k.value;
|
||||
}
|
||||
var calc = 0;
|
||||
if('' !== k.amount && setup.show_toggle.amount == 'yes'){
|
||||
calc = k.amount;
|
||||
}
|
||||
options_html += '<option value="'+value+'" data-calc-value="'+calc+'">'+label+'</option>';
|
||||
});
|
||||
preview_content = `
|
||||
<div class="formipay-field w-100"`+hidden+`>
|
||||
<div class="d-flex justify-content-between field-controls">
|
||||
<label for="`+setup.field_id+`">`+setup.label+asterisk+`</label>
|
||||
<div class="field-icons d-flex gap-2 align-items-center the_buttons">
|
||||
<button class="btn btn-sm edit-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M5 19h1.425L16.2 9.225L14.775 7.8L5 17.575zm-2 2v-4.25L16.2 3.575q.3-.275.663-.425t.762-.15t.775.15t.65.45L20.425 5q.3.275.438.65T21 6.4q0 .4-.137.763t-.438.662L7.25 21zM19 6.4L17.6 5zm-3.525 2.125l-.7-.725L16.2 9.225z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-sm delete-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M7 21q-.825 0-1.412-.587T5 19V6H4V4h5V3h6v1h5v2h-1v13q0 .825-.587 1.413T17 21zm2-4h2V8H9zm4 0h2V8h-2z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="`+setup.field_id+`_config" class="formipay-field-setup" value='`+setup_string+`'>
|
||||
<select id="`+setup.field_id+`" class="formipay-input formipay-form-field" `+is_required+`>
|
||||
`+options_html+`
|
||||
</select>
|
||||
<p class="formipay-inline-desc">`+setup.description+`</p>
|
||||
</div>`;
|
||||
}else{
|
||||
var options = setup.field_options;
|
||||
var options_html = '';
|
||||
$.each(options, function(j, k){
|
||||
var name = setup.field_id+`-`+j;
|
||||
if(setup.field_type == 'radio'){
|
||||
name = setup.field_id;
|
||||
}
|
||||
var label = k.label;
|
||||
var value = label;
|
||||
if('' !== k.value && setup.show_toggle.value == 'yes'){
|
||||
value = k.value;
|
||||
}
|
||||
var calc = 0;
|
||||
if('' !== k.amount && setup.show_toggle.amount == 'yes'){
|
||||
calc = k.amount;
|
||||
}
|
||||
var image = '';
|
||||
if('' !== k.image_id && '' !== k.image_url){
|
||||
image = `<img src="`+k.image_url+`" style="width: 100%; height: 150px; object-fit: contain;">`;
|
||||
}
|
||||
options_html +=
|
||||
`<div class="formipay-checkbox-group">
|
||||
`+image+`
|
||||
<input type="`+setup.field_type+`" id="`+setup.field_id+`-`+j+`" name="`+name+`" class="formipay-input formipay-form-field" value="`+k.value+`" />
|
||||
<label for="`+setup.field_id+`-`+j+`">`+k.label+`</label>
|
||||
</div>`;
|
||||
});
|
||||
if(setup.layout == ''){
|
||||
setup.layout = 1;
|
||||
}
|
||||
preview_content = `
|
||||
<div class="formipay-field w-100"`+hidden+`>
|
||||
<div class="d-flex justify-content-between field-controls">
|
||||
<label for="`+setup.field_id+`">`+setup.label+asterisk+`</label>
|
||||
<div class="field-icons d-flex gap-2 align-items-center the_buttons">
|
||||
<button class="btn btn-sm edit-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M5 19h1.425L16.2 9.225L14.775 7.8L5 17.575zm-2 2v-4.25L16.2 3.575q.3-.275.663-.425t.762-.15t.775.15t.65.45L20.425 5q.3.275.438.65T21 6.4q0 .4-.137.763t-.438.662L7.25 21zM19 6.4L17.6 5zm-3.525 2.125l-.7-.725L16.2 9.225z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="btn btn-sm delete-preview-field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M7 21q-.825 0-1.412-.587T5 19V6H4V4h5V3h6v1h5v2h-1v13q0 .825-.587 1.413T17 21zm2-4h2V8H9zm4 0h2V8h-2z" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="`+setup.field_id+`_config" class="formipay-field-setup" value='`+setup_string+`'>
|
||||
<div class="formipay-checkbox-wrapper" style="display: grid; grid-template-columns: repeat(`+setup.layout+`, 1fr); gap: 10px;">
|
||||
`+options_html+`
|
||||
</div>
|
||||
<p class="formipay-inline-desc">`+setup.description+`</p>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
var hidden = is_required = '';
|
||||
if(setup.type == 'hidden'){
|
||||
hidden = ' style="display: none;"';
|
||||
}
|
||||
if(setup.require == 'yes'){
|
||||
is_required = ' required';
|
||||
}
|
||||
|
||||
// Check if any
|
||||
|
||||
var edit_to = $('.add-field').attr('data-edit-to');
|
||||
var the_existed_field = $('.preview-field[data-field="'+edit_to+'"]');
|
||||
|
||||
if(the_existed_field.length > 0){
|
||||
$('.preview-field[data-field="'+edit_to+'"]').html(`
|
||||
<span class="grab pb-4">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M9 20q-.825 0-1.412-.587T7 18t.588-1.412T9 16t1.413.588T11 18t-.587 1.413T9 20m6 0q-.825 0-1.412-.587T13 18t.588-1.412T15 16t1.413.588T17 18t-.587 1.413T15 20m-6-6q-.825 0-1.412-.587T7 12t.588-1.412T9 10t1.413.588T11 12t-.587 1.413T9 14m6 0q-.825 0-1.412-.587T13 12t.588-1.412T15 10t1.413.588T17 12t-.587 1.413T15 14M9 8q-.825 0-1.412-.587T7 6t.588-1.412T9 4t1.413.588T11 6t-.587 1.413T9 8m6 0q-.825 0-1.412-.587T13 6t.588-1.412T15 4t1.413.588T17 6t-.587 1.413T15 8" />
|
||||
</svg>
|
||||
</span>
|
||||
`+preview_content+`
|
||||
`);
|
||||
}else{
|
||||
$('#preview-wrapper').append(`
|
||||
<div class="preview-field d-flex gap-2 align-items-center" data-field="`+setup.field_id+`" data-field-type="`+setup.field_type+`">
|
||||
<span class="grab pb-4">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="M9 20q-.825 0-1.412-.587T7 18t.588-1.412T9 16t1.413.588T11 18t-.587 1.413T9 20m6 0q-.825 0-1.412-.587T13 18t.588-1.412T15 16t1.413.588T17 18t-.587 1.413T15 20m-6-6q-.825 0-1.412-.587T7 12t.588-1.412T9 10t1.413.588T11 12t-.587 1.413T9 14m6 0q-.825 0-1.412-.587T13 12t.588-1.412T15 10t1.413.588T17 12t-.587 1.413T15 14M9 8q-.825 0-1.412-.587T7 6t.588-1.412T9 4t1.413.588T11 6t-.587 1.413T9 8m6 0q-.825 0-1.412-.587T13 6t.588-1.412T15 4t1.413.588T17 6t-.587 1.413T15 8" />
|
||||
</svg>
|
||||
</span>
|
||||
`+preview_content+`
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
|
||||
$('.preview-field[data-field="'+setup.field_id+'"]').attr('data-field-type', setup.field_type);
|
||||
|
||||
// scissors icon
|
||||
if(setup.field_type == 'page_break'){
|
||||
$('.preview-field[data-field="'+setup.field_id+'"]').append(`
|
||||
<span class="scissors">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="m12 14l-2.35 2.35q.2.375.275.8T10 18q0 1.65-1.175 2.825T6 22t-2.825-1.175T2 18t1.175-2.825T6 14q.425 0 .85.075t.8.275L10 12L7.65 9.65q-.375.2-.8.275T6 10q-1.65 0-2.825-1.175T2 6t1.175-2.825T6 2t2.825 1.175T10 6q0 .425-.075.85t-.275.8L20.6 18.6q.675.675.3 1.538T19.575 21q-.275 0-.537-.112t-.463-.313zm3-3l-2-2l5.575-5.575q.2-.2.463-.312T19.574 3q.95 0 1.313.875t-.313 1.55zM6 8q.825 0 1.413-.587T8 6t-.587-1.412T6 4t-1.412.588T4 6t.588 1.413T6 8m6 4.5q.2 0 .35-.15t.15-.35t-.15-.35t-.35-.15t-.35.15t-.15.35t.15.35t.35.15M6 20q.825 0 1.413-.587T8 18t-.587-1.412T6 16t-1.412.588T4 18t.588 1.413T6 20" />
|
||||
</svg>
|
||||
</span>
|
||||
`)
|
||||
}else{
|
||||
$('.preview-field[data-field="'+setup.field_id+'"] > span.scissors').remove();
|
||||
}
|
||||
|
||||
var builder_fields = $('#add_field_form').find('.formipay-builder-field');
|
||||
if(builder_fields.length > 0){
|
||||
$.each(builder_fields, function(a, b){
|
||||
if($(b).attr('type') == 'checkbox'){
|
||||
$(b).val('no').prop('checked', false);
|
||||
}else{
|
||||
$(b).val('');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('.repeater-child-input:not(:first-child)').remove();
|
||||
$('.repeater-child-input > input').val('');
|
||||
$('.repeater-child-input > .add-thumbnail').removeClass('text-info').addClass('text-white');
|
||||
$('.repeater-child-input .check-qty').prop('checked', false);
|
||||
$('#add_field_form .field.has-conditional').slideUp();
|
||||
|
||||
var all_option_toggle = $('.option-field-toggle');
|
||||
$.each(all_option_toggle, function(p, q){
|
||||
if($(q).is(':checked')){
|
||||
$(q).trigger('click');
|
||||
}
|
||||
});
|
||||
|
||||
$('.child-field-image-wrapper').find('img').attr('src', '').hide();
|
||||
$('.child-field-image-wrapper').find('i').attr('src', '').show();
|
||||
$('#add_field_form .field:not(.has-conditional)').show();
|
||||
$('[name=field_type]').val('text').change();
|
||||
$('.add-field').removeAttr('data-edit-to').text('Add Field');
|
||||
|
||||
formipay_sortable();
|
||||
|
||||
setTimeout(() => {
|
||||
update_option_to_data_mapping('update');
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
$(document).on('change', '#customer_data-buyer_allow_choose_country_code', function() {
|
||||
update_option_to_data_mapping('update');
|
||||
});
|
||||
|
||||
function update_option_to_data_mapping(initiation) {
|
||||
var fields = $('#preview-wrapper').find('input[type=hidden]');
|
||||
var options = [];
|
||||
$.each(fields, function(increment, field){
|
||||
var value = $(field).val();
|
||||
var config = JSON.parse(value);
|
||||
options.push(config);
|
||||
});
|
||||
var target = $('#customer_data').find('select');
|
||||
target.html('');
|
||||
target.append(`<option value="">${formipay_admin.config.datamapping.placeholder}</option>`);
|
||||
if(options.length > 0){
|
||||
$.each(options, function(increment, option){
|
||||
target.append(`<option value="${option.field_id}">${option.label}</option>`);
|
||||
});
|
||||
}
|
||||
if(initiation == 'initial'){
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_admin.ajax_url,
|
||||
data: {
|
||||
action: 'formipay_check_for_data_mapping_saved_value',
|
||||
post: $('#post_ID').val(),
|
||||
_wpnonce: formipay_admin.nonce
|
||||
},
|
||||
success: function(res) {
|
||||
$.each(res, function(name, value){
|
||||
if(value){
|
||||
$(`[name="${name}"]`).attr('data-current-value', value).val(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}else if(initiation == 'update'){
|
||||
$.each(target, function(increment, select){
|
||||
const current_value = $(select).attr('data-current-value');
|
||||
$(select).attr('data-current-value', current_value).val(current_value);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on('change', '#customer_data select', function() {
|
||||
var value = $(this).val();
|
||||
$(this).attr('data-current-value', value);
|
||||
});
|
||||
|
||||
$(document).on('click', '.delete-preview-field', function(e){
|
||||
e.preventDefault();
|
||||
$(this).parents('.preview-field').remove();
|
||||
update_option_to_data_mapping('update');
|
||||
});
|
||||
|
||||
$(document).on('click', '.edit-preview-field', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
// recondition all fields
|
||||
$('.option-field-toggle').prop('checked', false);
|
||||
$('.repeater-child-input:not(:first-child)').remove();
|
||||
$('.repeater-child-input:first-child').find('input').val('');
|
||||
// $('.repeater-child-input:first-child').find('.add-thumbnail').removeClass('text-info').addClass('text-white');
|
||||
|
||||
var setup = $(this).closest('.preview-field').find('.formipay-field-setup').val();
|
||||
setup = JSON.parse(setup);
|
||||
console.log(setup);
|
||||
$.each(setup, function(x, y){
|
||||
if(x == 'field_options'){
|
||||
if(y.length > 0){
|
||||
var first_repeater = $('.repeater-child-input:first-child')
|
||||
var repeater_template = first_repeater.html();
|
||||
var repeater_wrapper = $('.repeater-child-wrapper');
|
||||
$.each(y, function(p, q){
|
||||
repeater_wrapper.append(
|
||||
`<div class="repeater-child-input d-flex justify-content-start align-items-start gap-2 my-2">
|
||||
`+repeater_template+`
|
||||
</div>`);
|
||||
var repeater_target = $('.repeater-child-input:last-child');
|
||||
repeater_target.find('.the_title').text(q.label);
|
||||
repeater_target.find('.child-field-label').find('input').val(q.label);
|
||||
repeater_target.find('.child-field-value').find('input').val(q.value);
|
||||
repeater_target.find('.child-field-amount').find('input').val(q.amount);
|
||||
if(q.qty == 'yes'){
|
||||
repeater_target.find('.check-qty').val('yes').prop('checked', true);
|
||||
}else{
|
||||
repeater_target.find('.check-qty').val('no').prop('checked', false);
|
||||
}
|
||||
if('' !== q.image){
|
||||
repeater_target.find('.field-image-id').val(q.image_id);
|
||||
repeater_target.find('.field-image-url').val(q.image_url);
|
||||
repeater_target.find('img').attr('src', q.image_url).removeClass('d-none');
|
||||
repeater_target.find('.child-field-image').hide();
|
||||
// repeater_target.find('.add-thumbnail').removeClass('text-white').addClass('text-info');
|
||||
}
|
||||
repeater_target.show();
|
||||
first_repeater.hide();
|
||||
first_repeater.remove();
|
||||
});
|
||||
$('.repeater-child-input:first-child').find('.open-option');
|
||||
}
|
||||
}else if(x == 'layout'){
|
||||
$('#add_field_form [name="option_grid_columns"]').val(y);
|
||||
}else{
|
||||
$('#add_field_form [name="' + x + '"]').val(y);
|
||||
}
|
||||
});
|
||||
|
||||
$('#add_field_form [name=is_required]').prop('checked', setup.is_required === 'yes');
|
||||
// Handle show_toggle options
|
||||
if ('show_toggle' in setup) {
|
||||
|
||||
if(setup.show_toggle.image === 'yes'){
|
||||
$('#repeater-child-0_thumbnail').trigger('click');
|
||||
}
|
||||
if(setup.show_toggle.value === 'yes'){
|
||||
$('#repeater-child-2_value').trigger('click');
|
||||
}
|
||||
if(setup.show_toggle.amount === 'yes'){
|
||||
$('#repeater-child-3_amount').trigger('click');
|
||||
}
|
||||
}
|
||||
|
||||
formipay_sortable();
|
||||
// Trigger recondition and form change
|
||||
$('.formipay-builder-field[name=field_type]').trigger('change');
|
||||
|
||||
$('.add-field').attr('data-edit-to', setup.field_id).text('Edit Field');
|
||||
});
|
||||
|
||||
if( $('[name=daterange]').val() == '' ){
|
||||
$('[name=daterange]').daterangepicker({
|
||||
timePicker: true,
|
||||
startDate: moment().startOf('hour'),
|
||||
endDate: moment().startOf('hour').add(32, 'hour'),
|
||||
showDropdowns: true,
|
||||
timePicker24Hour: true,
|
||||
locale: {
|
||||
format: 'D-M-Y HH:mm'
|
||||
}
|
||||
});
|
||||
}else{
|
||||
$('[name=daterange]').daterangepicker({
|
||||
timePicker: true,
|
||||
showDropdowns: true,
|
||||
timePicker24Hour: true,
|
||||
locale: {
|
||||
format: 'D-M-Y HH:mm'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('click', '[role=switch]', function(){
|
||||
var id = $(this).attr('id');
|
||||
if($(this).is(':checked')){
|
||||
$('#add_field_form [data-if-'+id+'=active]').show();
|
||||
$(this).val('no');
|
||||
}else{
|
||||
$('#add_field_form [data-if-'+id+'=active]').hide();
|
||||
$(this).val('yes');
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click change', '#add_field_form [type=radio]', function(){
|
||||
var id = $(this).attr('name');
|
||||
var value = $(this).val();
|
||||
$('#add_field_form [data-if-'+id+']').hide();
|
||||
if($(this).is(':checked')){
|
||||
$('#add_field_form [data-if-'+id+'='+value+']').show();
|
||||
}
|
||||
});
|
||||
|
||||
$('[type=radio]').trigger('change');
|
||||
|
||||
$(document).on('change', '.config-dropdown', function(){
|
||||
var id = $(this).attr('id');
|
||||
var value = $(this).val();
|
||||
var attr_value = $('#add_field_form [data-if-'+id+']');
|
||||
|
||||
$('#add_field_form [data-if-'+id+']').hide();
|
||||
|
||||
if(attr_value.length > 0){
|
||||
$.each(attr_value, function(x,y){
|
||||
var this_attr_value = $(y).attr('data-if-'+id);
|
||||
if(this_attr_value.indexOf('::') !== -1){
|
||||
var split = this_attr_value.split('::');
|
||||
if($.inArray(value, split) !== -1){
|
||||
$(y).show();
|
||||
}
|
||||
}else{
|
||||
if(this_attr_value == value){
|
||||
$(y).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('.config-dropdown').trigger('change');
|
||||
|
||||
$(document).on('click', '.open-option', function(e){
|
||||
e.preventDefault();
|
||||
$(this).find('.bi').toggleClass('bi-arrow-up').toggleClass('bi-arrow-down');
|
||||
$(this).closest('.child-fields-wrapper').find('.child-field-wrapper').slideToggle();
|
||||
$(this).closest('.child-field-title').toggleClass('option-detail-opened');
|
||||
});
|
||||
|
||||
var all_checkbox = $('[type="checkbox"]');
|
||||
if(all_checkbox.length > 0){
|
||||
$.each(all_checkbox, function(a,b){
|
||||
if($(b).val() == 'yes'){
|
||||
$(b).val('no').trigger('click');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function modify_payment_box_behavior() {
|
||||
|
||||
var allbox = $('#payments multi_checkbox');
|
||||
var checkbox_input = $('.payments-payment input[type=checkbox]');
|
||||
var checked_value = [];
|
||||
if(checkbox_input.length > 0){
|
||||
$.each(checkbox_input, function(x, y){
|
||||
if($(y).is(':checked')){
|
||||
checked_value.push($(y).val());
|
||||
$('[data-field=wpcfto_addon_option_payment_'+$(y).val()+']').show();
|
||||
}else{
|
||||
$('[data-field=wpcfto_addon_option_payment_'+$(y).val()+']').hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
modify_payment_box_behavior();
|
||||
}, 500);
|
||||
|
||||
$(document).on('click', '.payments-payment input[type=checkbox]', function(){
|
||||
modify_payment_box_behavior();
|
||||
});
|
||||
|
||||
$(document).on('mouseover', 'span.grab', function(){
|
||||
$(this).css('pointer', 'grab');
|
||||
});
|
||||
|
||||
$(document).on('click', 'span.grab', function(){
|
||||
$(this).css('pointer', 'grabbing');
|
||||
});
|
||||
|
||||
$(document).on('change blur', '.child-field-label input.formipay-builder-field', function(){
|
||||
$(this).closest('.child-fields-wrapper').find('.the_title').text($(this).val());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
// setTimeout(() => {
|
||||
// var autocomplete_fields = $('.wpcfto-box .autocomplete');
|
||||
// if(autocomplete_fields.length > 0){
|
||||
// $.each(autocomplete_fields, function(increment, field){
|
||||
// var label = $(field).find('.wpcfto-field-aside__label').text();
|
||||
// var placeholder = formipay_admin.config.autocomplete.placeholder.replace('{field_label}', label);
|
||||
// var search_input = $(field).find('input');
|
||||
// search_input.attr('placeholder', placeholder);
|
||||
// search_input.parent().attr('data-input-placeholder', placeholder);
|
||||
// });
|
||||
// }
|
||||
// }, 1000);
|
||||
|
||||
// $(document).on('mouseleave blur focusout', '.wpcfto-autocomplete-search input', function(){
|
||||
// var placeholder = $(this).parent().attr('data-input-placeholder');
|
||||
// setTimeout(() => {
|
||||
// $(this).attr('placeholder', placeholder);
|
||||
// }, 500);
|
||||
// });
|
||||
|
||||
$( document ).on( 'click', '.add-thumbnail', function( event ) {
|
||||
|
||||
var gallery_items_frame;
|
||||
const $el = $( this );
|
||||
var target_field = $el.attr('data-field');
|
||||
var target_id = $el.siblings('.'+target_field+'-id');
|
||||
var target_url = $el.siblings('.'+target_field+'-url');
|
||||
var selected = target_id.val();
|
||||
var able_multiple = $el.attr('data-able-multiple');
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( gallery_items_frame ) {
|
||||
|
||||
// Select the attachment when the frame opens
|
||||
gallery_items_frame.on( 'open', function() {
|
||||
var selection = gallery_items_frame.state().get( 'selection' );
|
||||
selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] );
|
||||
});
|
||||
|
||||
// Open the modal.
|
||||
gallery_items_frame.open();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the media frame.
|
||||
gallery_items_frame = wp.media.frames.gallery_items = wp.media({
|
||||
// Set the title of the modal.
|
||||
title: 'Choose or upload media',
|
||||
button: {
|
||||
text: 'Select'
|
||||
},
|
||||
states: [
|
||||
new wp.media.controller.Library({
|
||||
title: 'Choose or upload media',
|
||||
filterable: 'all',
|
||||
multiple: able_multiple
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
// Select the attachment when the frame opens
|
||||
gallery_items_frame.on( 'open', function() {
|
||||
var selection = gallery_items_frame.state().get( 'selection' );
|
||||
selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] );
|
||||
});
|
||||
|
||||
gallery_items_frame.on( 'select', function() {
|
||||
attachment = gallery_items_frame.state().get('selection').first().toJSON();
|
||||
target_id.val( attachment.id );
|
||||
target_url.val( attachment.url );
|
||||
if(target_id.val() !== ''){
|
||||
// $el.removeClass('text-white').addClass('text-info d-none');
|
||||
if($el.hasClass('btn')){
|
||||
$el.siblings('i').hide();
|
||||
}else{
|
||||
$el.hide();
|
||||
}
|
||||
$el.siblings('img').removeClass('d-none').attr('src', attachment.url).show();
|
||||
}else{
|
||||
// $el.removeClass('text-info d-none').addClass('text-white');
|
||||
if($el.hasClass('btn')){
|
||||
$el.siblings('i').show();
|
||||
}else{
|
||||
$el.show();
|
||||
}
|
||||
$el.siblings('img').addClass('d-none').hide();
|
||||
}
|
||||
});
|
||||
|
||||
// Open the modal.
|
||||
gallery_items_frame.open();
|
||||
|
||||
});
|
||||
|
||||
$( document ).on( 'click', '.trumbowyg-button-group:has(.trumbowyg-insertImage-button)', function( event ) {
|
||||
|
||||
var gallery_items_frame;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// Create the media frame.
|
||||
gallery_items_frame = wp.media.frames.gallery_items = wp.media({
|
||||
// Set the title of the modal.
|
||||
title: 'Choose or upload media',
|
||||
button: {
|
||||
text: 'Select'
|
||||
},
|
||||
states: [
|
||||
new wp.media.controller.Library({
|
||||
title: 'Choose or upload media',
|
||||
filterable: 'all',
|
||||
multiple: false
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
gallery_items_frame.on( 'select', function() {
|
||||
attachment = gallery_items_frame.state().get('selection').first().toJSON();
|
||||
var target_input_url = $('.trumbowyg-modal.trumbowyg-fixed-top .trumbowyg-input-html input');
|
||||
var target_confirm = $('.trumbowyg-modal.trumbowyg-fixed-top .trumbowyg-modal-submit');
|
||||
target_input_url.val( attachment.url );
|
||||
target_confirm.trigger('click');
|
||||
|
||||
});
|
||||
|
||||
// Open the modal.
|
||||
gallery_items_frame.open();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
174
admin/assets/js/admin-handlebars.js
Normal file
174
admin/assets/js/admin-handlebars.js
Normal file
@@ -0,0 +1,174 @@
|
||||
jQuery(document).ready(function($) {
|
||||
|
||||
function getParam(key) {
|
||||
var paramsStr = window.location.search.substr(1, window.location.search.length),
|
||||
paramsArr = paramsStr.split("&"),
|
||||
items = [];
|
||||
|
||||
for (var i = 0; i < paramsArr.length; i++) {
|
||||
items[paramsArr[i].split("=")[0]] = paramsArr[i].split("=")[1];
|
||||
}
|
||||
|
||||
if (key != "" && key != undefined) {
|
||||
// return single
|
||||
if (items[key] != undefined) {
|
||||
return items[key];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// return all (array)
|
||||
return items;
|
||||
}
|
||||
};
|
||||
|
||||
if (getParam('post')){
|
||||
// Fetch data via AJAX
|
||||
$.ajax({
|
||||
url: formipay_admin.ajax_url, // WordPress AJAX URL
|
||||
method: 'GET',
|
||||
data: {
|
||||
action: 'fetch_formipay_settings',
|
||||
post_id: formipay_admin.form_id, // Assuming you have post ID available globally,
|
||||
_wpnonce: formipay_admin.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
var source = $("#preview-template").html();
|
||||
var template = Handlebars.compile(source);
|
||||
var context = {
|
||||
fields: response.data.fields
|
||||
};
|
||||
var html = template(context);
|
||||
$("#preview-wrapper").html(html);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch data via AJAX
|
||||
$.ajax({
|
||||
url: formipay_admin.ajax_url, // WordPress AJAX URL
|
||||
method: 'GET',
|
||||
data: {
|
||||
action: 'fetch_formipay_fields',
|
||||
},
|
||||
success: function(response) {
|
||||
var source = $("#add-field-form-template").html();
|
||||
var template = Handlebars.compile(source);
|
||||
var context = {
|
||||
fields: response.data.fields
|
||||
};
|
||||
var html = template(context);
|
||||
$("#add_field_form").html(html);
|
||||
$('#add_field_form .field select.form-select').trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
// Handlebars helper for comparing equality
|
||||
Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
|
||||
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
|
||||
});
|
||||
|
||||
// Handlebars helper for checking inequality
|
||||
Handlebars.registerHelper('ifNotEquals', function(arg1, arg2, options) {
|
||||
return (arg1 != arg2) ? options.fn(this) : options.inverse(this);
|
||||
});
|
||||
|
||||
// Handlebars helper for checking if a value is in a list
|
||||
Handlebars.registerHelper('ifIn', function(value, list, options) {
|
||||
return (list.split(' ').indexOf(value) > -1) ? options.fn(this) : options.inverse(this);
|
||||
});
|
||||
|
||||
// Handlebars helper for checking if a value is in a list
|
||||
Handlebars.registerHelper('ifNotIn', function(value, list, options) {
|
||||
return (list.split(' ').indexOf(value) > -1) ? options.inverse(this) : options.fn(this);
|
||||
});
|
||||
|
||||
// Handlebars helper for JSON stringify
|
||||
Handlebars.registerHelper('json', function(context) {
|
||||
return JSON.stringify(context);
|
||||
});
|
||||
|
||||
// Handlebars helper to concatenate custom classes
|
||||
Handlebars.registerHelper('custom_class', function(custom_class) {
|
||||
return (custom_class && Array.isArray(custom_class)) ? ' '+custom_class.join(' ') : '';
|
||||
});
|
||||
|
||||
// Handlebars helper to handle conditional classes and display properties
|
||||
Handlebars.registerHelper('conditional_class', function(conditional) {
|
||||
return (conditional && conditional.length > 0) ? ' has-conditional' : '';
|
||||
});
|
||||
|
||||
// Handlebars helper to return label class
|
||||
Handlebars.registerHelper('labelClass', function(fieldType) {
|
||||
return 'label-' + fieldType;
|
||||
});
|
||||
|
||||
// Handlebars helper to return name attribute for checkbox and radio inputs
|
||||
Handlebars.registerHelper('name', function(fieldType, fieldId, index) {
|
||||
return (fieldType == 'radio') ? fieldId : fieldId + '-' + index;
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('display', function(conditional) {
|
||||
var display = '';
|
||||
if (conditional) {
|
||||
display = ' style="display:none"';
|
||||
if (Array.isArray(conditional)) {
|
||||
conditional.forEach(function(cond) {
|
||||
display += ' data-if-' + cond.key + "='" + JSON.stringify(cond.value) + "'";
|
||||
});
|
||||
}
|
||||
}
|
||||
return display;
|
||||
});
|
||||
|
||||
// Handlebars helper to format option text
|
||||
Handlebars.registerHelper('formatOption', function(option) {
|
||||
return option.charAt(0).toUpperCase() + option.slice(1).replace('_', ' ');
|
||||
});
|
||||
|
||||
// Handlebars helper for toggle display property
|
||||
Handlebars.registerHelper('toggleDisplay', function(toggle) {
|
||||
return (toggle == 'yes') ? ' style="display:none;"' : '';
|
||||
});
|
||||
|
||||
// Handlebars helper for set grid column for checkbox and radio
|
||||
Handlebars.registerHelper('layoutColumn', function(layout) {
|
||||
return (layout !== '') ? layout : 1;
|
||||
});
|
||||
|
||||
// Handlebars helper for set the first option as selected
|
||||
Handlebars.registerHelper('selectedTheFirstOption', function(index) {
|
||||
return (index == 0) ? ' selected' : '';
|
||||
});
|
||||
|
||||
// Handlebars helper for set the first option as selected
|
||||
Handlebars.registerHelper('countryListOptions', function() {
|
||||
var country_json = formipay_admin.preset.country_list;
|
||||
// Check if country_json is a string (indicating it might need to be parsed)
|
||||
if (typeof country_json === 'string') {
|
||||
try {
|
||||
country_json = JSON.parse(country_json); // Parse the JSON string into an object
|
||||
} catch (e) {
|
||||
console.error('Error parsing JSON:', e); // Log any parsing errors
|
||||
country_json = []; // Fallback to an empty array
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the data type
|
||||
if (!Array.isArray(country_json)) {
|
||||
console.error('Expected an array but got:', country_json);
|
||||
country_json = []; // Fallback to an empty array if not an array
|
||||
}
|
||||
|
||||
var options_html = ``; // Initialize options_html variable
|
||||
|
||||
// Loop through each country object
|
||||
$.each(country_json, function(index, country) {
|
||||
// Assuming each country object has 'id' for the value and 'name' for the display text
|
||||
options_html += `<option value="${country.name}">${country.name}</option>`;
|
||||
});
|
||||
|
||||
return options_html;
|
||||
});
|
||||
|
||||
});
|
||||
430
admin/assets/js/admin-order-details.js
Normal file
430
admin/assets/js/admin-order-details.js
Normal file
@@ -0,0 +1,430 @@
|
||||
jQuery(function($){
|
||||
|
||||
Handlebars.registerHelper('ifEquals', function(arg1, arg2, options) {
|
||||
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
|
||||
});
|
||||
Handlebars.registerHelper('nameToTitle', function(arg) {
|
||||
var parse = arg.split('_');
|
||||
var output = [];
|
||||
$.each(parse, function( a, b ){
|
||||
if(b.length <= 3){
|
||||
output.push(b.toUpperCase());
|
||||
}else{
|
||||
output.push(b);
|
||||
}
|
||||
});
|
||||
return output.join(' ');
|
||||
});
|
||||
Handlebars.registerHelper('parsePaymentInfo', function(arg) {
|
||||
var explode = arg.split('-');
|
||||
var explode2 = explode[0].split(':::');
|
||||
var gateway = explode2[0].split('_').join(' ');
|
||||
var channel = explode2[1];
|
||||
return gateway + ' - ' + channel;
|
||||
});
|
||||
Handlebars.registerHelper('ifKeyExists', function(key, obj, options) {
|
||||
// Check if the key exists in the object
|
||||
if (obj && obj.hasOwnProperty(key)) {
|
||||
// If it exists, execute the block
|
||||
return options.fn(this);
|
||||
}
|
||||
// If it does not exist, execute the inverse block (if provided)
|
||||
return options.inverse(this);
|
||||
});
|
||||
|
||||
function ucWords(input) {
|
||||
return input
|
||||
.replace(/_/g, ' ') // Replace underscores with spaces
|
||||
.toLowerCase() // Convert entire string to lowercase first
|
||||
.replace(/^(.)/, function(char) { return char.toUpperCase(); }) // Capitalize the first letter of the first word
|
||||
.replace(/ (.)/g, function(char) { return char.toUpperCase(); }); // Capitalize the first letter after each space
|
||||
}
|
||||
|
||||
let order_id = $('#order_id').val();
|
||||
|
||||
function load_order_data() {
|
||||
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_order_details_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay_load_order_data',
|
||||
order: order_id,
|
||||
_wpnonce: formipay_order_details_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
console.log(res);
|
||||
var source = $("#order-item-row-template").html();
|
||||
var template = Handlebars.compile(source);
|
||||
var context = {
|
||||
items: res.items
|
||||
};
|
||||
var html = template(context);
|
||||
$("#order-items-table tbody").html(html);
|
||||
$('#order-total').html(res.total_formatted);
|
||||
$('#order_status').val(res.status);
|
||||
|
||||
var source = $("#form-data-item-template").html();
|
||||
var template = Handlebars.compile(source);
|
||||
var context = {
|
||||
datas: res.form_data
|
||||
};
|
||||
var html = template(context);
|
||||
$("#form-data-list").html(html);
|
||||
var editFormDataButton = $('.edit-transaction-data').attr('data-loaded-button-text');
|
||||
$('.edit-transaction-data').text(editFormDataButton).prop('disabled', false);
|
||||
|
||||
var source = $("#form-data-item-template").html();
|
||||
var template = Handlebars.compile(source);
|
||||
var meta_data = [];
|
||||
$.each(res.meta_data, function(index, meta){
|
||||
if(meta.name !== 'access_method' && meta.name !== 'access_password'){
|
||||
meta_data.push(meta);
|
||||
}
|
||||
});
|
||||
var context = {
|
||||
datas: meta_data
|
||||
};
|
||||
var html = template(context);
|
||||
$("#submission-detail-list").html(html);
|
||||
|
||||
var source = $("#notification-data-template").html();
|
||||
var template = Handlebars.compile(source);
|
||||
var context = {
|
||||
datas: res.notification.sort().reverse()
|
||||
};
|
||||
var html = template(context);
|
||||
$("#notification-list").html(html);
|
||||
|
||||
var source = $("#transaction-timeline-item").html();
|
||||
var template = Handlebars.compile(source);
|
||||
var context = {
|
||||
datas: res.transaction_timeline.sort().reverse()
|
||||
};
|
||||
var html = template(context);
|
||||
$("#transaction-list").html(html);
|
||||
|
||||
var passMethod = {
|
||||
'magic_link': 'Magic Link',
|
||||
'static_password': 'Static Password'
|
||||
}
|
||||
var source = $('#thankyou-access-template').html();
|
||||
var template = Handlebars.compile(source);
|
||||
var context = {
|
||||
data: {
|
||||
link: res.thankyou.link,
|
||||
pass_method: res.thankyou.pass_method,
|
||||
pass_method_label: passMethod[res.thankyou.pass_method],
|
||||
pass_word: res.thankyou.pass_word
|
||||
}
|
||||
};
|
||||
var html = template(context);
|
||||
$('#access-detail-list').html(html);
|
||||
$('#access_method').val(res.thankyou.pass_method).trigger('change');
|
||||
var editFormDataButton = $('.edit-access-data').attr('data-loaded-button-text');
|
||||
$('.edit-access-data').text(editFormDataButton).prop('disabled', false);
|
||||
if(res.thankyou.pass_method == 'static_password'){
|
||||
$('li.access-password p').text(res.thankyou.pass_word);
|
||||
$('li.access-password').removeClass('d-none');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function set_loading_button(selector, loadingText = '') {
|
||||
var buttonText = selector.text();
|
||||
selector.attr('data-button-text', buttonText);
|
||||
selector.prop('disabled', true);
|
||||
if(loadingText !== '') {
|
||||
selector.html(`
|
||||
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
|
||||
<span role="status">${loadingText}</span>
|
||||
`);
|
||||
}else{
|
||||
selector.html(`
|
||||
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
|
||||
<span class="visually-hidden" role="status">${loadingText}</span>
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
function remove_loading_button(selector) {
|
||||
var buttonText = selector.attr('data-button-text');
|
||||
selector.prop('disabled', false);
|
||||
selector.html(buttonText);
|
||||
}
|
||||
|
||||
load_order_data();
|
||||
|
||||
$(document).on('click', '.timeline-item-image', function(){
|
||||
var imageSrc = $(this).attr('src');
|
||||
$('#image-ligthbox img').attr('src', imageSrc);
|
||||
$('#image-ligthbox').modal('show');
|
||||
});
|
||||
|
||||
$('#order_status').on('change', function() {
|
||||
var status = $(this).val();
|
||||
var order_id = $(this).data('order-id');
|
||||
Swal.fire({
|
||||
html: formipay_order_details_page.order_detail.change_order_status_confirmation,
|
||||
icon: 'question',
|
||||
confirmButtonText: formipay_order_details_page.order_detail.change_order_status_button_confirm,
|
||||
cancelButtonText: formipay_order_details_page.order_detail.change_order_status_button_cancel,
|
||||
showCancelButton: true,
|
||||
reverseButtons: true
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_order_details_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay_change_order_status',
|
||||
id: order_id,
|
||||
status: status,
|
||||
_wpnonce: formipay_order_details_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
if(res.success){
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'success'
|
||||
});
|
||||
}else{
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('.edit-transaction-data').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var $this_button = $(this);
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_order_details_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay_check_editable_field',
|
||||
order_id: formipay_order_details_page.order_id,
|
||||
_wpnonce: formipay_order_details_page.nonce
|
||||
},
|
||||
beforeSend: function() {
|
||||
set_loading_button($this_button, formipay_order_details_page.order_detail.edit_button_loading_text);
|
||||
},
|
||||
success: function(res) {
|
||||
remove_loading_button($this_button);
|
||||
$('.edit-transaction-data').addClass('d-none');
|
||||
$('.update-transaction-buttons').removeClass('d-none');
|
||||
$.each(res, function(config, field_data){
|
||||
var field_id = field_data.field_id;
|
||||
var field_current_value = $(`[data-field-name=${field_id}]`).text();
|
||||
$(`[data-field-name=${field_id}]`).attr('data-current-value', field_current_value);
|
||||
|
||||
$(`[data-field-name=${field_id}]`).html(`
|
||||
<input type="${field_data.field_type}" name="${field_id}" value="${$.trim(field_current_value)}" class="form-control rounded border border-secondary-subtle">
|
||||
`);
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
$('.update-transaction-data').on('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var $this_button = $(this);
|
||||
var editable_inputs = $('#form-data-list').find('input');
|
||||
var editable_field_values = [];
|
||||
$.each(editable_inputs, function(i, input){
|
||||
var this_input = {
|
||||
name: $(input).attr('name'),
|
||||
value: $(input).val()
|
||||
}
|
||||
editable_field_values.push(this_input);
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_order_details_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay_update_editable_field_data',
|
||||
order_id: formipay_order_details_page.order_id,
|
||||
new_values: editable_field_values,
|
||||
_wpnonce: formipay_order_details_page.nonce
|
||||
},
|
||||
beforeSend: function() {
|
||||
set_loading_button($this_button, formipay_order_details_page.order_detail.update_button_loading_text);
|
||||
},
|
||||
success: function(res){
|
||||
remove_loading_button($this_button);
|
||||
if(res.success){
|
||||
$('.edit-transaction-data').removeClass('d-none');
|
||||
$('.update-transaction-buttons').addClass('d-none');
|
||||
$.each(editable_inputs, function(i, input){
|
||||
var new_value = $(input).val();
|
||||
$(input).parent().removeAttr('data-current-value');
|
||||
$(input).parent().text(new_value);
|
||||
});
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'success'
|
||||
});
|
||||
}else{
|
||||
$.each(editable_inputs, function(i, input){
|
||||
var current_value = $(input).parent().attr('data-current-value');
|
||||
$(input).val(current_value);
|
||||
});
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$('.cancel-transaction-data').on('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var editable_inputs = $('#form-data-list').find('input');
|
||||
$.each(editable_inputs, function(i, input){
|
||||
var current_value = $(input).parent().attr('data-current-value');
|
||||
$(input).parent().text(current_value);
|
||||
});
|
||||
$('.edit-transaction-data').removeClass('d-none');
|
||||
$('.update-transaction-buttons').addClass('d-none');
|
||||
|
||||
});
|
||||
|
||||
$('.edit-access-data').on('click', function(e){
|
||||
e.preventDefault();
|
||||
var $this_button = $(this);
|
||||
set_loading_button($this_button, formipay_order_details_page.order_detail.edit_button_loading_text);
|
||||
|
||||
var current_method = $('li.access-method').attr('data-access-method');
|
||||
$('li.access-method').find('p').after(`
|
||||
<select name="access_method" id="access_method" class="form-select w-100 rounded border border-secondary-subtle" data-order-id="${$('#order_id').val()}" style="max-width: unset;">
|
||||
<option value="magic_link" ${(current_method == 'magic_link') ? 'selected' : ''}>${formipay_order_details_page.order_detail.pass_method.magic_link}</option>
|
||||
<option value="static_password" ${(current_method == 'static_password') ? 'selected' : ''}>${formipay_order_details_page.order_detail.pass_method.static_password}</option>
|
||||
</select>
|
||||
`);
|
||||
$('#access_method').trigger('change');
|
||||
$('li.access-method').find('p').addClass('d-none');
|
||||
remove_loading_button($this_button);
|
||||
$('.edit-access-data').addClass('d-none');
|
||||
$('.update-access-buttons').removeClass('d-none');
|
||||
});
|
||||
|
||||
$(document).on('change', '#access_method', function(){
|
||||
var access_password_li = $(this).closest('li').siblings('.access-password');
|
||||
if($(this).val() == 'static_password'){
|
||||
var password = access_password_li.attr('data-access-password');
|
||||
access_password_li.removeClass('d-none');
|
||||
access_password_li.find('p').after(`
|
||||
<input type="text" id="access_password" class="form-control w-100 rounded border border-secondary-subtle" value="${ password}">
|
||||
`);
|
||||
access_password_li.find('p').addClass('d-none');
|
||||
}else{
|
||||
access_password_li.addClass('d-none');
|
||||
access_password_li.find('input').remove();
|
||||
}
|
||||
});
|
||||
|
||||
function normalize_access_data_card() {
|
||||
var accessMethod = $('li.access-method').attr('data-access-method');
|
||||
var accessPassword = $('li.access-password').attr('data-access-password');
|
||||
$('li.access-method select').remove();
|
||||
$('li.access-method p').removeClass('d-none');
|
||||
$('.edit-access-data').removeClass('d-none');
|
||||
$('.update-access-buttons').addClass('d-none');
|
||||
if( accessMethod == 'magic_link'){
|
||||
$('li.access-password').addClass('d-none');
|
||||
}
|
||||
$('li.access-method p').text(ucWords(accessMethod)).removeClass('d-none');
|
||||
$('li.access-password p').text(ucWords(accessPassword)).removeClass('d-none');
|
||||
$('li.access-password input').remove();
|
||||
}
|
||||
|
||||
$('.cancel-access-data').on('click', function(e){
|
||||
e.preventDefault();
|
||||
normalize_access_data_card();
|
||||
});
|
||||
|
||||
$('.update-access-data').on('click', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var $this_button = $(this);
|
||||
var this_method = $('#access_method').val();
|
||||
var this_password = $('#access_password').val()
|
||||
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_order_details_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay_update_digital_access',
|
||||
order_id: formipay_order_details_page.order_id,
|
||||
method: this_method,
|
||||
password: this_password,
|
||||
_wpnonce: formipay_order_details_page.nonce
|
||||
},
|
||||
beforeSend: function() {
|
||||
set_loading_button($this_button, formipay_order_details_page.order_detail.update_button_loading_text);
|
||||
},
|
||||
success: function(res){
|
||||
remove_loading_button($this_button);
|
||||
if(res.success){
|
||||
$('li.access-method').attr('data-access-method', this_method)
|
||||
if(this_method == 'static_password'){
|
||||
$('li.access-password').attr('data-access-password', this_password)
|
||||
}
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'success'
|
||||
});
|
||||
}else{
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
normalize_access_data_card();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$(document).on('click', '.formipay-copy-button', function(e) {
|
||||
e.preventDefault();
|
||||
var $this = $(this);
|
||||
var copiedtext = $(this).attr("data-copy-value");
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(copiedtext)
|
||||
.then(() => {
|
||||
$this.html('<i class="bi bi-check-circle-fill"></i> '+$this.attr('data-copied-text'));
|
||||
setTimeout(() => {
|
||||
$this.html('<i class="bi bi-copy"></i> '+$this.attr('data-copy-text'));
|
||||
}, 1200);
|
||||
})
|
||||
.catch((error) => {
|
||||
$this.html('<i class="bi bi-exclamation-circle-fill"></i> '+$this.attr('data-not-copied-text'));
|
||||
setTimeout(() => {
|
||||
$this.html('<i class="bi bi-copy"></i> '+$this.attr('data-copy-text'));
|
||||
}, 1200);
|
||||
});
|
||||
} else {
|
||||
$this.html('<i class="bi bi-check-circle-fill"></i> '+$this.attr('data-not-copied-text'));
|
||||
setTimeout(() => {
|
||||
$this.html('<i class="bi bi-copy"></i> '+$this.attr('data-copy-text'));
|
||||
}, 1200);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
256
admin/assets/js/admin-orders.js
Normal file
256
admin/assets/js/admin-orders.js
Normal file
@@ -0,0 +1,256 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const formChoices = 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_orders_page.filter_form.products.placeholder,
|
||||
noResultsText: formipay_orders_page.filter_form.products.noresult_text,
|
||||
itemSelectText: '',
|
||||
});
|
||||
|
||||
const currencyChoices = new Choices('#currencies', {
|
||||
searchEnabled: true,
|
||||
searchChoices: false, // Prevent Choices.js from filtering the local list
|
||||
searchResultLimit: 10, // Optional: Limit visible results
|
||||
placeholder: true,
|
||||
placeholderValue: formipay_orders_page.filter_form.currencies.placeholder,
|
||||
noResultsText: formipay_orders_page.filter_form.currencies.noresult_text,
|
||||
itemSelectText: '',
|
||||
allowHTML: true
|
||||
});
|
||||
|
||||
const searchInputs = document.querySelectorAll('.choices__input--cloned');
|
||||
let typingTimer;
|
||||
|
||||
searchInputs.forEach((searchInput) => {
|
||||
searchInput.addEventListener('input', function () {
|
||||
const query = searchInput.value;
|
||||
|
||||
if (query.length >= 3) {
|
||||
clearTimeout(typingTimer);
|
||||
typingTimer = setTimeout(() => {
|
||||
// Find the wrapper (e.g., .product or .currency)
|
||||
const parentWrapper = searchInput.closest('.product, .currency');
|
||||
let searchType = ''; // Initialize search type
|
||||
|
||||
// Determine the type based on the parent wrapper's class
|
||||
if (parentWrapper) {
|
||||
if (parentWrapper.classList.contains('product')) {
|
||||
searchType = 'form';
|
||||
} else if (parentWrapper.classList.contains('currency')) {
|
||||
searchType = 'currency';
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch choices with the determined type
|
||||
fetchChoices(query, searchType);
|
||||
}, 300); // Add a debounce delay
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function fetchChoices(query, type) {
|
||||
fetch(formipay_orders_page.ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'formipay_orders_get_choices',
|
||||
search: query,
|
||||
type: type, // Pass the type to the server,
|
||||
_wpnonce: formipay_orders_page.nonce
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
const currentChoices = type === 'form' ? formChoices : currencyChoices;
|
||||
|
||||
currentChoices.clearChoices();
|
||||
currentChoices.setChoices(data, 'value', 'label', true);
|
||||
})
|
||||
.catch((error) => console.error('Error:', error));
|
||||
}
|
||||
|
||||
document.getElementById('reset-filter').addEventListener('click', function(){
|
||||
formChoices.removeActiveItems();
|
||||
currencyChoices.removeActiveItems();
|
||||
|
||||
const input = document.getElementById('order_id');
|
||||
const event = new Event('change', { bubbles: true });
|
||||
|
||||
input.value = '';
|
||||
input.dispatchEvent(event);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
let formipay_table_grid = new gridjs.Grid({
|
||||
server: {
|
||||
url: formipay_orders_page.ajax_url+'?action=formipay-tabledata-orders&order_status='+document.getElementById('post_status').value+'&product='+document.getElementById('products').value+'¤cy='+document.getElementById('currencies').value+'&order_id='+document.getElementById('order_id').value+'&_wpnonce='+formipay_orders_page.nonce,
|
||||
then: data => {
|
||||
|
||||
if(data.posts_report){
|
||||
processPostsReport(data.posts_report);
|
||||
}
|
||||
|
||||
return data.results.map(
|
||||
order => [order.ID, order.ID, order.date, order.form, order.total, order.payment_gateway, order.status]
|
||||
);
|
||||
},
|
||||
total: data => data.total
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
id: 'checkbox',
|
||||
name: gridjs.html(`<input type="checkbox" id="select-all-rows">`),
|
||||
width: '50px',
|
||||
formatter: (_, row) => gridjs.html(
|
||||
`<input type="checkbox" class="formipay-row-checkbox" data-id="${row.cells[0].data}">`
|
||||
)
|
||||
},
|
||||
{
|
||||
name: formipay_orders_page.columns.id,
|
||||
width: '75px'
|
||||
},
|
||||
{
|
||||
name: formipay_orders_page.columns.date,
|
||||
formatter: (_, row) => gridjs.html('<span>' + _.split(' ').join('</span><br><span style="font-size: smaller;">') + '</span>')
|
||||
},
|
||||
{
|
||||
name: formipay_orders_page.columns.form,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<b>${_}</b><br>
|
||||
<span class="post-action" style="visibility: hidden;">
|
||||
<a href="${formipay_orders_page.site_url}/wp-admin/admin.php?page=formipay-orders&order_id=${row.cells[0].data}">details</a> | <a href="#" class="delete-order" data-id="${row.cells[0].data}">delete</a>
|
||||
</span>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_orders_page.columns.total,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<span class="grand_total">
|
||||
<span class="currency">
|
||||
<img src="${_.flag}" height="18">
|
||||
${_.name}
|
||||
</span>
|
||||
<span class="the-total">${_.value}</span>
|
||||
</span>
|
||||
`)
|
||||
},
|
||||
formipay_orders_page.columns.payment_gateway,
|
||||
{
|
||||
name: formipay_orders_page.columns.status,
|
||||
formatter: (status, row) => gridjs.html(`<span class="status-label ${status}">${status}</span>`)
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
limit: document.getElementById('limit').value,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
|
||||
},
|
||||
summary: false
|
||||
},
|
||||
className: {
|
||||
table: 'formipay-grid-table'
|
||||
}
|
||||
}).render(document.getElementById('formipay-orders'));
|
||||
|
||||
var $tableContainer = $('.formipay-grid-table');
|
||||
var $deleteBtn = $('#formipay-delete-selected');
|
||||
|
||||
function updateDeleteButtonVisibility() {
|
||||
if ($tableContainer.find('.formipay-row-checkbox:checked').length > 0) {
|
||||
$deleteBtn.show();
|
||||
} else {
|
||||
$deleteBtn.hide();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$tableContainer.on('change', '.formipay-row-checkbox', function() {
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$tableContainer.on('change', '#select-all-rows', function() {
|
||||
const is_checked = $(this).is(':checked');
|
||||
$tableContainer.find('.formipay-row-checkbox').prop('checked', is_checked);
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle delete button click
|
||||
$deleteBtn.on('click', function() {
|
||||
var selectedIds = $tableContainer.find('.formipay-row-checkbox:checked').map(function() {
|
||||
return $(this).data('id');
|
||||
}).get();
|
||||
|
||||
if (selectedIds.length > 0) {
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_orders_page.modal.bulk_delete.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_orders_page.modal.bulk_delete.confirmButton,
|
||||
cancelButtonText: formipay_orders_page.modal.bulk_delete.cancelButton
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_orders_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-bulk-delete-access-item',
|
||||
ids: selectedIds,
|
||||
_wpnonce: formipay_orders_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_table_grid.forceRender();
|
||||
$tableContainer.find('.formipay-row-checkbox').prop('checked', false);
|
||||
updateDeleteButtonVisibility();
|
||||
refresh_table_with_filter();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function refresh_table_with_filter() {
|
||||
formipay_table_grid.updateConfig({
|
||||
server: {
|
||||
url: formipay_orders_page.ajax_url+'?action=formipay-tabledata-orders&order_status='+document.getElementById('post_status').value+'&product='+document.getElementById('products').value+'¤cy='+document.getElementById('currencies').value+'&order_id='+document.getElementById('order_id').value+'&_wpnonce='+formipay_orders_page.nonce,
|
||||
then: data => data.results.map(
|
||||
order => [order.ID, order.ID, order.date, order.form, order.total, order.payment_gateway, order.status]
|
||||
),
|
||||
total: data => data.total
|
||||
},
|
||||
pagination: {
|
||||
limit: document.getElementById('limit').value,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
|
||||
},
|
||||
summary: false
|
||||
},
|
||||
}).forceRender();
|
||||
}
|
||||
|
||||
$('.form-tool, #post_status, #products, #currencies, #order_id').on('change', function(){
|
||||
refresh_table_with_filter();
|
||||
});
|
||||
|
||||
$(document).on('mouseover', 'td[data-column-id=form]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'visible');
|
||||
});
|
||||
$(document).on('mouseleave', 'td[data-column-id=form]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'hidden');
|
||||
});
|
||||
|
||||
});
|
||||
69
admin/assets/js/admin-pages.js
Normal file
69
admin/assets/js/admin-pages.js
Normal file
@@ -0,0 +1,69 @@
|
||||
function numberFormat(nStr) {
|
||||
nStr = parseFloat(nStr).toFixed(2);
|
||||
var x = nStr.split('.');
|
||||
var x1 = x[0];
|
||||
var x2 = x.length > 1 ? '.' + x[1] : '';
|
||||
var rgx = /(\d+)(\d{3})/;
|
||||
while (rgx.test(x1)) {
|
||||
x1 = x1.replace(rgx, '$1' + ',' + '$2');
|
||||
}
|
||||
return x1 + x2;
|
||||
}
|
||||
|
||||
function processPostsReport(data) {
|
||||
Object.keys(data).forEach(function(status) {
|
||||
// Update the text of elements matching the class
|
||||
var elements = document.querySelectorAll('.' + status + '-post-count');
|
||||
elements.forEach(function(element) {
|
||||
element.textContent = ' (' + data[status] + ')';
|
||||
});
|
||||
|
||||
// Handle the 'trash' status specifically
|
||||
if (status === 'trash' && data[status] > 0) {
|
||||
var wrapper = document.querySelector('.post-status-wrapper');
|
||||
if (wrapper) {
|
||||
wrapper.innerHTML += ' | <a data-value="trash">Trash</a><span class="draft-post-count"> (' + data[status] + ')</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(function($){
|
||||
$('.post-status-wrapper a').on('click', function(e){
|
||||
e.preventDefault();
|
||||
$('.post-status-wrapper a').removeAttr('data-active');
|
||||
$(this).attr('data-active', 'true');
|
||||
$('#post_status').val($(this).data('value')).trigger('change');
|
||||
});
|
||||
});
|
||||
|
||||
(function() {
|
||||
var supportsPassive = false;
|
||||
try {
|
||||
var opts = Object.defineProperty({}, 'passive', {
|
||||
get: function() {
|
||||
supportsPassive = true;
|
||||
}
|
||||
});
|
||||
window.addEventListener("testPassive", null, opts);
|
||||
window.removeEventListener("testPassive", null, opts);
|
||||
} catch (e) {}
|
||||
|
||||
if (!supportsPassive) return;
|
||||
|
||||
var origAddEventListener = EventTarget.prototype.addEventListener;
|
||||
EventTarget.prototype.addEventListener = function(type, listener, options) {
|
||||
// Only patch touchstart and touchmove if options is not explicitly passive
|
||||
if (
|
||||
(type === 'touchstart' || type === 'touchmove') &&
|
||||
(options === undefined || options === false || (typeof options === 'object' && !options.passive))
|
||||
) {
|
||||
options = options || {};
|
||||
if (typeof options === 'object') {
|
||||
options.passive = true;
|
||||
}
|
||||
}
|
||||
return origAddEventListener.call(this, type, listener, options);
|
||||
};
|
||||
})();
|
||||
|
||||
359
admin/assets/js/admin-product-editor.js
Normal file
359
admin/assets/js/admin-product-editor.js
Normal file
@@ -0,0 +1,359 @@
|
||||
jQuery(function ($) {
|
||||
|
||||
$('a[href="admin.php?page=formipay-products"]').addClass('current').closest('li').addClass('current');
|
||||
|
||||
function autoset_variation_name() {
|
||||
var repeater_single = $('.product_variation_attributes.repeater [parent_repeater="parent"] > .wpcfto-field-content > .wpcfto-repeater-single');
|
||||
$.each(repeater_single, function (key, parent) {
|
||||
var repeater_child = $(parent).find('[field_native_name="product_variation_attributes"]');
|
||||
var attribute_name = repeater_child.find(`[name="product_variation_attributes_${key}_attribute_name"]`).val();
|
||||
var attribute_type = repeater_child.find(`[name="product_variation_attributes_${key}_attribute_type"]`).val();
|
||||
var repeater_child_single = repeater_child.find('.wpcfto-repeater-single');
|
||||
$.each(repeater_child_single, function (index, child) {
|
||||
var label_field = $(`input[name="product_variation_attributes_${key}_attribute_variations_${index}_variation_label"]`);
|
||||
var name_field = $(`input[name="product_variation_attributes_${key}_attribute_variations_${index}_variation_name"]`);
|
||||
var color_field = $(`input[name="product_variation_attributes_${key}_attribute_variations_${index}_variation_color"]`);
|
||||
var color_field_row = color_field.closest('.wpcfto-repeater-field');
|
||||
if (attribute_type == 'color') {
|
||||
color_field_row.show();
|
||||
} else {
|
||||
color_field_row.hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('change blur', '[field_native_name_inner="variation_label"] input', function () {
|
||||
autoset_variation_name();
|
||||
});
|
||||
|
||||
$(document).on('click', '.stm_metaboxes_grid .stm_metaboxes_grid__inner .wpcfto-repeater .addArea', function () {
|
||||
autoset_variation_name();
|
||||
});
|
||||
|
||||
var onMetaboxLoaded = setInterval(() => {
|
||||
var repeater_single = $('.product_variation_attributes.repeater [parent_repeater="parent"] > .wpcfto-field-content > .wpcfto-repeater-single');
|
||||
if (repeater_single.length > 0) {
|
||||
autoset_variation_name();
|
||||
clearInterval(onMetaboxLoaded);
|
||||
}
|
||||
}, 250);
|
||||
|
||||
var waitForTable = setInterval(() => {
|
||||
if ($('#product-variables-table').length > 0) {
|
||||
clearInterval(waitForTable);
|
||||
|
||||
// --- PERBAIKAN UTAMA DI SINI ---
|
||||
Vue.component('price-input', {
|
||||
// Gunakan 'value' sebagai prop, sesuai konvensi v-model Vue 2
|
||||
props: {
|
||||
value: [Number, String], // Diubah dari modelValue
|
||||
currencySymbol: String,
|
||||
currencyDecimalDigits: {
|
||||
type: Number,
|
||||
default: 2
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
inputValue: this.value // Diubah dari modelValue
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
// Amati perubahan pada prop 'value'
|
||||
value(newValue) { // Diubah dari modelValue
|
||||
this.inputValue = newValue;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onInput(e) {
|
||||
const value = e.target.value;
|
||||
this.inputValue = value;
|
||||
// Pancarkan event 'input', sesuai konvensi v-model Vue 2
|
||||
this.$emit('input', value); // Diubah dari 'update:modelValue'
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
stepValue() {
|
||||
return Math.pow(10, -this.currencyDecimalDigits);
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="price-input-wrapper">
|
||||
<span class="price-currency">{{ currencySymbol }}</span>
|
||||
<input type="number" :value="inputValue" @input="onInput" :step="stepValue" placeholder="0" :disabled="disabled" />
|
||||
</div>
|
||||
`
|
||||
});
|
||||
// --- AKHIR DARI PERBAIKAN ---
|
||||
|
||||
new Vue({
|
||||
el: '#product-variables-table',
|
||||
data() {
|
||||
return {
|
||||
tableRows: [],
|
||||
deletedKeys: [],
|
||||
isPhysical: window.product_details?.product_is_physical || false,
|
||||
pricingMethod: window.product_details?.product_pricing_method || 'auto',
|
||||
manualPrices: [],
|
||||
productHasVariation: window.product_details?.product_has_variation || false,
|
||||
jsonValue: '[]',
|
||||
attributeRepeaterWatcher: null,
|
||||
manualPricesWatcher: null,
|
||||
_debounceTimer: null,
|
||||
productType: window.product_details?.product_type || 'digital',
|
||||
currencyDecimalDigits: parseInt(window.product_details?.default_currency_decimal_digits) || 2,
|
||||
currencySymbol: window.product_details?.default_currency_symbol || '$'
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
await this.initializeOrClearTable();
|
||||
this.setupAttributeRepeaterSync();
|
||||
this.setupManualPricesSync();
|
||||
const typeRadios = document.querySelectorAll('input[name="product_type"]');
|
||||
typeRadios.forEach(radio => {
|
||||
radio.addEventListener('change', e => {
|
||||
this.productType = e.target.value;
|
||||
this.isPhysical = e.target.value === 'physical';
|
||||
});
|
||||
});
|
||||
const pricingRadios = document.querySelectorAll('input[name="product_pricing_method"]');
|
||||
pricingRadios.forEach(radio => {
|
||||
radio.addEventListener('change', async e => {
|
||||
this.pricingMethod = e.target.value;
|
||||
await this.rebuildTable();
|
||||
});
|
||||
});
|
||||
const hasVariationToggle = document.querySelector('input[name="product_has_variation"]');
|
||||
if (hasVariationToggle) {
|
||||
hasVariationToggle.addEventListener('change', async (e) => {
|
||||
this.productHasVariation = e.target.checked;
|
||||
await this.initializeOrClearTable();
|
||||
});
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.attributeRepeaterWatcher) {
|
||||
this.attributeRepeaterWatcher.disconnect();
|
||||
}
|
||||
if (this.manualPricesWatcher) {
|
||||
this.manualPricesWatcher.disconnect();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async initializeOrClearTable() {
|
||||
if (!this.productHasVariation) {
|
||||
this.tableRows = [];
|
||||
this.updateJson();
|
||||
return;
|
||||
}
|
||||
await this.syncManualPrices();
|
||||
await this.loadProductVariables();
|
||||
},
|
||||
_ensureRowDataStructure(row) {
|
||||
if (this.pricingMethod === 'manual') {
|
||||
if (typeof row.prices === 'undefined') {
|
||||
row.prices = JSON.parse(JSON.stringify(this.manualPrices));
|
||||
delete row.price;
|
||||
delete row.sale;
|
||||
}
|
||||
} else {
|
||||
if (typeof row.price === 'undefined') {
|
||||
row.price = 0;
|
||||
row.sale = 0;
|
||||
delete row.prices;
|
||||
}
|
||||
}
|
||||
if (typeof row.expanded === 'undefined') {
|
||||
row.expanded = false;
|
||||
}
|
||||
return row;
|
||||
},
|
||||
async loadProductVariables() {
|
||||
if (!this.productHasVariation) {
|
||||
this.tableRows = [];
|
||||
this.updateJson();
|
||||
return;
|
||||
}
|
||||
const postId = window.formipayProductId || $('input[name="post_ID"]').val();
|
||||
if (!postId) {
|
||||
await this.buildFromAttributes();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await $.ajax({
|
||||
url: ajaxurl,
|
||||
method: 'POST',
|
||||
data: {
|
||||
action: 'get_product_variables',
|
||||
post_id: postId
|
||||
}
|
||||
});
|
||||
if (res.success && Array.isArray(res.data) && res.data.length) {
|
||||
this.tableRows = res.data.map(row => this._ensureRowDataStructure(row));
|
||||
this.deletedKeys = [];
|
||||
this.updateJson();
|
||||
} else {
|
||||
await this.buildFromAttributes();
|
||||
}
|
||||
} catch {
|
||||
await this.buildFromAttributes();
|
||||
}
|
||||
},
|
||||
async buildFromAttributes() {
|
||||
if (!this.productHasVariation) {
|
||||
this.tableRows = [];
|
||||
this.updateJson();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const attributes = await this.getAttributeRepeaterData();
|
||||
if (!attributes.length) {
|
||||
this.tableRows = [];
|
||||
this.updateJson();
|
||||
return;
|
||||
}
|
||||
const combinations = this.getAllCombinations(attributes);
|
||||
const filtered = combinations.filter(c => !this.deletedKeys.includes(c.key));
|
||||
const newRows = filtered.map(c => {
|
||||
const existing = this.tableRows.find(r => r.key === c.key);
|
||||
if (existing) {
|
||||
this._ensureRowDataStructure(existing);
|
||||
return Object.assign(existing, {
|
||||
name: c.label
|
||||
});
|
||||
}
|
||||
let newRowData = {
|
||||
key: c.key,
|
||||
name: c.label,
|
||||
stock: '',
|
||||
weight: 0,
|
||||
active: true,
|
||||
};
|
||||
return this._ensureRowDataStructure(newRowData);
|
||||
});
|
||||
this.tableRows = newRows;
|
||||
this.updateJson();
|
||||
} catch (e) {
|
||||
console.error("Error building from attributes:", e);
|
||||
this.tableRows = [];
|
||||
this.updateJson();
|
||||
}
|
||||
},
|
||||
getAttributeRepeaterData() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let attempts = 0;
|
||||
const maxAttempts = 100;
|
||||
const interval = setInterval(() => {
|
||||
const el = $('#variation-product_variation_attributes');
|
||||
if (el.length && el.val()) {
|
||||
try {
|
||||
const data = JSON.parse(el.val());
|
||||
clearInterval(interval);
|
||||
resolve(Array.isArray(data) ? data : []);
|
||||
} catch {
|
||||
clearInterval(interval);
|
||||
reject(new Error('Invalid JSON in attribute repeater'));
|
||||
}
|
||||
} else if (++attempts >= maxAttempts) {
|
||||
clearInterval(interval);
|
||||
reject(new Error('Attribute repeater data not found'));
|
||||
}
|
||||
}, 50);
|
||||
});
|
||||
},
|
||||
getAllCombinations(attributes) {
|
||||
const attrVars = attributes
|
||||
.map(attr => (attr.attribute_variations || []).map(v => ({
|
||||
label: v.variation_label
|
||||
})))
|
||||
.filter(arr => arr.length > 0);
|
||||
if (!attrVars.length) return [];
|
||||
const combine = (arrs) => arrs.reduce((a, b) => a.flatMap(d => b.map(e => [].concat(d, e))));
|
||||
const combos = combine(attrVars);
|
||||
return combos.map(combo => {
|
||||
const labels = Array.isArray(combo) ? combo.map(c => c.label) : [combo.label];
|
||||
return {
|
||||
key: labels.join('||'),
|
||||
label: labels.join(' - ')
|
||||
};
|
||||
});
|
||||
},
|
||||
setupAttributeRepeaterSync() {
|
||||
const target = document.getElementById('variation-product_variation_attributes');
|
||||
if (!target) return;
|
||||
const observer = new MutationObserver(() => {
|
||||
clearTimeout(this._debounceTimer);
|
||||
this._debounceTimer = setTimeout(() => this.buildFromAttributes(), 300);
|
||||
});
|
||||
observer.observe(target, {
|
||||
attributes: true,
|
||||
attributeFilter: ['value']
|
||||
});
|
||||
this.attributeRepeaterWatcher = observer;
|
||||
},
|
||||
async syncManualPrices() {
|
||||
const el = document.getElementById('general-product_prices');
|
||||
if (el && el.value) {
|
||||
try {
|
||||
const pricesData = JSON.parse(el.value);
|
||||
this.manualPrices = Array.isArray(pricesData) ? pricesData : [];
|
||||
} catch (e) {
|
||||
this.manualPrices = [];
|
||||
}
|
||||
} else {
|
||||
this.manualPrices = [];
|
||||
}
|
||||
},
|
||||
setupManualPricesSync() {
|
||||
const target = document.getElementById('general-product_prices');
|
||||
if (!target) return;
|
||||
const observer = new MutationObserver(async () => {
|
||||
await this.syncManualPrices();
|
||||
if (this.pricingMethod === 'manual') {
|
||||
this.tableRows.forEach(row => {
|
||||
const newPricesFromRepeater = this.manualPrices;
|
||||
let reconciledPrices = row.prices.filter(existingPrice =>
|
||||
newPricesFromRepeater.some(newPrice => newPrice.currency === existingPrice.currency)
|
||||
);
|
||||
newPricesFromRepeater.forEach(newPrice => {
|
||||
const isAlreadyThere = reconciledPrices.some(p => p.currency === newPrice.currency);
|
||||
if (!isAlreadyThere) {
|
||||
reconciledPrices.push(JSON.parse(JSON.stringify(newPrice)));
|
||||
}
|
||||
});
|
||||
row.prices = reconciledPrices;
|
||||
});
|
||||
}
|
||||
this.updateJson();
|
||||
});
|
||||
observer.observe(target, {
|
||||
attributes: true,
|
||||
attributeFilter: ['value']
|
||||
});
|
||||
this.manualPricesWatcher = observer;
|
||||
},
|
||||
updateJson() {
|
||||
this.jsonValue = JSON.stringify(this.tableRows);
|
||||
},
|
||||
async rebuildTable() {
|
||||
await this.initializeOrClearTable();
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
tableRows: {
|
||||
handler() {
|
||||
this.updateJson();
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 250);
|
||||
|
||||
});
|
||||
217
admin/assets/js/admin-product-editor.jsbak
Normal file
217
admin/assets/js/admin-product-editor.jsbak
Normal file
@@ -0,0 +1,217 @@
|
||||
jQuery(function($){
|
||||
|
||||
$('a[href="admin.php?page=formipay-products"]').addClass('current').closest('li').addClass('current');
|
||||
|
||||
function autoset_variation_name() {
|
||||
|
||||
var repeater_single = $('.product_variation_attributes.repeater [parent_repeater="parent"] > .wpcfto-field-content > .wpcfto-repeater-single');
|
||||
$.each(repeater_single, function(key, parent){
|
||||
var repeater_child = $(parent).find('[field_native_name="product_variation_attributes"]');
|
||||
var attribute_name = repeater_child.find(`[name="product_variation_attributes_${key}_attribute_name"]`).val();
|
||||
var attribute_type = repeater_child.find(`[name="product_variation_attributes_${key}_attribute_type"]`).val();
|
||||
var repeater_child_single = repeater_child.find('.wpcfto-repeater-single');
|
||||
$.each(repeater_child_single, function(index, child){
|
||||
var label_field = $(`input[name="product_variation_attributes_${key}_attribute_variations_${index}_variation_label"]`);
|
||||
var name_field = $(`input[name="product_variation_attributes_${key}_attribute_variations_${index}_variation_name"]`);
|
||||
var color_field = $(`input[name="product_variation_attributes_${key}_attribute_variations_${index}_variation_color"]`);
|
||||
var color_field_row = color_field.closest('.wpcfto-repeater-field');
|
||||
|
||||
if(attribute_type == 'color'){
|
||||
color_field_row.show();
|
||||
}else{
|
||||
color_field_row.hide();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$(document).on('change blur', '[field_native_name_inner="variation_label"] input', function(){
|
||||
autoset_variation_name();
|
||||
});
|
||||
|
||||
$(document).on('click', '.stm_metaboxes_grid .stm_metaboxes_grid__inner .wpcfto-repeater .addArea', function() {
|
||||
autoset_variation_name();
|
||||
});
|
||||
|
||||
var onMetaboxLoaded = setInterval(() => {
|
||||
var repeater_single = $('.product_variation_attributes.repeater [parent_repeater="parent"] > .wpcfto-field-content > .wpcfto-repeater-single');
|
||||
if(repeater_single.length > 0){
|
||||
autoset_variation_name();
|
||||
clearInterval(onMetaboxLoaded);
|
||||
}
|
||||
}, 250);
|
||||
|
||||
var waitForTable = setInterval(() => {
|
||||
if ($('#product-variables-table').length > 0) {
|
||||
clearInterval(waitForTable);
|
||||
|
||||
new Vue({
|
||||
el: '#product-variables-table',
|
||||
data() {
|
||||
return {
|
||||
tableRows: [],
|
||||
deletedKeys: [],
|
||||
isPhysical: window.product_details?.product_is_physical || false,
|
||||
jsonValue: '[]',
|
||||
attributeRepeaterWatcher: null,
|
||||
_debounceTimer: null,
|
||||
productType: window.product_details?.product_type || 'digital', // default, will update on mount
|
||||
productCurrencyRaw: window.product_details?.product_currency || 'USD:::United States dollar:::$',
|
||||
currencyDecimalDigits: parseInt(window.product_details?.product_currency_decimal_digits) || 2,
|
||||
currencyDecimalSymbol: window.product_details?.product_currency_decimal_symbol || '.',
|
||||
currencyThousandSeparator: window.product_details?.product_currency_thousand_separator || ',',
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
|
||||
await this.loadProductVariables();
|
||||
this.setupAttributeRepeaterSync();
|
||||
|
||||
// Listen for changes on product_type radios to update reactive data
|
||||
const radios = document.querySelectorAll('input[name="product_type"]');
|
||||
radios.forEach(radio => {
|
||||
radio.addEventListener('change', e => {
|
||||
this.productType = e.target.value;
|
||||
this.isPhysical = e.target.value == 'physical';
|
||||
this.rebuildTable(); // Rebuild the table on type change
|
||||
});
|
||||
});
|
||||
|
||||
// Listen for changes on product_currency select
|
||||
const currencySelect = document.querySelector('select[name="product_currency"]');
|
||||
if (currencySelect) {
|
||||
currencySelect.addEventListener('change', (e) => {
|
||||
this.productCurrencyRaw = e.target.value;
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize currency values
|
||||
this.productCurrencyRaw = window.product_details?.product_currency || 'USD:::United States dollar:::$';
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.attributeRepeaterWatcher) {
|
||||
this.attributeRepeaterWatcher.disconnect();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadProductVariables() {
|
||||
const postId = window.formipayProductId || $('input[name="post_ID"]').val();
|
||||
if (!postId) {
|
||||
await this.buildFromAttributes();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await $.ajax({
|
||||
url: ajaxurl,
|
||||
method: 'POST',
|
||||
data: { action: 'get_product_variables', post_id: postId }
|
||||
});
|
||||
if (res.success && Array.isArray(res.data) && res.data.length) {
|
||||
this.tableRows = res.data;
|
||||
this.deletedKeys = [];
|
||||
this.updateJson();
|
||||
} else {
|
||||
await this.buildFromAttributes();
|
||||
}
|
||||
} catch {
|
||||
await this.buildFromAttributes();
|
||||
}
|
||||
},
|
||||
async buildFromAttributes() {
|
||||
try {
|
||||
const attributes = await this.getAttributeRepeaterData();
|
||||
if (!attributes.length) {
|
||||
this.tableRows = [];
|
||||
this.updateJson();
|
||||
return;
|
||||
}
|
||||
const combinations = this.getAllCombinations(attributes);
|
||||
const filtered = combinations.filter(c => !this.deletedKeys.includes(c.key));
|
||||
const newRows = filtered.map(c => {
|
||||
const existing = this.tableRows.find(r => r.key === c.key);
|
||||
return existing ? Object.assign(existing, { name: c.label }) : {
|
||||
key: c.key,
|
||||
name: c.label,
|
||||
stock: '',
|
||||
price: 0,
|
||||
sale: 0,
|
||||
weight: 0,
|
||||
active: true,
|
||||
};
|
||||
});
|
||||
this.tableRows = newRows;
|
||||
this.updateJson();
|
||||
} catch (e) {
|
||||
this.tableRows = [];
|
||||
this.updateJson();
|
||||
}
|
||||
},
|
||||
getAttributeRepeaterData() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let attempts = 0;
|
||||
const maxAttempts = 100;
|
||||
const interval = setInterval(() => {
|
||||
const el = $('#variation-product_variation_attributes');
|
||||
if (el.length && el.val()) {
|
||||
try {
|
||||
const data = JSON.parse(el.val());
|
||||
clearInterval(interval);
|
||||
resolve(data);
|
||||
} catch {
|
||||
clearInterval(interval);
|
||||
reject(new Error('Invalid JSON in attribute repeater'));
|
||||
}
|
||||
} else if (++attempts >= maxAttempts) {
|
||||
clearInterval(interval);
|
||||
reject(new Error('Attribute repeater data not found'));
|
||||
}
|
||||
}, 50);
|
||||
});
|
||||
},
|
||||
getAllCombinations(attributes) {
|
||||
if (!attributes.length) return [];
|
||||
const attrVars = attributes.map(attr =>
|
||||
(attr.attribute_variations || []).map(v => ({ label: v.variation_label }))
|
||||
).filter(arr => arr.length > 0);
|
||||
if (!attrVars.length) return [];
|
||||
const combine = (arrs) => arrs.reduce((a, b) => a.flatMap(d => b.map(e => [].concat(d, e))));
|
||||
const combos = combine(attrVars);
|
||||
return combos.map(combo => {
|
||||
const labels = Array.isArray(combo) ? combo.map(c => c.label) : [combo.label];
|
||||
return { key: labels.join('||'), label: labels.join(' - ') };
|
||||
});
|
||||
},
|
||||
setupAttributeRepeaterSync() {
|
||||
const target = document.getElementById('variation-product_variation_attributes');
|
||||
if (!target) return;
|
||||
const observer = new MutationObserver(mutations => {
|
||||
for (const m of mutations) {
|
||||
if (m.type === 'attributes' && m.attributeName === 'value') {
|
||||
clearTimeout(this._debounceTimer);
|
||||
this._debounceTimer = setTimeout(() => this.buildFromAttributes(), 200);
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe(target, { attributes: true, attributeFilter: ['value'] });
|
||||
this.attributeRepeaterWatcher = observer;
|
||||
},
|
||||
updateJson() {
|
||||
this.jsonValue = JSON.stringify(this.tableRows);
|
||||
},
|
||||
rebuildTable() {
|
||||
this.loadProductVariables();
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
tableRows: {
|
||||
handler() { this.updateJson(); },
|
||||
deep: true
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 250);
|
||||
|
||||
});
|
||||
68
admin/assets/js/admin-setting.js
Normal file
68
admin/assets/js/admin-setting.js
Normal file
@@ -0,0 +1,68 @@
|
||||
jQuery(function($){
|
||||
$(document).on('click', '.show-instruction', function(){
|
||||
$('.global-paypal-instruction').slideToggle();
|
||||
$(this).text(function(i, text){
|
||||
return text === 'Show Instruction' ? 'Hide Instruction' : 'Show Instruction';
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.formipay-connect-paypal', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
url: formipay_admin_setting.ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'formipay_oneclick_connect',
|
||||
nonce: formipay_admin_setting.nonce
|
||||
},
|
||||
beforeSend: function() {
|
||||
$('#connect-status').html('<div class="notice notice-info"><p>Initiating PayPal connection...</p></div>');
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
// Open PayPal auth in popup
|
||||
const popup = window.open(
|
||||
response.data.auth_url,
|
||||
'paypal_oauth',
|
||||
'width=600,height=700,scrollbars=yes'
|
||||
);
|
||||
|
||||
// Listen for message from popup
|
||||
window.addEventListener('message', function(event) {
|
||||
if (event.data.type === 'formipay-paypal-connect') {
|
||||
if (event.data.success) {
|
||||
$('#connect-status').html(`
|
||||
<div class="notice notice-success">
|
||||
<p>${event.data.message}</p>
|
||||
<p>Webhook ID: ${event.data.webhook_id}</p>
|
||||
</div>
|
||||
`);
|
||||
} else {
|
||||
$('#connect-status').html(`
|
||||
<div class="notice notice-error">
|
||||
<p>${event.data.message}</p>
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('#connect-status').html(`
|
||||
<div class="notice notice-error">
|
||||
<p>Connection failed: ${response.data}</p>
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#connect-status').html(`
|
||||
<div class="notice notice-error">
|
||||
<p>Connection failed: Server error</p>
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
30
admin/assets/js/classic-editor.js
Normal file
30
admin/assets/js/classic-editor.js
Normal file
@@ -0,0 +1,30 @@
|
||||
jQuery(document).ready(function($) {
|
||||
// Smooth toggle for postboxes
|
||||
$('.postbox').each(function() {
|
||||
$(this).on('click', '.hndle', function() {
|
||||
$(this).next('.inside').slideToggle();
|
||||
});
|
||||
});
|
||||
|
||||
// Add class for better styling
|
||||
$('#title').attr('placeholder', 'Enter title here...');
|
||||
$('#publishing-action .spinner').html(`
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<rect width="6" height="14" x="1" y="4" fill="#0073aa">
|
||||
<animate id="svgSpinnersBarsScaleFade0" fill="freeze" attributeName="y" begin="0;svgSpinnersBarsScaleFade1.end-0.25s" dur="0.75s" values="1;5" />
|
||||
<animate fill="freeze" attributeName="height" begin="0;svgSpinnersBarsScaleFade1.end-0.25s" dur="0.75s" values="22;14" />
|
||||
<animate fill="freeze" attributeName="opacity" begin="0;svgSpinnersBarsScaleFade1.end-0.25s" dur="0.75s" values="1;0.2" />
|
||||
</rect>
|
||||
<rect width="6" height="14" x="9" y="4" fill="#0073aa" opacity="0.4">
|
||||
<animate fill="freeze" attributeName="y" begin="svgSpinnersBarsScaleFade0.begin+0.15s" dur="0.75s" values="1;5" />
|
||||
<animate fill="freeze" attributeName="height" begin="svgSpinnersBarsScaleFade0.begin+0.15s" dur="0.75s" values="22;14" />
|
||||
<animate fill="freeze" attributeName="opacity" begin="svgSpinnersBarsScaleFade0.begin+0.15s" dur="0.75s" values="1;0.2" />
|
||||
</rect>
|
||||
<rect width="6" height="14" x="17" y="4" fill="#0073aa" opacity="0.3">
|
||||
<animate id="svgSpinnersBarsScaleFade1" fill="freeze" attributeName="y" begin="svgSpinnersBarsScaleFade0.begin+0.3s" dur="0.75s" values="1;5" />
|
||||
<animate fill="freeze" attributeName="height" begin="svgSpinnersBarsScaleFade0.begin+0.3s" dur="0.75s" values="22;14" />
|
||||
<animate fill="freeze" attributeName="opacity" begin="svgSpinnersBarsScaleFade0.begin+0.3s" dur="0.75s" values="1;0.2" />
|
||||
</rect>
|
||||
</svg>
|
||||
`);
|
||||
});
|
||||
69
admin/assets/js/formipay-wpmedia-modal.js
Normal file
69
admin/assets/js/formipay-wpmedia-modal.js
Normal file
@@ -0,0 +1,69 @@
|
||||
jQuery(function($){
|
||||
|
||||
$( document ).on( 'click', '.open-media-modal', function( event ) {
|
||||
|
||||
var gallery_items_frame;
|
||||
const $el = $( this );
|
||||
|
||||
var target_field = $el.attr('data-target-field');
|
||||
var target_id = $el.siblings('.'+target_field+'-id');
|
||||
var target_url = $el.siblings('.'+target_field+'-url');
|
||||
var image_preview = $el.siblings('.image-preview');
|
||||
var selected = target_id.val();
|
||||
var able_multiple = $el.attr('data-able-multiple');
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( gallery_items_frame ) {
|
||||
|
||||
// Select the attachment when the frame opens
|
||||
gallery_items_frame.on( 'open', function() {
|
||||
var selection = gallery_items_frame.state().get( 'selection' );
|
||||
selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] );
|
||||
});
|
||||
|
||||
// Open the modal.
|
||||
gallery_items_frame.open();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the media frame.
|
||||
gallery_items_frame = wp.media.frames.gallery_items = wp.media({
|
||||
// Set the title of the modal.
|
||||
title: 'Choose or upload media',
|
||||
button: {
|
||||
text: 'Select'
|
||||
},
|
||||
states: [
|
||||
new wp.media.controller.Library({
|
||||
title: 'Choose or upload media',
|
||||
filterable: 'all',
|
||||
multiple: able_multiple
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
// Select the attachment when the frame opens
|
||||
gallery_items_frame.on( 'open', function() {
|
||||
var selection = gallery_items_frame.state().get( 'selection' );
|
||||
selection.reset( selected ? [ wp.media.attachment( selected ) ] : [] );
|
||||
});
|
||||
|
||||
gallery_items_frame.on( 'select', function() {
|
||||
// We set multiple to false so only get one image from the uploader
|
||||
attachment = gallery_items_frame.state().get('selection').first().toJSON();
|
||||
// Do something with attachment.id and/or attachment.url here
|
||||
target_url.val( attachment.url );
|
||||
target_id.val( attachment.id );
|
||||
// $el.find('.bi-image-alt').hide();
|
||||
image_preview.html('<img src="'+attachment.url+'" width="150px">');
|
||||
// $el.attr('data-id', attachment.id);
|
||||
});
|
||||
|
||||
// Open the modal.
|
||||
gallery_items_frame.open();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
354
admin/assets/js/page-access-items.js
Normal file
354
admin/assets/js/page-access-items.js
Normal file
@@ -0,0 +1,354 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const formChoices = 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_access_page.filter_form.products.placeholder,
|
||||
noResultsText: formipay_access_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_access_page.ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'formipay_access_items_get_products',
|
||||
search: query,
|
||||
nonce: formipay_access_page.nonce
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
formChoices.clearChoices();
|
||||
formChoices.setChoices( data, 'value', 'label', true);
|
||||
})
|
||||
.catch((error) => console.error('Error:', error));
|
||||
}
|
||||
|
||||
document.getElementById('reset-filter').addEventListener('click', function(){
|
||||
formChoices.removeActiveItems();
|
||||
const event = new Event('change', { bubbles: true });
|
||||
|
||||
document.getElementById('orderby').value = 'ID';
|
||||
document.getElementById('sort_by').value = 'desc';
|
||||
document.getElementById('keyword').value = '';
|
||||
document.getElementById('keyword').dispatchEvent(event);
|
||||
});
|
||||
});
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
let formipay_table_grid = new gridjs.Grid({
|
||||
server: {
|
||||
url: formipay_access_page.ajax_url+'?action=formipay-tabledata-access-items&post_status='+document.getElementById('post_status').value+'&product='+document.getElementById('products').value+'&orderby='+document.getElementById('orderby').value+'&sort='+document.getElementById('sort_by').value+'&search='+document.getElementById('keyword').value+'&_wpnonce='+formipay_access_page.nonce,
|
||||
then: data => {
|
||||
|
||||
if(data.posts_report){
|
||||
processPostsReport(data.posts_report);
|
||||
}
|
||||
|
||||
return data.results.map(
|
||||
access => [access.ID, access.ID, access.title, access.type, access.products, access.status]
|
||||
);
|
||||
},
|
||||
total: data => data.total
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
id: 'checkbox',
|
||||
name: gridjs.html(`<input type="checkbox" id="select-all-rows">`),
|
||||
width: '50px',
|
||||
formatter: (_, row) => gridjs.html(
|
||||
`<input type="checkbox" class="formipay-row-checkbox" data-id="${row.cells[0].data}">`
|
||||
)
|
||||
},
|
||||
{
|
||||
name: formipay_access_page.columns.id,
|
||||
width: '75px'
|
||||
},
|
||||
{
|
||||
name: formipay_access_page.columns.title,
|
||||
formatter: (_, row) => {
|
||||
var html = `
|
||||
<b>${_}</b><br>
|
||||
<span class="post-action" style="visibility: hidden;">
|
||||
<a href="${formipay_access_page.site_url}/wp-admin/post.php?post=${row.cells[0].data}&action=edit">edit</a> | <a href="#" class="delete-access" data-id="${row.cells[0].data}">delete</a> | <a href="#" class="duplicate-access" data-id="${row.cells[0].data}">duplicate</a>
|
||||
</span>
|
||||
`;
|
||||
return gridjs.html(html)
|
||||
}
|
||||
},
|
||||
{
|
||||
name: formipay_access_page.columns.type,
|
||||
formatter: (type, row) => {
|
||||
var html;
|
||||
if(type == 'Redirect'){
|
||||
html = `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#277aff" d="M11 17H7q-2.075 0-3.537-1.463T2 12t1.463-3.537T7 7h4v2H7q-1.25 0-2.125.875T4 12t.875 2.125T7 15h4zm-3-4v-2h8v2zm5 4v-2h4q1.25 0 2.125-.875T20 12t-.875-2.125T17 9h-4V7h4q2.075 0 3.538 1.463T22 12t-1.463 3.538T17 17z" />
|
||||
</svg>${type}`;
|
||||
}else if(type == 'Download') {
|
||||
html = `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#277aff" d="M11 12.15V6.1q-1.9.35-2.95 1.838T7 11h-.5q-1.45 0-2.475 1.025T3 14.5t1.025 2.475T6.5 18h12q1.05 0 1.775-.725T21 15.5t-.725-1.775T18.5 13H17v-2q0-1.2-.55-2.238T15 7V4.675q1.85.875 2.925 2.588T19 11q1.725.2 2.863 1.488T23 15.5q0 1.875-1.312 3.188T18.5 20h-12q-2.275 0-3.887-1.575T1 14.575q0-1.95 1.175-3.475T5.25 9.15q.425-1.8 2.125-3.425T11 4.1q.825 0 1.413.588T13 6.1v6.05l.9-.875q.275-.275.688-.275t.712.3q.275.275.275.7t-.275.7l-2.6 2.6q-.3.3-.7.3t-.7-.3l-2.6-2.6q-.275-.275-.287-.687T8.7 11.3q.275-.275.688-.288t.712.263zm1-1.1" />
|
||||
</svg>${type}`;
|
||||
}else if(type == 'Document') {
|
||||
html = `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#277aff" d="M8 13h8v-2H8zm0 3h8v-2H8zm0 3h5v-2H8zm-2 3q-.825 0-1.412-.587T4 20V4q0-.825.588-1.412T6 2h8l6 6v12q0 .825-.587 1.413T18 22zm7-13V4H6v16h12V9zM6 4v5zv16z" />
|
||||
</svg>${type}`;
|
||||
}
|
||||
return gridjs.html(html)
|
||||
}
|
||||
},
|
||||
{
|
||||
name: formipay_access_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) {
|
||||
html += `
|
||||
<span class="product_related">
|
||||
${product}
|
||||
</span>
|
||||
</span>
|
||||
`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return gridjs.html(html);
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
name: formipay_access_page.columns.status,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<span class="status-label ${_}">${_}</span>
|
||||
`)
|
||||
}
|
||||
],
|
||||
pagination: {
|
||||
limit: 10,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
|
||||
},
|
||||
summary: false
|
||||
},
|
||||
className: {
|
||||
table: 'formipay-grid-table'
|
||||
}
|
||||
}).render(document.getElementById('formipay-access-items'));
|
||||
|
||||
var $tableContainer = $('.formipay-grid-table');
|
||||
var $deleteBtn = $('#formipay-delete-selected');
|
||||
|
||||
function updateDeleteButtonVisibility() {
|
||||
if ($tableContainer.find('.formipay-row-checkbox:checked').length > 0) {
|
||||
$deleteBtn.show();
|
||||
} else {
|
||||
$deleteBtn.hide();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$tableContainer.on('change', '.formipay-row-checkbox', function() {
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$tableContainer.on('change', '#select-all-rows', function() {
|
||||
const is_checked = $(this).is(':checked');
|
||||
$tableContainer.find('.formipay-row-checkbox').prop('checked', is_checked);
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle delete button click
|
||||
$deleteBtn.on('click', function() {
|
||||
var selectedIds = $tableContainer.find('.formipay-row-checkbox:checked').map(function() {
|
||||
return $(this).data('id');
|
||||
}).get();
|
||||
|
||||
if (selectedIds.length > 0) {
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_access_page.modal.bulk_delete.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_access_page.modal.bulk_delete.confirmButton,
|
||||
cancelButtonText: formipay_access_page.modal.bulk_delete.cancelButton
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_access_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-bulk-delete-access-item',
|
||||
ids: selectedIds,
|
||||
_wpnonce: formipay_access_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_table_grid.forceRender();
|
||||
$tableContainer.find('.formipay-row-checkbox').prop('checked', false);
|
||||
updateDeleteButtonVisibility();
|
||||
refresh_table_with_filter();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function refresh_table_with_filter() {
|
||||
formipay_table_grid.updateConfig({
|
||||
server: {
|
||||
url: formipay_access_page.ajax_url+'?action=formipay-tabledata-access-items&post_status='+document.getElementById('post_status').value+'&product='+document.getElementById('products').value+'&orderby='+document.getElementById('orderby').value+'&sort='+document.getElementById('sort_by').value+'&search='+document.getElementById('keyword').value,
|
||||
then: data => data.results.map(
|
||||
access => [access.ID, access.ID, access.title, access.type, access.products, access.status]
|
||||
),
|
||||
total: data => data.total
|
||||
}
|
||||
}).forceRender();
|
||||
}
|
||||
|
||||
$('.form-tool, #post_status').on('change', function(){
|
||||
refresh_table_with_filter();
|
||||
});
|
||||
|
||||
$(document).on('mouseover', 'td[data-column-id=title]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'visible');
|
||||
});
|
||||
$(document).on('mouseleave', 'td[data-column-id=title]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'hidden');
|
||||
});
|
||||
|
||||
$(document).on('click', '#add-new-item', async function(e){
|
||||
e.preventDefault();
|
||||
const { value: coupon_code } = await Swal.fire({
|
||||
input: "text",
|
||||
inputLabel: formipay_access_page.modal.add.title,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_access_page.modal.add.confirmButton,
|
||||
cancelButtonText: formipay_access_page.modal.add.cancelButton,
|
||||
reverseButtons: true,
|
||||
inputValidator: (value) => {
|
||||
if (!value) {
|
||||
return formipay_access_page.modal.add.validation;
|
||||
}
|
||||
}
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below, input value is ${coupon_code} */
|
||||
if (result.isConfirmed && result.value) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_access_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-create-access-item-post',
|
||||
title: result.value,
|
||||
nonce: formipay_access_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
if(res.success){
|
||||
window.location.href = res.data.edit_post_url;
|
||||
}else{
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.delete-access', function(e){
|
||||
e.preventDefault();
|
||||
var data_id = $(this).attr('data-id');
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_access_page.modal.delete.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_access_page.modal.delete.confirmButton,
|
||||
cancelButtonText: formipay_access_page.modal.delete.cancelButton,
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_access_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-delete-access-item',
|
||||
id: data_id,
|
||||
nonce: formipay_access_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_table_grid.forceRender();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.duplicate-access', function(e){
|
||||
e.preventDefault();
|
||||
var data_id = $(this).attr('data-id');
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_access_page.modal.duplicate.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_access_page.modal.duplicate.confirmButton,
|
||||
cancelButtonText: formipay_access_page.modal.duplicate.cancelButton,
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_access_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-duplicate-access-item',
|
||||
id: data_id,
|
||||
nonce: formipay_access_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_table_grid.forceRender();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
346
admin/assets/js/page-coupons.js
Normal file
346
admin/assets/js/page-coupons.js
Normal file
@@ -0,0 +1,346 @@
|
||||
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({
|
||||
server: {
|
||||
url: formipay_coupons_page.ajax_url+'?action=formipay-tabledata-coupons&search='+document.getElementById('keyword').value+'&_wpnonce='+formipay_coupons_page.nonce,
|
||||
then: data => {
|
||||
|
||||
if(data.posts_report){
|
||||
processPostsReport(data.posts_report);
|
||||
}
|
||||
|
||||
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]
|
||||
);
|
||||
},
|
||||
total: data => data.total
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
id: 'checkbox',
|
||||
name: gridjs.html(`<input type="checkbox" id="select-all-rows">`),
|
||||
width: '50px',
|
||||
formatter: (_, row) => gridjs.html(
|
||||
`<input type="checkbox" class="formipay-row-checkbox" data-id="${row.cells[0].data}">`
|
||||
)
|
||||
},
|
||||
{
|
||||
name: formipay_coupons_page.columns.id,
|
||||
width: '75px'
|
||||
},
|
||||
{
|
||||
name: formipay_coupons_page.columns.code,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<b>${_}</b><br>
|
||||
<span class="post-action" style="visibility: hidden;">
|
||||
<a href="${formipay_coupons_page.site_url}/wp-admin/post.php?post=${row.cells[0].data}&action=edit">edit</a> | <a href="#" class="delete-coupon" data-id="${row.cells[0].data}">delete</a> | <a href="#" class="duplicate-coupon" data-id="${row.cells[0].data}">duplicate</a>
|
||||
</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(_)
|
||||
},
|
||||
{
|
||||
name: formipay_coupons_page.columns.type,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<span class="type-capsule the-type">${_}</span>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_coupons_page.columns.usages, // { used: 1, limit: 5 }
|
||||
formatter: (_, row) => gridjs.html(`<span class="coupon-used">${_.used}</span>/<span class="coupon-limit">${_.limit}</span>`) // 1/∞
|
||||
},
|
||||
formipay_coupons_page.columns.date_limit,
|
||||
{
|
||||
name: formipay_coupons_page.columns.status,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<span class="status-label ${_.toLowerCase()}">${_}</span>
|
||||
`)
|
||||
},
|
||||
],
|
||||
pagination: {
|
||||
limit: 10,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
|
||||
},
|
||||
summary: false
|
||||
},
|
||||
className: {
|
||||
table: 'formipay-grid-table'
|
||||
}
|
||||
}).render(document.getElementById('formipay-coupons'));
|
||||
|
||||
var $tableContainer = $('.formipay-grid-table');
|
||||
var $deleteBtn = $('#formipay-delete-selected');
|
||||
|
||||
function updateDeleteButtonVisibility() {
|
||||
if ($tableContainer.find('.formipay-row-checkbox:checked').length > 0) {
|
||||
$deleteBtn.show();
|
||||
} else {
|
||||
$deleteBtn.hide();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$tableContainer.on('change', '.formipay-row-checkbox', function() {
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$tableContainer.on('change', '#select-all-rows', function() {
|
||||
const is_checked = $(this).is(':checked');
|
||||
$tableContainer.find('.formipay-row-checkbox').prop('checked', is_checked);
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle delete button click
|
||||
$deleteBtn.on('click', function() {
|
||||
var selectedIds = $tableContainer.find('.formipay-row-checkbox:checked').map(function() {
|
||||
return $(this).data('id');
|
||||
}).get();
|
||||
|
||||
if (selectedIds.length > 0) {
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_coupons_page.modal.bulk_delete.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_coupons_page.modal.bulk_delete.confirmButton,
|
||||
cancelButtonText: formipay_coupons_page.modal.bulk_delete.cancelButton
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_coupons_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-bulk-delete-coupon',
|
||||
ids: selectedIds,
|
||||
_wpnonce: formipay_coupons_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_table_grid.forceRender();
|
||||
$tableContainer.find('.formipay-row-checkbox').prop('checked', false);
|
||||
updateDeleteButtonVisibility();
|
||||
refresh_table_with_filter();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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,
|
||||
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]
|
||||
),
|
||||
total: data => data.total
|
||||
}
|
||||
}).forceRender();
|
||||
}
|
||||
|
||||
$('.form-tool, #products, #post_status').on('change', function(){
|
||||
refresh_table_with_filter();
|
||||
});
|
||||
|
||||
$(document).on('mouseover', 'td[data-column-id=couponCode]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'visible');
|
||||
});
|
||||
$(document).on('mouseleave', 'td[data-column-id=couponCode]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'hidden');
|
||||
});
|
||||
|
||||
$(document).on('input', 'input#swal2-input', function(){
|
||||
const value = $(this).val();
|
||||
$(this).val(value.replace(' ', ''));
|
||||
});
|
||||
|
||||
$(document).on('click', '#add-new-coupon', async function(e){
|
||||
e.preventDefault();
|
||||
const { value: coupon_code } = await Swal.fire({
|
||||
input: "text",
|
||||
inputLabel: formipay_coupons_page.modal.add.title,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_coupons_page.modal.add.confirmButton,
|
||||
cancelButtonText: formipay_coupons_page.modal.add.cancelButton,
|
||||
reverseButtons: true,
|
||||
inputValidator: (value) => {
|
||||
if (!value) {
|
||||
return formipay_coupons_page.modal.add.validation;
|
||||
}
|
||||
}
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below, input value is ${coupon_code} */
|
||||
if (result.isConfirmed && result.value) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_coupons_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-create-coupon-post',
|
||||
title: result.value,
|
||||
_wpnonce: formipay_coupons_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
if(res.success){
|
||||
window.location.href = res.data.edit_post_url;
|
||||
}else{
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.delete-coupon', function(e){
|
||||
e.preventDefault();
|
||||
var data_id = $(this).attr('data-id');
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: "Do you want to delete the coupon?",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Delete Permanently",
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_coupons_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-delete-coupon',
|
||||
id: data_id,
|
||||
_wpnonce: formipay_coupons_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_coupon_table_grid.forceRender();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.duplicate-coupon', function(e){
|
||||
e.preventDefault();
|
||||
var data_id = $(this).attr('data-id');
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: "Do you want to duplicate the coupon?",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Confirm",
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_coupons_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-duplicate-coupon',
|
||||
id: data_id,
|
||||
_wpnonce: formipay_coupons_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_coupon_table_grid.forceRender();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
320
admin/assets/js/page-forms.js
Normal file
320
admin/assets/js/page-forms.js
Normal file
@@ -0,0 +1,320 @@
|
||||
document.getElementById('reset-filter').addEventListener('click', function(){
|
||||
categoryChoices.removeActiveItems();
|
||||
currencyChoices.removeActiveItems();
|
||||
|
||||
const event = new Event('change', { bubbles: true });
|
||||
|
||||
document.getElementById('orderby').value = 'ID';
|
||||
document.getElementById('sort_by').value = 'desc';
|
||||
document.getElementById('keyword').value = '';
|
||||
document.getElementById('keyword').dispatchEvent(event);
|
||||
});
|
||||
|
||||
let formipay_table_grid = new gridjs.Grid({
|
||||
server: {
|
||||
url: formipay_forms_page.ajax_url+'?action=formipay-tabledata-forms&post_status='+document.getElementById('post_status').value+'&orderby='+document.getElementById('orderby').value+'&sort='+document.getElementById('sort_by').value+'&search='+document.getElementById('keyword').value+'&_wpnonce='+formipay_forms_page.nonce,
|
||||
then: data => {
|
||||
|
||||
if(data.posts_report){
|
||||
processPostsReport(data.posts_report);
|
||||
}
|
||||
|
||||
return data.results.map(
|
||||
form => [form.ID, form.ID, form.title, form.date, form.status]
|
||||
);
|
||||
},
|
||||
total: data => data.total
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
id: 'checkbox',
|
||||
name: gridjs.html(`<input type="checkbox" id="select-all-rows">`),
|
||||
width: '50px',
|
||||
formatter: (_, row) => gridjs.html(
|
||||
`<input type="checkbox" class="formipay-row-checkbox" data-id="${row.cells[0].data}">`
|
||||
)
|
||||
},
|
||||
{
|
||||
name: formipay_forms_page.columns.id,
|
||||
width: '75px'
|
||||
},
|
||||
{
|
||||
name: formipay_forms_page.columns.title,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<b>${_}</b><br>
|
||||
<span class="post-action" style="visibility: hidden;">
|
||||
<a href="${formipay_forms_page.site_url}/wp-admin/post.php?post=${row.cells[0].data}&action=edit&_wpnonce=${formipay_forms_page.nonce}">edit</a> | <a href="#" class="delete-form" data-id="${row.cells[0].data}">delete</a> | <a href="#" class="duplicate-form" data-id="${row.cells[0].data}">duplicate</a>
|
||||
</span>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_forms_page.columns.date,
|
||||
formatter: (_, row) => gridjs.html('<span style="text-wrap: nowrap;">' + _.split(' ').join('</span><br><span style="font-size: smaller;">') + '</span>')
|
||||
},
|
||||
{
|
||||
name: formipay_forms_page.columns.status,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<span class="status-label ${_}">${_}</span>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_forms_page.columns.shortcode,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<input class="formipay-form-shortcode" value="[formipay form=${row.cells[0].data}]" disabled>
|
||||
<button class="copy-shortcode" data-copy="[formipay form=${row.cells[0].data}]">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#b7b7b7" d="M9 18q-.825 0-1.412-.587T7 16V4q0-.825.588-1.412T9 2h9q.825 0 1.413.588T20 4v12q0 .825-.587 1.413T18 18zm0-2h9V4H9zm-4 6q-.825 0-1.412-.587T3 20V6h2v14h11v2zm4-6V4z" />
|
||||
</svg> ${formipay_forms_page.toast.copy_button.copy}
|
||||
</button>
|
||||
`)
|
||||
},
|
||||
],
|
||||
pagination: {
|
||||
limit: 10,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
|
||||
},
|
||||
summary: false
|
||||
},
|
||||
className: {
|
||||
table: 'formipay-grid-table'
|
||||
}
|
||||
}).render(document.getElementById('formipay-forms'));
|
||||
|
||||
document.addEventListener('click', function (e) {
|
||||
const copyButton = e.target.closest('[data-copy]'); // Check if the clicked element or its parent has the data-copy attribute
|
||||
if (copyButton) {
|
||||
const textToCopy = copyButton.getAttribute('data-copy');
|
||||
|
||||
// Use the Clipboard API to copy text
|
||||
navigator.clipboard.writeText(textToCopy)
|
||||
.then(() => {
|
||||
// Optionally, display a success message
|
||||
copyButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#000" d="m9.55 18l-5.7-5.7l1.425-1.425L9.55 15.15l9.175-9.175L20.15 7.4z" />
|
||||
</svg> ${formipay_forms_page.toast.copy_button.copied}`;
|
||||
setTimeout(() => {
|
||||
copyButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
|
||||
<path fill="#b7b7b7" d="M9 18q-.825 0-1.412-.587T7 16V4q0-.825.588-1.412T9 2h9q.825 0 1.413.588T20 4v12q0 .825-.587 1.413T18 18zm0-2h9V4H9zm-4 6q-.825 0-1.412-.587T3 20V6h2v14h11v2zm4-6V4z" />
|
||||
</svg> ${formipay_forms_page.toast.copy_button.copy}`; // Reset button text
|
||||
}, 2000);
|
||||
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: formipay_forms_page.toast.copy_button.title,
|
||||
toast: true,
|
||||
position: "top-end",
|
||||
showConfirmButton: false,
|
||||
timer: 3000,
|
||||
timerProgressBar: true,
|
||||
customClass: {
|
||||
container: 'top-40'
|
||||
},
|
||||
didOpen: (toast) => {
|
||||
toast.onmouseenter = Swal.stopTimer;
|
||||
toast.onmouseleave = Swal.resumeTimer;
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Failed to copy text: ', err);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
var $deleteBtn = $('#formipay-delete-selected');
|
||||
|
||||
function updateDeleteButtonVisibility() {
|
||||
if ($(document).find('.formipay-row-checkbox:checked').length > 0) {
|
||||
$deleteBtn.show();
|
||||
} else {
|
||||
$deleteBtn.hide();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$(document).on('change', '.formipay-row-checkbox', function() {
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$(document).on('change', '#select-all-rows', function() {
|
||||
const is_checked = $(this).is(':checked');
|
||||
$(document).find('.formipay-row-checkbox').prop('checked', is_checked);
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle delete button click
|
||||
$deleteBtn.on('click', function() {
|
||||
var selectedIds = $(document).find('.formipay-row-checkbox:checked').map(function() {
|
||||
return $(this).data('id');
|
||||
}).get();
|
||||
|
||||
console.log(selectedIds);
|
||||
|
||||
if (selectedIds.length > 0) {
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_forms_page.modal.bulk_delete.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_forms_page.modal.bulk_delete.confirmButton,
|
||||
cancelButtonText: formipay_forms_page.modal.bulk_delete.cancelButton
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_forms_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-bulk-delete-form',
|
||||
ids: selectedIds,
|
||||
_wpnonce: formipay_forms_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_table_grid.forceRender();
|
||||
$(document).find('.formipay-row-checkbox').prop('checked', false);
|
||||
updateDeleteButtonVisibility();
|
||||
refresh_table_with_filter();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function refresh_table_with_filter() {
|
||||
formipay_table_grid.updateConfig({
|
||||
server: {
|
||||
url: formipay_forms_page.ajax_url+'?action=formipay-tabledata-forms&post_status='+document.getElementById('post_status').value+'&orderby='+document.getElementById('orderby').value+'&sort='+document.getElementById('sort_by').value+'&search='+document.getElementById('keyword').value+'&_wpnonce='+formipay_forms_page.nonce,
|
||||
then: data => data.results.map(
|
||||
form => [form.ID, form.ID, form.title, form.date, form.status]
|
||||
),
|
||||
total: data => data.total
|
||||
}
|
||||
}).forceRender();
|
||||
}
|
||||
|
||||
$('.form-tool, #post_status').on('change', function(){
|
||||
refresh_table_with_filter();
|
||||
});
|
||||
|
||||
$(document).on('mouseover', 'td[data-column-id=title]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'visible');
|
||||
});
|
||||
$(document).on('mouseleave', 'td[data-column-id=title]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'hidden');
|
||||
});
|
||||
|
||||
$(document).on('click', '#add-new-form', async function(e){
|
||||
e.preventDefault();
|
||||
const { value: title } = await Swal.fire({
|
||||
input: "text",
|
||||
inputLabel: formipay_forms_page.modal.add.title,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_forms_page.modal.add.confirmButton,
|
||||
cancelButtonText: formipay_forms_page.modal.add.cancelButton,
|
||||
reverseButtons: true,
|
||||
inputValidator: (value) => {
|
||||
if (!value) {
|
||||
return formipay_forms_page.modal.add.validation;
|
||||
}
|
||||
}
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below, input value is ${coupon_code} */
|
||||
if (result.isConfirmed && result.value) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_forms_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-create-form-post',
|
||||
title: result.value,
|
||||
_wpnonce: formipay_forms_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
if(res.success){
|
||||
window.location.href = res.data.edit_post_url;
|
||||
}else{
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.delete-form', function(e){
|
||||
e.preventDefault();
|
||||
var data_id = $(this).attr('data-id');
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_forms_page.bulk_delete.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_forms_page.delete.confirmButton,
|
||||
cancelButtonText: formipay_forms_page.delete.cancelButton,
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_forms_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-delete-form',
|
||||
id: data_id,
|
||||
_wpnonce: formipay_forms_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_table_grid.forceRender();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.duplicate-form', function(e){
|
||||
e.preventDefault();
|
||||
var data_id = $(this).attr('data-id');
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: "Do you want to duplicate the form?",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Confirm",
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_forms_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-duplicate-form',
|
||||
id: data_id,
|
||||
_wpnonce: formipay_forms_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_table_grid.forceRender();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
13
admin/assets/js/page-product-taxonomy.js
Normal file
13
admin/assets/js/page-product-taxonomy.js
Normal file
@@ -0,0 +1,13 @@
|
||||
jQuery(function($){
|
||||
$('#wpbody-content').prepend(`
|
||||
<div class="formipay-screen-menu">
|
||||
<img src="`+formipay_product_taxonomy_page.site_url+`/wp-content/plugins/formipay/admin/assets/img/formipay-logo-circle-white_256.png" alt="Formipay">
|
||||
<div class="screen-title">
|
||||
<h1>`+formipay_product_taxonomy_page.page_title+`</h1>
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
$('form.search-form.wp-clearfix').appendTo('.tablenav.top');
|
||||
$('.wp-heading-inline').hide();
|
||||
$(`a[href="edit-tags.php?taxonomy=formipay-product-category&post_type=formipay-product"]`).addClass('current').closest('li').addClass('current');
|
||||
});
|
||||
371
admin/assets/js/page-products.js
Normal file
371
admin/assets/js/page-products.js
Normal file
@@ -0,0 +1,371 @@
|
||||
const categoryChoices = new Choices('#categories', {
|
||||
searchEnabled: true,
|
||||
searchChoices: false, // Prevent Choices.js from filtering the local list
|
||||
searchResultLimit: 10, // Optional: Limit visible results
|
||||
placeholder: true,
|
||||
placeholderValue: formipay_products_page.filter_form.categories.placeholder,
|
||||
noResultsText: formipay_products_page.filter_form.categories.noresult_text,
|
||||
itemSelectText: '',
|
||||
allowHTML: true
|
||||
});
|
||||
|
||||
const currencyChoices = new Choices('#currencies', {
|
||||
searchEnabled: true,
|
||||
searchChoices: false, // Prevent Choices.js from filtering the local list
|
||||
searchResultLimit: 10, // Optional: Limit visible results
|
||||
placeholder: true,
|
||||
placeholderValue: formipay_products_page.filter_form.currencies.placeholder,
|
||||
noResultsText: formipay_products_page.filter_form.currencies.noresult_text,
|
||||
itemSelectText: '',
|
||||
allowHTML: true
|
||||
});
|
||||
|
||||
const searchInput = document.querySelectorAll('.currency .choices__input--cloned');
|
||||
let typingTimer;
|
||||
|
||||
searchInput[0].addEventListener('input', function () {
|
||||
const query = this.value;
|
||||
|
||||
if (query.length >= 3) {
|
||||
clearTimeout(typingTimer);
|
||||
typingTimer = setTimeout(() => {
|
||||
fetchChoices(query);
|
||||
}, 300); // Add a debounce delay
|
||||
}
|
||||
});
|
||||
|
||||
function fetchChoices(query) {
|
||||
fetch(formipay_products_page.ajax_url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
action: 'formipay_product_get_currencies',
|
||||
search: query,
|
||||
_wpnonce: formipay_products_page.nonce
|
||||
}),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
currencyChoices.clearChoices();
|
||||
currencyChoices.setChoices( data, 'value', 'label', true);
|
||||
})
|
||||
.catch((error) => console.error('Error:', error));
|
||||
}
|
||||
|
||||
document.getElementById('reset-filter').addEventListener('click', function(){
|
||||
categoryChoices.removeActiveItems();
|
||||
currencyChoices.removeActiveItems();
|
||||
|
||||
const event = new Event('change', { bubbles: true });
|
||||
|
||||
document.getElementById('orderby').value = 'ID';
|
||||
document.getElementById('sort_by').value = 'desc';
|
||||
document.getElementById('keyword').value = '';
|
||||
document.getElementById('keyword').dispatchEvent(event);
|
||||
});
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
let formipay_product_table_grid = new gridjs.Grid({
|
||||
server: {
|
||||
url: formipay_products_page.ajax_url+'?action=formipay-tabledata-products&post_status='+document.getElementById('post_status').value+'¤cy='+document.getElementById('currencies').value+'&category='+document.getElementById('categories').value+'&orderby='+document.getElementById('orderby').value+'&sort='+document.getElementById('sort_by').value+'&search='+document.getElementById('keyword').value+'&_wpnonce='+formipay_products_page.nonce,
|
||||
then: data => {
|
||||
|
||||
if(data.posts_report){
|
||||
processPostsReport(data.posts_report);
|
||||
}
|
||||
|
||||
return data.results.map(
|
||||
product => [product.ID, product.ID, product.title, product.price, product.type, product.stock, product.status]
|
||||
);
|
||||
},
|
||||
total: data => data.total
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
id: 'checkbox',
|
||||
name: gridjs.html(`<input type="checkbox" id="select-all-rows">`),
|
||||
width: '50px',
|
||||
formatter: (_, row) => gridjs.html(
|
||||
`<input type="checkbox" class="formipay-row-checkbox" data-id="${row.cells[0].data}">`
|
||||
)
|
||||
},
|
||||
{
|
||||
name: formipay_products_page.columns.id,
|
||||
width: '75px'
|
||||
},
|
||||
{
|
||||
name: formipay_products_page.columns.title,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<b>${_}</b><br>
|
||||
<span class="post-action" style="visibility: hidden;">
|
||||
<a href="${formipay_products_page.site_url}/wp-admin/post.php?post=${row.cells[0].data}&action=edit">edit</a> | <a href="#" class="delete-product" data-id="${row.cells[0].data}">delete</a> | <a href="#" class="duplicate-product" data-id="${row.cells[0].data}">duplicate</a>
|
||||
</span>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_products_page.columns.price,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<span class="price">
|
||||
<img src="${_.flag}" width="20"> ${_.name}
|
||||
</span>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_products_page.columns.type
|
||||
},
|
||||
{
|
||||
name: formipay_products_page.columns.stock,
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<span class="type-capsule the-type">${_}</span>
|
||||
`)
|
||||
},
|
||||
{
|
||||
name: formipay_products_page.columns.status, // { used: 1, limit: 5 }
|
||||
formatter: (_, row) => gridjs.html(`
|
||||
<span class="status-label ${_}">${_}</span>
|
||||
`)
|
||||
},
|
||||
],
|
||||
pagination: {
|
||||
limit: 10,
|
||||
server: {
|
||||
url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
|
||||
},
|
||||
summary: false
|
||||
},
|
||||
className: {
|
||||
table: 'formipay-grid-table'
|
||||
}
|
||||
}).render(document.getElementById('formipay-products'));
|
||||
|
||||
var $deleteBtn = $('#formipay-delete-selected');
|
||||
|
||||
function updateDeleteButtonVisibility() {
|
||||
if ($(document).find('.formipay-row-checkbox:checked').length > 0) {
|
||||
$deleteBtn.show();
|
||||
} else {
|
||||
$deleteBtn.hide();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$(document).on('change', '.formipay-row-checkbox', function() {
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle row and "select all" checkbox changes
|
||||
$(document).on('change', '#select-all-rows', function() {
|
||||
const is_checked = $(this).is(':checked');
|
||||
$(document).find('.formipay-row-checkbox').prop('checked', is_checked);
|
||||
updateDeleteButtonVisibility();
|
||||
});
|
||||
|
||||
// Handle delete button click
|
||||
$deleteBtn.on('click', function() {
|
||||
var selectedIds = $(document).find('.formipay-row-checkbox:checked').map(function() {
|
||||
return $(this).data('id');
|
||||
}).get();
|
||||
|
||||
console.log(selectedIds);
|
||||
|
||||
if (selectedIds.length > 0) {
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_products_page.modal.bulk_delete.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_products_page.modal.bulk_delete.confirmButton,
|
||||
cancelButtonText: formipay_products_page.modal.bulk_delete.cancelButton
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_products_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-bulk-delete-product',
|
||||
ids: selectedIds,
|
||||
_wpnonce: formipay_products_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
formipay_product_table_grid.forceRender();
|
||||
$(document).find('.formipay-row-checkbox').prop('checked', false);
|
||||
updateDeleteButtonVisibility();
|
||||
refresh_table_with_filter();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function refresh_table_with_filter() {
|
||||
formipay_product_table_grid.updateConfig({
|
||||
server: {
|
||||
url: formipay_products_page.ajax_url+'?action=formipay-tabledata-products&post_status='+document.getElementById('post_status').value+'¤cy='+document.getElementById('currencies').value+'&category='+document.getElementById('categories').value+'&orderby='+document.getElementById('orderby').value+'&sort='+document.getElementById('sort_by').value+'&search='+document.getElementById('keyword').value+'&_wpnonce='+formipay_products_page.nonce,
|
||||
then: data => data.results.map(
|
||||
product => [product.ID, product.ID, product.title, product.price, product.type, product.stock, product.status]
|
||||
),
|
||||
total: data => data.total
|
||||
}
|
||||
}).forceRender();
|
||||
$(document) = $('.formipay-grid-table');
|
||||
}
|
||||
|
||||
$('.form-tool, #post_status').on('change', function(){
|
||||
refresh_table_with_filter();
|
||||
});
|
||||
|
||||
$(document).on('mouseover', 'td[data-column-id=title]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'visible');
|
||||
});
|
||||
$(document).on('mouseleave', 'td[data-column-id=title]', function(){
|
||||
$(this).find('.post-action').css('visibility', 'hidden');
|
||||
});
|
||||
|
||||
$(document).on('click', '#add-new-product', async function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var options = [];
|
||||
$.each(formipay_products_page.modal.form.currency_options, function(value, label){
|
||||
options.push(`<option value="${value}">${label}</option>`);
|
||||
});
|
||||
|
||||
// Table-based form HTML
|
||||
const formHtml = `
|
||||
<input id="swal-input-title" class="swal2-input" placeholder="Product Title">
|
||||
<input id="swal-input-price" type="number" min="0" class="swal2-input" placeholder="Price">
|
||||
`;
|
||||
|
||||
// Show the SweetAlert2 modal
|
||||
const { value: title } = await Swal.fire({
|
||||
input: "text",
|
||||
inputLabel: formipay_products_page.modal.add.title,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_products_page.modal.add.confirmButton,
|
||||
cancelButtonText: formipay_products_page.modal.add.cancelButton,
|
||||
reverseButtons: true,
|
||||
inputValidator: (value) => {
|
||||
if (!value) {
|
||||
return formipay_products_page.modal.add.validation;
|
||||
}
|
||||
}
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below, input value is ${coupon_code} */
|
||||
if (result.isConfirmed && result.value) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_products_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-create-product-post',
|
||||
title: result.value,
|
||||
_wpnonce: formipay_products_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
if(res.success){
|
||||
window.location.href = res.data.edit_post_url;
|
||||
}else{
|
||||
Swal.fire({
|
||||
html: res.data.message,
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.delete-product', function(e){
|
||||
e.preventDefault();
|
||||
var data_id = $(this).attr('data-id');
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_products_page.modal.delete.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_products_page.modal.delete.confirmButton,
|
||||
cancelButtonText: formipay_products_page.modal.delete.cancelButton,
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_products_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-delete-product',
|
||||
id: data_id,
|
||||
_wpnonce: formipay_products_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
updateDeleteButtonVisibility();
|
||||
refresh_table_with_filter();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.duplicate-product', function(e){
|
||||
e.preventDefault();
|
||||
var data_id = $(this).attr('data-id');
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
html: formipay_products_page.modal.duplicate.question,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: formipay_products_page.modal.duplicate.confirmButton,
|
||||
cancelButtonText: formipay_products_page.modal.duplicate.cancelButton,
|
||||
}).then((result) => {
|
||||
/* Read more about isConfirmed, isDenied below */
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: formipay_products_page.ajax_url,
|
||||
data: {
|
||||
action: 'formipay-duplicate-product',
|
||||
id: data_id,
|
||||
_wpnonce: formipay_products_page.nonce
|
||||
},
|
||||
success: function (res) {
|
||||
Swal.fire({
|
||||
title: res.data.title,
|
||||
html: res.data.message,
|
||||
icon: res.data.icon
|
||||
});
|
||||
updateDeleteButtonVisibility();
|
||||
refresh_table_with_filter();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
Swal.fire({
|
||||
title: 'Error!',
|
||||
html: xhr.responseText,
|
||||
icon: 'error',
|
||||
customClass: {
|
||||
confirmButton: 'formipay-button-error'
|
||||
},
|
||||
allowOutsideClick: false,
|
||||
allowEscapeKey: false,
|
||||
showCloseButton: false,
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user