quick-edit.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*global inlineEditPost, woocommerce_admin, woocommerce_quick_edit */
  2. jQuery(function( $ ) {
  3. $( '#the-list' ).on( 'click', '.editinline', function() {
  4. inlineEditPost.revert();
  5. var post_id = $( this ).closest( 'tr' ).attr( 'id' );
  6. post_id = post_id.replace( 'post-', '' );
  7. var $wc_inline_data = $( '#woocommerce_inline_' + post_id );
  8. var sku = $wc_inline_data.find( '.sku' ).text(),
  9. regular_price = $wc_inline_data.find( '.regular_price' ).text(),
  10. sale_price = $wc_inline_data.find( '.sale_price ').text(),
  11. weight = $wc_inline_data.find( '.weight' ).text(),
  12. length = $wc_inline_data.find( '.length' ).text(),
  13. width = $wc_inline_data.find( '.width' ).text(),
  14. height = $wc_inline_data.find( '.height' ).text(),
  15. shipping_class = $wc_inline_data.find( '.shipping_class' ).text(),
  16. visibility = $wc_inline_data.find( '.visibility' ).text(),
  17. stock_status = $wc_inline_data.find( '.stock_status' ).text(),
  18. stock = $wc_inline_data.find( '.stock' ).text(),
  19. featured = $wc_inline_data.find( '.featured' ).text(),
  20. manage_stock = $wc_inline_data.find( '.manage_stock' ).text(),
  21. menu_order = $wc_inline_data.find( '.menu_order' ).text(),
  22. tax_status = $wc_inline_data.find( '.tax_status' ).text(),
  23. tax_class = $wc_inline_data.find( '.tax_class' ).text(),
  24. backorders = $wc_inline_data.find( '.backorders' ).text();
  25. var formatted_regular_price = regular_price.replace('.', woocommerce_admin.mon_decimal_point ),
  26. formatted_sale_price = sale_price.replace('.', woocommerce_admin.mon_decimal_point );
  27. $( 'input[name="_sku"]', '.inline-edit-row' ).val( sku );
  28. $( 'input[name="_regular_price"]', '.inline-edit-row' ).val( formatted_regular_price );
  29. $( 'input[name="_sale_price"]', '.inline-edit-row' ).val( formatted_sale_price );
  30. $( 'input[name="_weight"]', '.inline-edit-row' ).val( weight );
  31. $( 'input[name="_length"]', '.inline-edit-row' ).val( length );
  32. $( 'input[name="_width"]', '.inline-edit-row' ).val( width );
  33. $( 'input[name="_height"]', '.inline-edit-row' ).val( height );
  34. $( 'select[name="_shipping_class"] option:selected', '.inline-edit-row' ).attr( 'selected', false ).change();
  35. $( 'select[name="_shipping_class"] option[value="' + shipping_class + '"]' ).attr( 'selected', 'selected' ).change();
  36. $( 'input[name="_stock"]', '.inline-edit-row' ).val( stock );
  37. $( 'input[name="menu_order"]', '.inline-edit-row' ).val( menu_order );
  38. $( 'select[name="_tax_status"] option, select[name="_tax_class"] option, select[name="_visibility"] option, select[name="_stock_status"] option, select[name="_backorders"] option' ).removeAttr( 'selected' );
  39. $( 'select[name="_tax_status"] option[value="' + tax_status + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
  40. $( 'select[name="_tax_class"] option[value="' + tax_class + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
  41. $( 'select[name="_visibility"] option[value="' + visibility + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
  42. $( 'select[name="_stock_status"] option[value="' + stock_status + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
  43. $( 'select[name="_backorders"] option[value="' + backorders + '"]', '.inline-edit-row' ).attr( 'selected', 'selected' );
  44. if ( 'yes' === featured ) {
  45. $( 'input[name="_featured"]', '.inline-edit-row' ).attr( 'checked', 'checked' );
  46. } else {
  47. $( 'input[name="_featured"]', '.inline-edit-row' ).removeAttr( 'checked' );
  48. }
  49. // Conditional display
  50. var product_type = $wc_inline_data.find( '.product_type' ).text(),
  51. product_is_virtual = $wc_inline_data.find( '.product_is_virtual' ).text();
  52. var product_supports_stock_status = 'external' !== product_type;
  53. var product_supports_stock_fields = 'external' !== product_type && 'grouped' !== product_type;
  54. $( '.stock_fields, .manage_stock_field, .stock_status_field, .backorder_field' ).show();
  55. if ( product_supports_stock_fields ) {
  56. if ( 'yes' === manage_stock ) {
  57. $( '.stock_fields' ).show().removeAttr( 'style' );
  58. $( '.stock_status_field' ).hide();
  59. $( '.manage_stock_field input' ).prop( 'checked', true );
  60. } else {
  61. $( '.stock_qty_field', '.inline-edit-row' ).hide();
  62. $( '.stock_status_field' ).show().removeAttr( 'style' );
  63. $( '.manage_stock_field input' ).prop( 'checked', false );
  64. }
  65. } else if ( product_supports_stock_status ) {
  66. $( '.stock_fields, .manage_stock_field, .backorder_field' ).hide();
  67. } else {
  68. $( '.stock_fields, .manage_stock_field, .stock_status_field, .backorder_field' ).hide();
  69. }
  70. if ( 'simple' === product_type || 'external' === product_type ) {
  71. $( '.price_fields', '.inline-edit-row' ).show().removeAttr( 'style' );
  72. } else {
  73. $( '.price_fields', '.inline-edit-row' ).hide();
  74. }
  75. if ( 'yes' === product_is_virtual ) {
  76. $( '.dimension_fields', '.inline-edit-row' ).hide();
  77. } else {
  78. $( '.dimension_fields', '.inline-edit-row' ).show().removeAttr( 'style' );
  79. }
  80. // Rename core strings
  81. $( 'input[name="comment_status"]' ).parent().find( '.checkbox-title' ).text( woocommerce_quick_edit.strings.allow_reviews );
  82. });
  83. $( '#the-list' ).on( 'change', '.inline-edit-row input[name="_manage_stock"]', function() {
  84. if ( $( this ).is( ':checked' ) ) {
  85. $( '.stock_qty_field', '.inline-edit-row' ).show().removeAttr( 'style' );
  86. $( '.stock_status_field' ).hide();
  87. } else {
  88. $( '.stock_qty_field', '.inline-edit-row' ).hide();
  89. $( '.stock_status_field' ).show().removeAttr( 'style' );
  90. }
  91. });
  92. $( '#wpbody' ).on( 'click', '#doaction, #doaction2', function() {
  93. $( 'input.text', '.inline-edit-row' ).val( '' );
  94. $( '#woocommerce-fields' ).find( 'select' ).prop( 'selectedIndex', 0 );
  95. $( '#woocommerce-fields-bulk' ).find( '.inline-edit-group .change-input' ).hide();
  96. });
  97. $( '#wpbody' ).on( 'change', '#woocommerce-fields-bulk .inline-edit-group .change_to', function() {
  98. if ( 0 < $( this ).val() ) {
  99. $( this ).closest( 'div' ).find( '.change-input' ).show();
  100. } else {
  101. $( this ).closest( 'div' ).find( '.change-input' ).hide();
  102. }
  103. });
  104. $( '#wpbody' ).on( 'click', '.trash-product', function() {
  105. return window.confirm( woocommerce_admin.i18n_delete_product_notice );
  106. });
  107. });