Refactor order notes inline js

This commit is contained in:
Gerhard 2013-11-28 14:03:29 +02:00
parent bc98a8dc9f
commit 238becb050
3 changed files with 42 additions and 53 deletions

View File

@ -954,6 +954,46 @@ jQuery( function($){
return false;
});
// Order notes
$('#woocommerce-order-notes').on( 'click', 'a.add_note', function() {
if ( ! $('textarea#add_order_note').val() ) return;
$('#woocommerce-order-notes').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_add_order_note',
post_id: woocommerce_admin_meta_boxes.post_id,
note: $('textarea#add_order_note').val(),
note_type: $('select#order_note_type').val(),
security: woocommerce_admin_meta_boxes.add_order_note_nonce,
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function(response) {
$('ul.order_notes').prepend( response );
$('#woocommerce-order-notes').unblock();
$('#add_order_note').val('');
});
return false;
});
$('#woocommerce-order-notes').on( 'click', 'a.delete_note', function() {
var note = $(this).closest('li.note');
$(note).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_delete_order_note',
note_id: $(note).attr('rel'),
security: woocommerce_admin_meta_boxes.delete_order_note_nonce,
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function(response) {
$(note).remove();
});
return false;
});
// PRODUCT TYPE SPECIFIC OPTIONS
$('select#product-type').change(function(){

View File

@ -164,6 +164,8 @@ class WC_Admin_Assets {
'search_products_nonce' => wp_create_nonce("search-products"),
'grant_access_nonce' => wp_create_nonce("grant-access"),
'revoke_access_nonce' => wp_create_nonce("revoke-access"),
'add_order_note_nonce' => wp_create_nonce("add-order-note"),
'delete_order_note_nonce' => wp_create_nonce("delete-order-note"),
'calendar_image' => WC()->plugin_url().'/assets/images/calendar.png',
'post_id' => isset( $post->ID ) ? $post->ID : '',
'base_country' => WC()->countries->get_base_country(),

View File

@ -67,59 +67,6 @@ class WC_Meta_Box_Order_Notes {
<a href="#" class="add_note button"><?php _e( 'Add', 'woocommerce' ); ?></a>
</p>
</div>
<script type="text/javascript">
jQuery('#woocommerce-order-notes')
.on( 'click', 'a.add_note', function() {
if (!jQuery('textarea#add_order_note').val()) return;
jQuery('#woocommerce-order-notes').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_add_order_note',
post_id: '<?php echo $post->ID; ?>',
note: jQuery('textarea#add_order_note').val(),
note_type: jQuery('select#order_note_type').val(),
security: '<?php echo wp_create_nonce("add-order-note"); ?>'
};
jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
jQuery('ul.order_notes').prepend( response );
jQuery('#woocommerce-order-notes').unblock();
jQuery('#add_order_note').val('');
});
return false;
})
.on( 'click', 'a.delete_note', function() {
var note = jQuery(this).closest('li.note');
jQuery(note).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_delete_order_note',
note_id: jQuery(note).attr('rel'),
security: '<?php echo wp_create_nonce("delete-order-note"); ?>'
};
jQuery.post( '<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
jQuery(note).remove();
});
return false;
});
</script>
<?php
}
}