No Description

quick-edit.js 6.8KB

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