Move all download permissions inline js to meta-boxes.js
This commit is contained in:
parent
a1ad556fb9
commit
06020f4bd5
|
@ -746,6 +746,80 @@ jQuery( function($){
|
|||
return false;
|
||||
} );
|
||||
|
||||
// Download permissions
|
||||
$('.order_download_permissions').on('click', 'button.grant_access', function(){
|
||||
var products = $('select#grant_access_id').val();
|
||||
if (!products) return;
|
||||
|
||||
$('.order_download_permissions').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_grant_access_to_download',
|
||||
product_ids: products,
|
||||
loop: $('.order_download_permissions .wc-metabox').size(),
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.grant_access_nonce,
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
|
||||
if ( response ) {
|
||||
$('.order_download_permissions .wc-metaboxes').append( response );
|
||||
} else {
|
||||
alert( woocommerce_admin_meta_boxes.i18n_download_permission_fail );
|
||||
}
|
||||
|
||||
$( ".date-picker" ).datepicker({
|
||||
dateFormat: "yy-mm-dd",
|
||||
numberOfMonths: 1,
|
||||
showButtonPanel: true,
|
||||
showOn: "button",
|
||||
buttonImage: woocommerce_admin_meta_boxes.calendar_image,
|
||||
buttonImageOnly: true
|
||||
});
|
||||
$('#grant_access_id').val('').trigger('chosen:updated');
|
||||
$('.order_download_permissions').unblock();
|
||||
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.order_download_permissions').on('click', 'button.revoke_access', function(e){
|
||||
e.preventDefault();
|
||||
var answer = confirm( woocommerce_admin_meta_boxes.i18n_permission_revoke );
|
||||
if ( answer ) {
|
||||
var el = $(this).parent().parent();
|
||||
var product = $(this).attr('rel').split(",")[0];
|
||||
var file = $(this).attr('rel').split(",")[1];
|
||||
|
||||
if ( product > 0 ) {
|
||||
$(el).block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_admin_meta_boxes.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_revoke_access_to_download',
|
||||
product_id: product,
|
||||
download_id: file,
|
||||
order_id: woocommerce_admin_meta_boxes.post_id,
|
||||
security: woocommerce_admin_meta_boxes.revoke_access_nonce,
|
||||
};
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function(response) {
|
||||
// Success
|
||||
$(el).fadeOut('300', function(){
|
||||
$(el).remove();
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
$(el).fadeOut('300', function(){
|
||||
$(el).remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
$('button.load_customer_billing').click(function(){
|
||||
|
||||
|
|
|
@ -162,6 +162,8 @@ class WC_Admin_Assets {
|
|||
'calc_totals_nonce' => wp_create_nonce("calc-totals"),
|
||||
'get_customer_details_nonce' => wp_create_nonce("get-customer-details"),
|
||||
'search_products_nonce' => wp_create_nonce("search-products"),
|
||||
'grant_access_nonce' => wp_create_nonce("grant-access"),
|
||||
'revoke_access_nonce' => wp_create_nonce("revoke-access"),
|
||||
'calendar_image' => WC()->plugin_url().'/assets/images/calendar.png',
|
||||
'post_id' => isset( $post->ID ) ? $post->ID : '',
|
||||
'base_country' => WC()->countries->get_base_country(),
|
||||
|
@ -175,6 +177,8 @@ class WC_Admin_Assets {
|
|||
'product_types' => array_map( 'sanitize_title', get_terms( 'product_type', array( 'hide_empty' => false, 'fields' => 'names' ) ) ),
|
||||
'default_attribute_visibility' => apply_filters( 'default_attribute_visibility', false ),
|
||||
'default_attribute_variation' => apply_filters( 'default_attribute_variation', false ),
|
||||
'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ),
|
||||
'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ),
|
||||
);
|
||||
|
||||
wp_localize_script( 'woocommerce_admin_meta_boxes', 'woocommerce_admin_meta_boxes', $params );
|
||||
|
|
|
@ -61,101 +61,6 @@ class WC_Meta_Box_Order_Downloads {
|
|||
|
||||
</div>
|
||||
<?php
|
||||
/**
|
||||
* Javascript
|
||||
*/
|
||||
ob_start();
|
||||
?>
|
||||
jQuery(function(){
|
||||
|
||||
jQuery('.order_download_permissions').on('click', 'button.grant_access', function(){
|
||||
|
||||
var products = jQuery('select#grant_access_id').val();
|
||||
|
||||
if (!products) return;
|
||||
|
||||
jQuery('.order_download_permissions').block({ message: null, overlayCSS: { background: '#fff url(<?php echo WC()->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_grant_access_to_download',
|
||||
product_ids: products,
|
||||
loop: jQuery('.order_download_permissions .wc-metabox').size(),
|
||||
order_id: '<?php echo $post->ID; ?>',
|
||||
security: '<?php echo wp_create_nonce("grant-access"); ?>'
|
||||
};
|
||||
|
||||
jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function( response ) {
|
||||
|
||||
if ( response ) {
|
||||
|
||||
jQuery('.order_download_permissions .wc-metaboxes').append( response );
|
||||
|
||||
} else {
|
||||
|
||||
alert('<?php echo esc_js( __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ) ); ?>');
|
||||
|
||||
}
|
||||
|
||||
jQuery( ".date-picker" ).datepicker({
|
||||
dateFormat: "yy-mm-dd",
|
||||
numberOfMonths: 1,
|
||||
showButtonPanel: true,
|
||||
showOn: "button",
|
||||
buttonImage: woocommerce_admin_meta_boxes.calendar_image,
|
||||
buttonImageOnly: true
|
||||
});
|
||||
jQuery('#grant_access_id').val('').trigger('chosen:updated');
|
||||
jQuery('.order_download_permissions').unblock();
|
||||
|
||||
});
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
jQuery('.order_download_permissions').on('click', 'button.revoke_access', function(e){
|
||||
e.preventDefault();
|
||||
var answer = confirm('<?php echo esc_js( __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ) ); ?>');
|
||||
if (answer){
|
||||
|
||||
var el = jQuery(this).parent().parent();
|
||||
|
||||
var product = jQuery(this).attr('rel').split(",")[0];
|
||||
var file = jQuery(this).attr('rel').split(",")[1];
|
||||
|
||||
if (product>0) {
|
||||
|
||||
jQuery(el).block({ message: null, overlayCSS: { background: '#fff url(<?php echo WC()->plugin_url(); ?>/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } });
|
||||
|
||||
var data = {
|
||||
action: 'woocommerce_revoke_access_to_download',
|
||||
product_id: product,
|
||||
download_id: file,
|
||||
order_id: '<?php echo $post->ID; ?>',
|
||||
security: '<?php echo wp_create_nonce("revoke-access"); ?>'
|
||||
};
|
||||
|
||||
jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
|
||||
// Success
|
||||
jQuery(el).fadeOut('300', function(){
|
||||
jQuery(el).remove();
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
jQuery(el).fadeOut('300', function(){
|
||||
jQuery(el).remove();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
<?php
|
||||
$javascript = ob_get_clean();
|
||||
wc_enqueue_js( $javascript );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue