2011-08-09 15:16:18 +00:00
jQuery ( function ( $ ) {
2012-11-27 16:22:47 +00:00
2013-10-18 17:10:55 +00:00
// Allow tabbing
$ ( '#titlediv #title' ) . keyup ( function ( event ) {
var code = event . keyCode || event . which ;
if ( code == '9' && $ ( '#woocommerce-coupon-description' ) . size ( ) > 0 ) {
event . stopPropagation ( ) ;
$ ( '#woocommerce-coupon-description' ) . focus ( ) ;
return false ;
}
} ) ;
// Coupon type options
$ ( 'select#discount_type' ) . change ( function ( ) {
// Get value
var select _val = $ ( this ) . val ( ) ;
if ( select _val == 'fixed_product' || select _val == 'percent_product' ) {
$ ( '.limit_usage_to_x_items_field' ) . show ( ) ;
} else {
$ ( '.limit_usage_to_x_items_field' ) . hide ( ) ;
}
} ) . change ( ) ;
2012-11-22 13:46:01 +00:00
// Scroll to first checked category - https://github.com/scribu/wp-category-checklist-tree/blob/d1c3c1f449e1144542efa17dde84a9f52ade1739/category-checklist-tree.php
$ ( function ( ) {
$ ( '[id$="-all"] > ul.categorychecklist' ) . each ( function ( ) {
var $list = $ ( this ) ;
var $firstChecked = $list . find ( ':checked' ) . first ( ) ;
if ( ! $firstChecked . length )
return ;
2012-08-01 12:43:46 +00:00
2013-06-28 10:22:12 +00:00
var pos _first = $list . find ( 'input' ) . position ( ) . top ;
2012-11-22 13:46:01 +00:00
var pos _checked = $firstChecked . position ( ) . top ;
$list . closest ( '.tabs-panel' ) . scrollTop ( pos _checked - pos _first + 5 ) ;
} ) ;
} ) ;
2012-11-27 16:22:47 +00:00
2011-09-19 14:57:17 +00:00
// Prevent enter submitting post form
2011-11-05 19:03:03 +00:00
$ ( "#upsell_product_data" ) . bind ( "keypress" , function ( e ) {
2011-09-28 12:34:41 +00:00
if ( e . keyCode == 13 ) return false ;
2011-09-19 14:57:17 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
// Type box
$ ( '.type_box' ) . appendTo ( '#woocommerce-product-data h3.hndle span' ) ;
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
$ ( function ( ) {
2012-08-01 12:43:46 +00:00
// Prevent inputs in meta box headings opening/closing contents
$ ( '#woocommerce-product-data h3.hndle' ) . unbind ( 'click.postboxes' ) ;
2012-07-22 12:50:45 +00:00
jQuery ( '#woocommerce-product-data' ) . on ( 'click' , 'h3.hndle' , function ( event ) {
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
// If the user clicks on some form input inside the h3 the box should not be toggled
2012-08-01 12:43:46 +00:00
if ( $ ( event . target ) . filter ( 'input, option, label, select' ) . length )
2012-07-22 12:50:45 +00:00
return ;
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
$ ( '#woocommerce-product-data' ) . toggleClass ( 'closed' ) ;
} ) ;
} ) ;
2012-08-01 12:43:46 +00:00
2013-11-12 17:01:13 +00:00
$ ( function ( ) {
jQuery ( '.wc-metabox > h3' ) . click ( function ( event ) {
$ ( this ) . parent ( '.wc-metabox' ) . toggleClass ( 'closed' ) . toggleClass ( 'open' ) ;
} ) ;
} ) ;
2012-10-10 17:03:49 +00:00
// Order emails
$ ( '#order-emails a.show-order-emails' ) . click ( function ( ) {
if ( $ ( '#order-emails-select' ) . is ( ":hidden" ) ) {
$ ( '#order-emails-select' ) . slideDown ( 'fast' ) ;
$ ( this ) . hide ( ) ;
}
return false ;
} ) ;
$ ( '#order-emails a.hide-order-emails' ) . click ( function ( ) {
2012-10-12 13:33:46 +00:00
$ ( 'input[name="order_email[]"]' ) . each ( function ( ) { $ ( this ) . attr ( 'checked' , false ) } ) ;
2012-10-10 17:03:49 +00:00
if ( $ ( '#order-emails-select' ) . is ( ":visible" ) ) {
$ ( '#order-emails-select' ) . slideUp ( 'fast' ) ;
$ ( '#order-emails a.show-order-emails' ) . show ( ) ;
}
return false ;
} ) ;
2012-07-22 12:50:45 +00:00
// Catalog Visibility
$ ( '#catalog-visibility .edit-catalog-visibility' ) . click ( function ( ) {
if ( $ ( '#catalog-visibility-select' ) . is ( ":hidden" ) ) {
$ ( '#catalog-visibility-select' ) . slideDown ( 'fast' ) ;
$ ( this ) . hide ( ) ;
}
return false ;
} ) ;
$ ( '#catalog-visibility .save-post-visibility' ) . click ( function ( ) {
$ ( '#catalog-visibility-select' ) . slideUp ( 'fast' ) ;
$ ( '#catalog-visibility .edit-catalog-visibility' ) . show ( ) ;
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
var value = $ ( 'input[name=_visibility]:checked' ) . val ( ) ;
var label = $ ( 'input[name=_visibility]:checked' ) . attr ( 'data-label' ) ;
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
if ( $ ( 'input[name=_featured]' ) . is ( ':checked' ) ) {
2013-08-06 10:41:20 +00:00
label = label + ', ' + woocommerce _admin _meta _boxes . featured _label
2012-07-22 12:50:45 +00:00
$ ( 'input[name=_featured]' ) . attr ( 'checked' , 'checked' ) ;
}
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
$ ( '#catalog-visibility-display' ) . text ( label ) ;
return false ;
} ) ;
$ ( '#catalog-visibility .cancel-post-visibility' ) . click ( function ( ) {
$ ( '#catalog-visibility-select' ) . slideUp ( 'fast' ) ;
$ ( '#catalog-visibility .edit-catalog-visibility' ) . show ( ) ;
2012-08-01 12:43:46 +00:00
2013-01-04 15:30:31 +00:00
var current _visibility = $ ( '#current_visibility' ) . val ( ) ;
2012-07-22 12:50:45 +00:00
var current _featured = $ ( '#current_featured' ) . val ( ) ;
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
$ ( 'input[name=_visibility]' ) . removeAttr ( 'checked' ) ;
$ ( 'input[name=_visibility][value=' + current _visibility + ']' ) . attr ( 'checked' , 'checked' ) ;
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
var label = $ ( 'input[name=_visibility]:checked' ) . attr ( 'data-label' ) ;
if ( current _featured == 'yes' ) {
2013-08-06 10:41:20 +00:00
label = label + ', ' + woocommerce _admin _meta _boxes . featured _label
2012-07-22 12:50:45 +00:00
$ ( 'input[name=_featured]' ) . attr ( 'checked' , 'checked' ) ;
} else {
$ ( 'input[name=_featured]' ) . removeAttr ( 'checked' ) ;
}
2012-08-01 12:43:46 +00:00
2012-07-22 12:50:45 +00:00
$ ( '#catalog-visibility-display' ) . text ( label ) ;
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
// TABS
2012-08-15 18:28:08 +00:00
$ ( 'ul.wc-tabs' ) . show ( ) ;
2011-11-05 19:03:03 +00:00
$ ( 'div.panel-wrap' ) . each ( function ( ) {
2012-12-05 15:05:50 +00:00
$ ( this ) . find ( 'div.panel:not(:first)' ) . hide ( ) ;
2011-08-09 15:16:18 +00:00
} ) ;
2012-08-15 18:28:08 +00:00
$ ( 'ul.wc-tabs a' ) . click ( function ( ) {
2011-11-05 19:03:03 +00:00
var panel _wrap = $ ( this ) . closest ( 'div.panel-wrap' ) ;
2012-08-15 18:28:08 +00:00
$ ( 'ul.wc-tabs li' , panel _wrap ) . removeClass ( 'active' ) ;
2011-11-05 19:03:03 +00:00
$ ( this ) . parent ( ) . addClass ( 'active' ) ;
$ ( 'div.panel' , panel _wrap ) . hide ( ) ;
$ ( $ ( this ) . attr ( 'href' ) ) . show ( ) ;
2011-08-09 15:16:18 +00:00
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-03-06 15:46:53 +00:00
// Chosen selects
jQuery ( "select.chosen_select" ) . chosen ( ) ;
2012-08-01 12:43:46 +00:00
2012-03-06 15:46:53 +00:00
jQuery ( "select.chosen_select_nostd" ) . chosen ( {
allow _single _deselect : 'true'
} ) ;
2012-08-01 12:43:46 +00:00
2012-03-12 17:26:11 +00:00
// Ajax Chosen Product Selectors
2012-03-06 15:46:53 +00:00
jQuery ( "select.ajax_chosen_select_products" ) . ajaxChosen ( {
method : 'GET' ,
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2012-03-06 15:46:53 +00:00
dataType : 'json' ,
2012-07-31 17:26:25 +00:00
afterTypeDelay : 100 ,
2012-03-06 15:46:53 +00:00
data : {
action : 'woocommerce_json_search_products' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . search _products _nonce
2012-03-06 15:46:53 +00:00
}
} , function ( data ) {
2012-08-01 12:43:46 +00:00
2012-03-06 15:46:53 +00:00
var terms = { } ;
2012-08-01 12:43:46 +00:00
2012-03-06 15:46:53 +00:00
$ . each ( data , function ( i , val ) {
terms [ i ] = val ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-03-06 15:46:53 +00:00
return terms ;
2012-08-01 12:43:46 +00:00
} ) ;
2012-03-12 17:26:11 +00:00
jQuery ( "select.ajax_chosen_select_products_and_variations" ) . ajaxChosen ( {
method : 'GET' ,
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2012-03-12 17:26:11 +00:00
dataType : 'json' ,
2012-03-13 12:18:15 +00:00
afterTypeDelay : 100 ,
2012-03-12 17:26:11 +00:00
data : {
action : 'woocommerce_json_search_products_and_variations' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . search _products _nonce
2012-03-12 17:26:11 +00:00
}
} , function ( data ) {
2012-08-01 12:43:46 +00:00
2012-07-31 17:26:25 +00:00
var terms = { } ;
2012-08-01 12:43:46 +00:00
2012-07-31 17:26:25 +00:00
$ . each ( data , function ( i , val ) {
terms [ i ] = val ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-07-31 17:26:25 +00:00
return terms ;
} ) ;
2012-03-06 15:46:53 +00:00
2013-11-26 13:54:34 +00:00
jQuery ( "select.ajax_chosen_select_downloadable_products_and_variations" ) . ajaxChosen ( {
method : 'GET' ,
url : woocommerce _admin _meta _boxes . ajax _url ,
dataType : 'json' ,
afterTypeDelay : 100 ,
data : {
action : 'woocommerce_json_search_downloadable_products_and_variations' ,
security : woocommerce _admin _meta _boxes . search _products _nonce
}
} , function ( data ) {
var terms = { } ;
$ . each ( data , function ( i , val ) {
terms [ i ] = val ;
} ) ;
return terms ;
} ) ;
2011-08-09 15:16:18 +00:00
// ORDERS
2012-01-27 15:00:03 +00:00
jQuery ( '#woocommerce-order-actions input, #woocommerce-order-actions a' ) . click ( function ( ) {
window . onbeforeunload = '' ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-02-28 13:06:58 +00:00
$ ( 'a.edit_address' ) . click ( function ( event ) {
2011-11-25 19:31:06 +00:00
$ ( this ) . hide ( ) ;
2012-12-13 00:47:40 +00:00
$ ( this ) . closest ( '.order_data_column' ) . find ( 'div.address' ) . hide ( ) ;
$ ( this ) . closest ( '.order_data_column' ) . find ( 'div.edit_address' ) . show ( ) ;
2012-02-28 13:06:58 +00:00
event . preventDefault ( ) ;
2011-11-25 19:31:06 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
$ ( '#order_items_list' ) . on ( 'init_row' , 'tr.item' , function ( ) {
var $row = $ ( this ) ;
var $qty = $row . find ( 'input.quantity' ) ;
var qty = $qty . val ( ) ;
2012-11-27 16:22:47 +00:00
2014-02-12 15:01:56 +00:00
var line _subtotal = accounting . unformat ( $row . find ( 'input.line_subtotal' ) . val ( ) , woocommerce _admin . mon _decimal _point ) ;
var line _total = accounting . unformat ( $row . find ( 'input.line_total' ) . val ( ) , woocommerce _admin . mon _decimal _point ) ;
var line _tax = accounting . unformat ( $row . find ( 'input.line_tax' ) . val ( ) , woocommerce _admin . mon _decimal _point ) ;
var line _subtotal _tax = accounting . unformat ( $row . find ( 'input.line_subtotal_tax' ) . val ( ) , woocommerce _admin . mon _decimal _point ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
if ( qty ) {
2013-10-24 12:15:42 +00:00
unit _subtotal = parseFloat ( accounting . toFixed ( ( line _subtotal / qty ) , woocommerce _admin _meta _boxes . rounding _precision ) ) ;
unit _subtotal _tax = parseFloat ( accounting . toFixed ( ( line _subtotal _tax / qty ) , woocommerce _admin _meta _boxes . rounding _precision ) ) ;
unit _total = parseFloat ( accounting . toFixed ( ( line _total / qty ) , woocommerce _admin _meta _boxes . rounding _precision ) ) ;
unit _total _tax = parseFloat ( accounting . toFixed ( ( line _tax / qty ) , woocommerce _admin _meta _boxes . rounding _precision ) ) ;
2012-09-18 18:07:13 +00:00
} else {
unit _subtotal = unit _subtotal _tax = unit _total = unit _total _tax = 0 ;
}
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
$qty . attr ( 'data-o_qty' , qty ) ;
$row . attr ( 'data-unit_subtotal' , unit _subtotal ) ;
$row . attr ( 'data-unit_subtotal_tax' , unit _subtotal _tax ) ;
$row . attr ( 'data-unit_total' , unit _total ) ;
$row . attr ( 'data-unit_total_tax' , unit _total _tax ) ;
} ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
// When the page is loaded, store the unit costs
$ ( '#order_items_list tr.item' ) . each ( function ( ) {
$ ( this ) . trigger ( 'init_row' ) ;
2013-08-15 15:49:09 +00:00
$ ( this ) . find ( '.edit' ) . hide ( ) ;
} ) ;
$ ( '#order_items_list' ) . on ( 'click' , 'a.edit_order_item' , function ( ) {
$ ( this ) . closest ( 'tr' ) . find ( '.view' ) . hide ( ) ;
$ ( this ) . closest ( 'tr' ) . find ( '.edit' ) . show ( ) ;
$ ( this ) . hide ( ) ;
return false ;
2012-09-18 18:07:13 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
// When the qty is changed, increase or decrease costs
$ ( '#order_items_list' ) . on ( 'change' , 'input.quantity' , function ( ) {
var $row = $ ( this ) . closest ( 'tr.item' ) ;
var qty = $ ( this ) . val ( ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
var unit _subtotal = $row . attr ( 'data-unit_subtotal' ) ;
var unit _subtotal _tax = $row . attr ( 'data-unit_subtotal_tax' ) ;
var unit _total = $row . attr ( 'data-unit_total' ) ;
var unit _total _tax = $row . attr ( 'data-unit_total_tax' ) ;
var o _qty = $ ( this ) . attr ( 'data-o_qty' ) ;
2012-11-27 16:22:47 +00:00
2013-10-24 12:15:42 +00:00
var subtotal = parseFloat ( accounting . formatNumber ( unit _subtotal * qty , woocommerce _admin _meta _boxes . rounding _precision , '' ) ) ;
var tax = parseFloat ( accounting . formatNumber ( unit _subtotal _tax * qty , woocommerce _admin _meta _boxes . rounding _precision , '' ) ) ;
var total = parseFloat ( accounting . formatNumber ( unit _total * qty , woocommerce _admin _meta _boxes . rounding _precision , '' ) ) ;
var total _tax = parseFloat ( accounting . formatNumber ( unit _total _tax * qty , woocommerce _admin _meta _boxes . rounding _precision , '' ) ) ;
2012-11-27 16:22:47 +00:00
2014-02-12 15:01:56 +00:00
subtotal = subtotal . toString ( ) . replace ( '.' , woocommerce _admin . mon _decimal _point ) ;
tax = tax . toString ( ) . replace ( '.' , woocommerce _admin . mon _decimal _point ) ;
total = total . toString ( ) . replace ( '.' , woocommerce _admin . mon _decimal _point ) ;
total _tax = total _tax . toString ( ) . replace ( '.' , woocommerce _admin . mon _decimal _point ) ;
2012-09-18 18:07:13 +00:00
$row . find ( 'input.line_subtotal' ) . val ( subtotal ) ;
$row . find ( 'input.line_total' ) . val ( total ) ;
$row . find ( 'input.line_subtotal_tax' ) . val ( tax ) ;
$row . find ( 'input.line_tax' ) . val ( total _tax ) ;
2013-04-18 20:05:53 +00:00
$ ( this ) . trigger ( 'quantity_changed' ) ;
2012-09-18 18:07:13 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
// When subtotal is changed, update the unit costs
$ ( '#order_items_list' ) . on ( 'change' , 'input.line_subtotal' , function ( ) {
var $row = $ ( this ) . closest ( 'tr.item' ) ;
var $qty = $row . find ( 'input.quantity' ) ;
var qty = $qty . val ( ) ;
2013-10-24 12:15:42 +00:00
var value = ( qty ) ? accounting . toFixed ( ( $ ( this ) . val ( ) / qty ) , woocommerce _admin _meta _boxes . rounding _precision ) : 0 ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
$row . attr ( 'data-unit_subtotal' , value ) ;
} ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
// When total is changed, update the unit costs + discount amount
$ ( '#order_items_list' ) . on ( 'change' , 'input.line_total' , function ( ) {
var $row = $ ( this ) . closest ( 'tr.item' ) ;
var $qty = $row . find ( 'input.quantity' ) ;
var qty = $qty . val ( ) ;
2013-10-24 12:15:42 +00:00
var value = ( qty ) ? accounting . toFixed ( ( $ ( this ) . val ( ) / qty ) , woocommerce _admin _meta _boxes . rounding _precision ) : 0 ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
$row . attr ( 'data-unit_total' , value ) ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-09-18 18:07:13 +00:00
// When total is changed, update the unit costs + discount amount
$ ( '#order_items_list' ) . on ( 'change' , 'input.line_subtotal_tax' , function ( ) {
var $row = $ ( this ) . closest ( 'tr.item' ) ;
var $qty = $row . find ( 'input.quantity' ) ;
var qty = $qty . val ( ) ;
2013-10-24 12:15:42 +00:00
var value = ( qty ) ? accounting . toFixed ( ( $ ( this ) . val ( ) / qty ) , woocommerce _admin _meta _boxes . rounding _precision ) : 0 ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
$row . attr ( 'data-unit_subtotal_tax' , value ) ;
} ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
// When total is changed, update the unit costs + discount amount
$ ( '#order_items_list' ) . on ( 'change' , 'input.line_tax' , function ( ) {
var $row = $ ( this ) . closest ( 'tr.item' ) ;
var $qty = $row . find ( 'input.quantity' ) ;
var qty = $qty . val ( ) ;
2013-10-24 12:15:42 +00:00
var value = ( qty ) ? accounting . toFixed ( ( $ ( this ) . val ( ) / qty ) , woocommerce _admin _meta _boxes . rounding _precision ) : 0 ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
$row . attr ( 'data-unit_total_tax' , value ) ;
} ) ;
2012-11-27 16:22:47 +00:00
// Display a total for taxes
2013-08-16 15:43:26 +00:00
$ ( '#woocommerce-order-totals' ) . on ( 'change input' , '.order_taxes_amount, .order_taxes_shipping_amount, .shipping_cost, #_order_discount' , function ( ) {
2012-11-27 16:22:47 +00:00
2013-08-16 15:43:26 +00:00
var $this = $ ( this ) ;
2013-11-12 17:43:30 +00:00
var fields = $this . closest ( '.totals_group' ) . find ( 'input[type=number], .wc_input_price' ) ;
2013-08-16 15:43:26 +00:00
var total = 0 ;
2012-11-27 16:22:47 +00:00
2012-09-20 13:43:52 +00:00
fields . each ( function ( ) {
2012-11-12 18:53:40 +00:00
if ( $ ( this ) . val ( ) )
2013-11-12 17:43:30 +00:00
total = total + accounting . unformat ( $ ( this ) . val ( ) , woocommerce _admin . mon _decimal _point ) ;
2012-09-20 13:43:52 +00:00
} ) ;
2013-10-24 12:15:42 +00:00
if ( $this . is ( '.order_taxes_amount' ) || $this . is ( '.order_taxes_shipping_amount' ) ) {
total = round ( total , woocommerce _admin _meta _boxes . currency _format _num _decimals , woocommerce _admin _meta _boxes . tax _rounding _mode ) ;
}
2012-09-20 13:43:52 +00:00
var formatted _total = accounting . formatMoney ( total , {
2013-08-06 10:41:20 +00:00
symbol : woocommerce _admin _meta _boxes . currency _format _symbol ,
decimal : woocommerce _admin _meta _boxes . currency _format _decimal _sep ,
thousand : woocommerce _admin _meta _boxes . currency _format _thousand _sep ,
precision : woocommerce _admin _meta _boxes . currency _format _num _decimals ,
format : woocommerce _admin _meta _boxes . currency _format
2012-09-20 13:43:52 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-09-20 13:43:52 +00:00
$this . closest ( '.totals_group' ) . find ( 'span.inline_total' ) . text ( formatted _total ) ;
} ) ;
2012-11-27 16:22:47 +00:00
2012-09-20 13:43:52 +00:00
$ ( 'span.inline_total' ) . closest ( '.totals_group' ) . find ( 'input' ) . change ( ) ;
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
// Calculate totals
2012-12-28 13:02:12 +00:00
$ ( 'button.calc_line_taxes' ) . click ( function ( ) {
2012-01-13 21:25:39 +00:00
// Block write panel
2013-08-06 10:41:20 +00:00
$ ( '.woocommerce_order_items_wrapper' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
var answer = confirm ( woocommerce _admin _meta _boxes . calc _line _taxes ) ;
2012-08-01 12:43:46 +00:00
2012-01-13 21:25:39 +00:00
if ( answer ) {
2012-08-01 12:43:46 +00:00
2012-11-12 14:34:10 +00:00
var $items = $ ( '#order_items_list' ) . find ( 'tr.item, tr.fee' ) ;
2012-08-01 12:43:46 +00:00
2013-04-14 20:59:18 +00:00
var shipping _country = $ ( '#_shipping_country' ) . val ( ) ;
var billing _country = $ ( '#_billing_country' ) . val ( ) ;
2013-05-28 14:27:26 +00:00
2013-04-14 20:59:18 +00:00
if ( shipping _country ) {
var country = shipping _country ;
2012-01-13 21:25:39 +00:00
var state = $ ( '#_shipping_state' ) . val ( ) ;
var postcode = $ ( '#_shipping_postcode' ) . val ( ) ;
2012-09-23 16:16:39 +00:00
var city = $ ( '#_shipping_city' ) . val ( ) ;
2013-04-14 20:59:18 +00:00
} else if ( billing _country ) {
var country = billing _country ;
2012-01-13 21:25:39 +00:00
var state = $ ( '#_billing_state' ) . val ( ) ;
var postcode = $ ( '#_billing_postcode' ) . val ( ) ;
2012-09-23 16:16:39 +00:00
var city = $ ( '#_billing_city' ) . val ( ) ;
2013-04-14 20:59:18 +00:00
} else {
2013-08-06 10:41:20 +00:00
var country = woocommerce _admin _meta _boxes . base _country ;
2013-04-14 20:59:18 +00:00
var state = '' ;
var postcode = '' ;
var city = '' ;
2012-01-13 21:25:39 +00:00
}
2012-11-27 16:22:47 +00:00
2012-11-12 18:53:40 +00:00
// Get items and values
var calculate _items = { } ;
2012-11-27 16:22:47 +00:00
2012-11-12 18:53:40 +00:00
$items . each ( function ( ) {
2012-11-27 16:22:47 +00:00
2012-01-13 21:25:39 +00:00
var $row = $ ( this ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 18:53:40 +00:00
var item _id = $row . find ( 'input.order_item_id' ) . val ( ) ;
var line _subtotal = $row . find ( 'input.line_subtotal' ) . val ( ) ;
var line _total = $row . find ( 'input.line_total' ) . val ( ) ;
var tax _class = $row . find ( 'select.tax_class' ) . val ( ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 18:53:40 +00:00
calculate _items [ item _id ] = { } ;
calculate _items [ item _id ] . line _subtotal = line _subtotal ;
calculate _items [ item _id ] . line _total = line _total ;
calculate _items [ item _id ] . tax _class = tax _class ;
} ) ;
2012-11-27 16:22:47 +00:00
2013-08-16 15:43:26 +00:00
order _shipping = 0 ;
2013-11-12 17:43:30 +00:00
$ ( '#shipping_rows' ) . find ( 'input[type=number], .wc_input_price' ) . each ( function ( ) {
2013-08-16 15:43:26 +00:00
cost = $ ( this ) . val ( ) || '0' ;
2013-11-12 17:43:30 +00:00
cost = accounting . unformat ( cost , woocommerce _admin . mon _decimal _point ) ;
2013-08-16 15:43:26 +00:00
order _shipping = order _shipping + parseFloat ( cost ) ;
} ) ;
2012-11-12 18:53:40 +00:00
var data = {
action : 'woocommerce_calc_line_taxes' ,
2013-08-06 10:41:20 +00:00
order _id : woocommerce _admin _meta _boxes . post _id ,
2012-11-12 18:53:40 +00:00
items : calculate _items ,
2013-08-16 15:43:26 +00:00
shipping : order _shipping ,
2012-11-12 18:53:40 +00:00
country : country ,
state : state ,
postcode : postcode ,
city : city ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . calc _totals _nonce
2012-11-12 18:53:40 +00:00
} ;
2013-08-06 10:41:20 +00:00
$ . post ( woocommerce _admin _meta _boxes . ajax _url , data , function ( response ) {
2012-12-13 01:27:34 +00:00
2013-01-22 16:48:28 +00:00
if ( response ) {
$items . each ( function ( ) {
var $row = $ ( this ) ;
var item _id = $row . find ( 'input.order_item_id' ) . val ( ) ;
2013-08-16 16:00:49 +00:00
$row . find ( '.edit_order_item' ) . click ( ) ;
2012-11-27 16:22:47 +00:00
2013-09-13 15:34:37 +00:00
if ( response [ 'item_taxes' ] [ item _id ] ) {
$row . find ( 'input.line_tax' ) . val ( response [ 'item_taxes' ] [ item _id ] [ 'line_tax' ] ) . change ( ) ;
$row . find ( 'input.line_subtotal_tax' ) . val ( response [ 'item_taxes' ] [ item _id ] [ 'line_subtotal_tax' ] ) . change ( ) ;
}
if ( response [ 'tax_row_html' ] )
$ ( '#tax_rows' ) . empty ( ) . append ( response [ 'tax_row_html' ] ) ;
2013-01-22 16:48:28 +00:00
} ) ;
2013-08-16 15:43:26 +00:00
$ ( '#tax_rows' ) . find ( 'input' ) . change ( ) ;
2013-01-22 16:48:28 +00:00
}
2012-11-27 16:22:47 +00:00
2012-11-12 18:53:40 +00:00
$ ( '.woocommerce_order_items_wrapper' ) . unblock ( ) ;
2012-01-13 21:25:39 +00:00
} ) ;
} else {
$ ( '.woocommerce_order_items_wrapper' ) . unblock ( ) ;
}
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-12-28 13:02:12 +00:00
$ ( 'button.calc_totals' ) . click ( function ( ) {
2012-01-13 21:25:39 +00:00
// Block write panel
2013-08-06 10:41:20 +00:00
$ ( '#woocommerce-order-totals' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
var answer = confirm ( woocommerce _admin _meta _boxes . calc _totals ) ;
2012-08-01 12:43:46 +00:00
2012-01-13 21:25:39 +00:00
if ( answer ) {
2012-08-01 12:43:46 +00:00
2012-01-13 21:25:39 +00:00
// Get row totals
2012-06-10 08:08:11 +00:00
var line _totals = 0 ;
2013-08-16 15:43:26 +00:00
var tax = 0 ;
var shipping = 0 ;
2013-02-25 11:39:15 +00:00
var order _discount = $ ( '#_order_discount' ) . val ( ) || '0' ;
2012-08-01 12:43:46 +00:00
2013-02-19 17:16:19 +00:00
order _discount = accounting . unformat ( order _discount . replace ( ',' , '.' ) ) ;
2013-11-12 17:43:30 +00:00
$ ( '#shipping_rows' ) . find ( 'input[type=number], .wc_input_price' ) . each ( function ( ) {
2013-08-16 15:43:26 +00:00
cost = $ ( this ) . val ( ) || '0' ;
2013-11-12 17:43:30 +00:00
cost = accounting . unformat ( cost , woocommerce _admin . mon _decimal _point ) ;
2013-08-16 15:43:26 +00:00
shipping = shipping + parseFloat ( cost ) ;
2012-11-12 14:34:10 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2013-11-12 17:43:30 +00:00
$ ( '#tax_rows' ) . find ( 'input[type=number], .wc_input_price' ) . each ( function ( ) {
2013-08-16 15:43:26 +00:00
cost = $ ( this ) . val ( ) || '0' ;
2013-11-12 17:43:30 +00:00
cost = accounting . unformat ( cost , woocommerce _admin . mon _decimal _point ) ;
2013-08-16 15:43:26 +00:00
tax = tax + parseFloat ( cost ) ;
} ) ;
2012-08-01 12:43:46 +00:00
2013-08-16 15:43:26 +00:00
$ ( '#order_items_list tr.item, #order_items_list tr.fee' ) . each ( function ( ) {
line _total = $ ( this ) . find ( 'input.line_total' ) . val ( ) || '0' ;
line _totals = line _totals + accounting . unformat ( line _total . replace ( ',' , '.' ) ) ;
2012-01-13 21:25:39 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2012-01-13 21:25:39 +00:00
// Tax
2013-08-16 15:43:26 +00:00
if ( woocommerce _admin _meta _boxes . round _at _subtotal == 'yes' )
2013-10-24 12:15:42 +00:00
tax = parseFloat ( accounting . toFixed ( tax , woocommerce _admin _meta _boxes . rounding _precision ) ) ;
2012-11-27 16:22:47 +00:00
2013-08-16 15:43:26 +00:00
// Set Total
2013-11-12 17:43:30 +00:00
$ ( '#_order_total' ) . val ( accounting . formatNumber ( line _totals + tax + shipping - order _discount , woocommerce _admin _meta _boxes . currency _format _num _decimals , '' , woocommerce _admin . mon _decimal _point ) ) . change ( ) ;
2013-08-16 15:43:26 +00:00
}
2012-08-01 12:43:46 +00:00
2013-08-16 15:43:26 +00:00
$ ( '#woocommerce-order-totals' ) . unblock ( ) ;
2011-08-09 15:16:18 +00:00
return false ;
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 13:41:54 +00:00
// Add a line item
2012-10-19 14:05:23 +00:00
$ ( '#woocommerce-order-items button.add_order_item' ) . click ( function ( ) {
2012-11-27 16:22:47 +00:00
2012-04-10 00:39:31 +00:00
var add _item _ids = $ ( 'select#add_item_id' ) . val ( ) ;
2012-08-01 12:43:46 +00:00
2012-04-10 00:39:31 +00:00
if ( add _item _ids ) {
2012-08-01 12:43:46 +00:00
2012-04-10 00:39:31 +00:00
count = add _item _ids . length ;
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
$ ( 'table.woocommerce_order_items' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-08-01 12:43:46 +00:00
2012-04-10 00:39:31 +00:00
$ . each ( add _item _ids , function ( index , value ) {
2012-08-01 12:43:46 +00:00
2012-04-10 00:39:31 +00:00
var data = {
2013-11-25 16:26:07 +00:00
action : 'woocommerce_add_order_item' ,
2012-04-10 00:39:31 +00:00
item _to _add : value ,
2013-08-06 10:41:20 +00:00
order _id : woocommerce _admin _meta _boxes . post _id ,
security : woocommerce _admin _meta _boxes . order _item _nonce
2012-04-10 00:39:31 +00:00
} ;
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
$ . post ( woocommerce _admin _meta _boxes . ajax _url , data , function ( response ) {
2012-08-01 12:43:46 +00:00
$ ( 'table.woocommerce_order_items tbody#order_items_list' ) . append ( response ) ;
2012-04-10 00:39:31 +00:00
if ( ! -- count ) {
2013-08-02 15:54:28 +00:00
$ ( 'select#add_item_id, #add_item_id_chosen .chosen-choices' ) . css ( 'border-color' , '' ) . val ( '' ) ;
2012-04-10 00:39:31 +00:00
jQuery ( ".tips" ) . tipTip ( {
'attribute' : 'data-tip' ,
'fadeIn' : 50 ,
2012-07-22 12:50:45 +00:00
'fadeOut' : 50 ,
'delay' : 200
2012-04-10 00:39:31 +00:00
} ) ;
2013-08-02 15:54:28 +00:00
$ ( 'select#add_item_id' ) . trigger ( "chosen:updated" ) ;
2012-04-10 00:39:31 +00:00
$ ( 'table.woocommerce_order_items' ) . unblock ( ) ;
2012-08-01 12:43:46 +00:00
}
2012-11-27 16:22:47 +00:00
2012-09-18 18:07:13 +00:00
$ ( '#order_items_list tr.new_row' ) . trigger ( 'init_row' ) . removeClass ( 'new_row' ) ;
2012-04-10 00:39:31 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
} ) ;
} else {
2013-08-02 15:54:28 +00:00
$ ( 'select#add_item_id, #add_item_id_chosen .chosen-choices' ) . css ( 'border-color' , 'red' ) ;
2011-08-09 15:16:18 +00:00
}
2012-11-12 13:41:54 +00:00
return false ;
2011-08-09 15:16:18 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 13:41:54 +00:00
// Add a fee
$ ( '#woocommerce-order-items button.add_order_fee' ) . click ( function ( ) {
2012-11-27 16:22:47 +00:00
2013-08-06 10:41:20 +00:00
$ ( 'table.woocommerce_order_items' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-11-12 13:41:54 +00:00
var data = {
action : 'woocommerce_add_order_fee' ,
2013-08-06 10:41:20 +00:00
order _id : woocommerce _admin _meta _boxes . post _id ,
security : woocommerce _admin _meta _boxes . order _item _nonce
2012-11-12 13:41:54 +00:00
} ;
2013-08-06 10:41:20 +00:00
$ . post ( woocommerce _admin _meta _boxes . ajax _url , data , function ( response ) {
2012-11-12 13:41:54 +00:00
$ ( 'table.woocommerce_order_items tbody#order_items_list' ) . append ( response ) ;
$ ( 'table.woocommerce_order_items' ) . unblock ( ) ;
} ) ;
return false ;
} ) ;
// Add some meta to a line item
2012-12-28 13:02:12 +00:00
$ ( '#order_items_list' ) . on ( 'click' , 'button.add_order_item_meta' , function ( ) {
2012-11-27 16:22:47 +00:00
2012-10-18 17:56:28 +00:00
var $button = $ ( this ) ;
var $item = $button . closest ( 'tr.item' ) ;
2012-11-27 16:22:47 +00:00
2012-10-18 17:56:28 +00:00
var data = {
2012-10-19 17:59:17 +00:00
order _item _id : $item . attr ( 'data-order_item_id' ) ,
2013-11-25 16:30:12 +00:00
action : 'woocommerce_add_order_item_meta' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . order _item _nonce
2012-10-18 17:56:28 +00:00
} ;
2012-11-27 16:22:47 +00:00
2013-08-06 10:41:20 +00:00
$ ( 'table.woocommerce_order_items' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-11-27 16:22:47 +00:00
2012-10-18 17:56:28 +00:00
$ . ajax ( {
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2012-10-18 17:56:28 +00:00
data : data ,
type : 'POST' ,
success : function ( response ) {
$item . find ( 'tbody.meta_items' ) . append ( response ) ;
$ ( 'table.woocommerce_order_items' ) . unblock ( ) ;
}
} ) ;
2012-08-01 12:43:46 +00:00
2011-08-19 20:11:04 +00:00
return false ;
2011-08-09 15:16:18 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2012-12-28 13:02:12 +00:00
$ ( '#order_items_list' ) . on ( 'click' , 'button.remove_order_item_meta' , function ( ) {
2013-08-06 10:41:20 +00:00
var answer = confirm ( woocommerce _admin _meta _boxes . remove _item _meta )
2012-10-18 17:56:28 +00:00
if ( answer ) {
var $row = $ ( this ) . closest ( 'tr' ) ;
2012-11-27 16:22:47 +00:00
2012-10-18 17:56:28 +00:00
var data = {
meta _id : $row . attr ( 'data-meta_id' ) ,
action : 'woocommerce_remove_order_item_meta' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . order _item _nonce
2012-10-18 17:56:28 +00:00
} ;
2012-11-27 16:22:47 +00:00
2013-08-06 10:41:20 +00:00
$ ( 'table.woocommerce_order_items' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-11-27 16:22:47 +00:00
2012-10-18 17:56:28 +00:00
$ . ajax ( {
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2012-10-18 17:56:28 +00:00
data : data ,
type : 'POST' ,
success : function ( response ) {
$row . hide ( ) ;
$ ( 'table.woocommerce_order_items' ) . unblock ( ) ;
}
} ) ;
2011-08-19 20:11:04 +00:00
}
return false ;
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-10 16:18:20 +00:00
// Bulk actions for line items
2012-11-12 12:30:37 +00:00
$ ( '#woocommerce-order-items' ) . on ( 'click' , 'input.check-column' , function ( ) {
if ( $ ( this ) . is ( ':checked' ) )
$ ( '#woocommerce-order-items' ) . find ( '.check-column input' ) . attr ( 'checked' , 'checked' ) ;
else
$ ( '#woocommerce-order-items' ) . find ( '.check-column input' ) . removeAttr ( 'checked' ) ;
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-10 16:18:20 +00:00
$ ( '#woocommerce-order-items' ) . on ( 'click' , '.do_bulk_action' , function ( ) {
2012-11-27 16:22:47 +00:00
2012-11-10 16:18:20 +00:00
var action = $ ( this ) . closest ( '.bulk_actions' ) . find ( 'select' ) . val ( ) ;
var selected _rows = $ ( '#woocommerce-order-items' ) . find ( '.check-column input:checked' ) ;
2012-11-12 12:22:35 +00:00
var item _ids = [ ] ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
$ ( selected _rows ) . each ( function ( ) {
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
var $item = $ ( this ) . closest ( 'tr.item, tr.fee' ) ;
item _ids . push ( $item . attr ( 'data-order_item_id' ) ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2013-02-27 12:50:02 +00:00
if ( item _ids . length == 0 ) {
2013-08-06 10:41:20 +00:00
alert ( woocommerce _admin _meta _boxes . i18n _select _items ) ;
2013-02-27 12:50:02 +00:00
return ;
}
2012-11-10 16:18:20 +00:00
if ( action == 'delete' ) {
2012-11-27 16:22:47 +00:00
2013-08-06 10:41:20 +00:00
var answer = confirm ( woocommerce _admin _meta _boxes . remove _item _notice ) ;
2012-11-27 16:22:47 +00:00
2012-11-10 16:18:20 +00:00
if ( answer ) {
2012-11-27 16:22:47 +00:00
2013-08-06 10:41:20 +00:00
$ ( 'table.woocommerce_order_items' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
var data = {
order _item _ids : item _ids ,
action : 'woocommerce_remove_order_item' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . order _item _nonce
2012-11-12 12:22:35 +00:00
} ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
$ . ajax ( {
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2012-11-12 12:22:35 +00:00
data : data ,
type : 'POST' ,
success : function ( response ) {
2012-11-12 14:34:10 +00:00
$ ( selected _rows ) . each ( function ( ) {
2013-02-26 14:36:18 +00:00
$ ( this ) . closest ( 'tr.item, tr.fee' ) . remove ( ) ;
2012-11-12 14:34:10 +00:00
} ) ;
2012-11-12 12:22:35 +00:00
$ ( 'table.woocommerce_order_items' ) . unblock ( ) ;
}
2012-11-10 16:18:20 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-10 16:18:20 +00:00
}
2012-11-27 16:22:47 +00:00
2012-11-10 16:25:50 +00:00
} else if ( action == 'reduce_stock' ) {
2012-11-27 16:22:47 +00:00
2013-08-06 10:41:20 +00:00
$ ( 'table.woocommerce_order_items' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
var quantities = { } ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
$ ( selected _rows ) . each ( function ( ) {
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
var $item = $ ( this ) . closest ( 'tr.item, tr.fee' ) ;
var $qty = $item . find ( 'input.quantity' ) ;
2012-11-27 16:22:47 +00:00
quantities [ $item . attr ( 'data-order_item_id' ) ] = $qty . val ( ) ;
2012-11-12 12:22:35 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
var data = {
2013-08-06 10:41:20 +00:00
order _id : woocommerce _admin _meta _boxes . post _id ,
2012-11-12 12:22:35 +00:00
order _item _ids : item _ids ,
order _item _qty : quantities ,
action : 'woocommerce_reduce_order_item_stock' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . order _item _nonce
2012-11-12 12:22:35 +00:00
} ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
$ . ajax ( {
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2012-11-12 12:22:35 +00:00
data : data ,
type : 'POST' ,
success : function ( response ) {
alert ( response ) ;
$ ( 'table.woocommerce_order_items' ) . unblock ( ) ;
}
2012-11-27 16:22:47 +00:00
} ) ;
2012-11-12 12:22:35 +00:00
} else if ( action == 'increase_stock' ) {
2013-08-06 10:41:20 +00:00
$ ( 'table.woocommerce_order_items' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
var quantities = { } ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
$ ( selected _rows ) . each ( function ( ) {
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
var $item = $ ( this ) . closest ( 'tr.item, tr.fee' ) ;
var $qty = $item . find ( 'input.quantity' ) ;
2012-11-27 16:22:47 +00:00
quantities [ $item . attr ( 'data-order_item_id' ) ] = $qty . val ( ) ;
2012-11-12 12:22:35 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
var data = {
2013-08-06 10:41:20 +00:00
order _id : woocommerce _admin _meta _boxes . post _id ,
2012-11-12 12:22:35 +00:00
order _item _ids : item _ids ,
order _item _qty : quantities ,
action : 'woocommerce_increase_order_item_stock' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . order _item _nonce
2012-11-12 12:22:35 +00:00
} ;
2012-11-27 16:22:47 +00:00
2012-11-12 12:22:35 +00:00
$ . ajax ( {
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2012-11-12 12:22:35 +00:00
data : data ,
type : 'POST' ,
success : function ( response ) {
alert ( response ) ;
$ ( 'table.woocommerce_order_items' ) . unblock ( ) ;
}
2012-11-27 16:22:47 +00:00
} ) ;
2012-11-10 16:18:20 +00:00
}
2012-11-27 16:22:47 +00:00
2012-11-10 16:18:20 +00:00
return false ;
} ) ;
2012-11-27 16:22:47 +00:00
2013-11-27 14:03:04 +00:00
// 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 ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-12-28 13:02:12 +00:00
$ ( 'button.load_customer_billing' ) . click ( function ( ) {
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
var answer = confirm ( woocommerce _admin _meta _boxes . load _billing ) ;
2011-11-26 16:15:25 +00:00
if ( answer ) {
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
// Get user ID to load data for
var user _id = $ ( '#customer_user' ) . val ( ) ;
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
if ( ! user _id ) {
2013-08-06 10:41:20 +00:00
alert ( woocommerce _admin _meta _boxes . no _customer _selected ) ;
2011-11-26 16:15:25 +00:00
return false ;
}
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
var data = {
user _id : user _id ,
type _to _load : 'billing' ,
action : 'woocommerce_get_customer_details' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . get _customer _details _nonce
2011-11-26 16:15:25 +00:00
} ;
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
$ ( this ) . closest ( '.edit_address' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
$ . ajax ( {
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2011-11-26 16:15:25 +00:00
data : data ,
type : 'POST' ,
success : function ( response ) {
2013-01-22 14:35:10 +00:00
var info = response ;
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
if ( info ) {
$ ( 'input#_billing_first_name' ) . val ( info . billing _first _name ) ;
$ ( 'input#_billing_last_name' ) . val ( info . billing _last _name ) ;
$ ( 'input#_billing_company' ) . val ( info . billing _company ) ;
$ ( 'input#_billing_address_1' ) . val ( info . billing _address _1 ) ;
$ ( 'input#_billing_address_2' ) . val ( info . billing _address _2 ) ;
$ ( 'input#_billing_city' ) . val ( info . billing _city ) ;
$ ( 'input#_billing_postcode' ) . val ( info . billing _postcode ) ;
2012-07-11 15:22:18 +00:00
$ ( '#_billing_country' ) . val ( info . billing _country ) ;
2011-11-26 16:15:25 +00:00
$ ( 'input#_billing_state' ) . val ( info . billing _state ) ;
$ ( 'input#_billing_email' ) . val ( info . billing _email ) ;
$ ( 'input#_billing_phone' ) . val ( info . billing _phone ) ;
}
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
$ ( '.edit_address' ) . unblock ( ) ;
}
} ) ;
}
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-12-28 13:02:12 +00:00
$ ( 'button.load_customer_shipping' ) . click ( function ( ) {
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
var answer = confirm ( woocommerce _admin _meta _boxes . load _shipping ) ;
2011-11-26 16:15:25 +00:00
if ( answer ) {
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
// Get user ID to load data for
var user _id = $ ( '#customer_user' ) . val ( ) ;
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
if ( ! user _id ) {
2013-08-06 10:41:20 +00:00
alert ( woocommerce _admin _meta _boxes . no _customer _selected ) ;
2011-11-26 16:15:25 +00:00
return false ;
}
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
var data = {
user _id : user _id ,
type _to _load : 'shipping' ,
action : 'woocommerce_get_customer_details' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . get _customer _details _nonce
2011-11-26 16:15:25 +00:00
} ;
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
$ ( this ) . closest ( '.edit_address' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
$ . ajax ( {
2013-08-06 10:41:20 +00:00
url : woocommerce _admin _meta _boxes . ajax _url ,
2011-11-26 16:15:25 +00:00
data : data ,
type : 'POST' ,
success : function ( response ) {
2013-01-22 14:35:10 +00:00
var info = response ;
2013-01-22 16:48:28 +00:00
2011-11-26 16:15:25 +00:00
if ( info ) {
$ ( 'input#_shipping_first_name' ) . val ( info . shipping _first _name ) ;
$ ( 'input#_shipping_last_name' ) . val ( info . shipping _last _name ) ;
$ ( 'input#_shipping_company' ) . val ( info . shipping _company ) ;
$ ( 'input#_shipping_address_1' ) . val ( info . shipping _address _1 ) ;
$ ( 'input#_shipping_address_2' ) . val ( info . shipping _address _2 ) ;
$ ( 'input#_shipping_city' ) . val ( info . shipping _city ) ;
$ ( 'input#_shipping_postcode' ) . val ( info . shipping _postcode ) ;
2012-07-11 15:22:18 +00:00
$ ( '#_shipping_country' ) . val ( info . shipping _country ) ;
2011-11-26 16:15:25 +00:00
$ ( 'input#_shipping_state' ) . val ( info . shipping _state ) ;
}
2012-08-01 12:43:46 +00:00
2011-11-26 16:15:25 +00:00
$ ( '.edit_address' ) . unblock ( ) ;
}
} ) ;
}
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2012-12-28 13:02:12 +00:00
$ ( 'button.billing-same-as-shipping' ) . click ( function ( ) {
2013-08-06 10:41:20 +00:00
var answer = confirm ( woocommerce _admin _meta _boxes . copy _billing ) ;
2011-08-09 15:16:18 +00:00
if ( answer ) {
2011-11-26 16:15:25 +00:00
$ ( 'input#_shipping_first_name' ) . val ( $ ( 'input#_billing_first_name' ) . val ( ) ) ;
$ ( 'input#_shipping_last_name' ) . val ( $ ( 'input#_billing_last_name' ) . val ( ) ) ;
$ ( 'input#_shipping_company' ) . val ( $ ( 'input#_billing_company' ) . val ( ) ) ;
$ ( 'input#_shipping_address_1' ) . val ( $ ( 'input#_billing_address_1' ) . val ( ) ) ;
$ ( 'input#_shipping_address_2' ) . val ( $ ( 'input#_billing_address_2' ) . val ( ) ) ;
$ ( 'input#_shipping_city' ) . val ( $ ( 'input#_billing_city' ) . val ( ) ) ;
$ ( 'input#_shipping_postcode' ) . val ( $ ( 'input#_billing_postcode' ) . val ( ) ) ;
2012-08-10 11:31:18 +00:00
$ ( '#_shipping_country' ) . val ( $ ( '#_billing_country' ) . val ( ) ) ;
2012-08-01 12:43:46 +00:00
$ ( 'input#_shipping_state' ) . val ( $ ( 'input#_billing_state' ) . val ( ) ) ;
2011-08-09 15:16:18 +00:00
}
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2013-08-16 15:43:26 +00:00
$ ( '.totals_group' ) . on ( 'click' , 'a.add_total_row' , function ( ) {
$ ( this ) . closest ( '.totals_group' ) . find ( '.total_rows' ) . append ( $ ( this ) . data ( 'row' ) ) ;
2012-01-27 15:00:03 +00:00
return false ;
} ) ;
2012-11-27 16:22:47 +00:00
2013-08-16 15:43:26 +00:00
$ ( '.total_rows' ) . on ( 'click' , 'a.delete_total_row' , function ( ) {
$row = $ ( this ) . closest ( '.total_row' ) ;
2013-01-25 03:26:16 +00:00
2013-08-16 15:43:26 +00:00
var row _id = $row . attr ( 'data-order_item_id' ) ;
2012-11-27 16:22:47 +00:00
2013-08-16 15:43:26 +00:00
if ( row _id ) {
$row . append ( '<input type="hidden" name="delete_order_item_id[]" value="' + row _id + '" />' ) . hide ( ) ;
} else {
$row . remove ( ) ;
}
2012-11-27 16:22:47 +00:00
2011-12-31 19:03:41 +00:00
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2013-11-28 12:03:29 +00:00
// 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 ;
} ) ;
2011-08-09 15:16:18 +00:00
// PRODUCT TYPE SPECIFIC OPTIONS
$ ( 'select#product-type' ) . change ( function ( ) {
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
// Get value
2011-11-05 19:03:03 +00:00
var select _val = $ ( this ) . val ( ) ;
2012-08-01 12:43:46 +00:00
2012-12-07 10:51:06 +00:00
if ( select _val == 'variable' ) {
2011-12-24 16:57:36 +00:00
$ ( 'input#_manage_stock' ) . change ( ) ;
2012-12-07 10:51:06 +00:00
$ ( 'input#_downloadable' ) . prop ( 'checked' , false ) ;
$ ( 'input#_virtual' ) . removeAttr ( 'checked' ) ;
2011-11-05 19:03:03 +00:00
}
2012-08-01 12:43:46 +00:00
2011-11-05 19:03:03 +00:00
else if ( select _val == 'grouped' ) {
2012-12-07 10:51:06 +00:00
$ ( 'input#_downloadable' ) . prop ( 'checked' , false ) ;
$ ( 'input#_virtual' ) . removeAttr ( 'checked' ) ;
2011-11-05 19:03:03 +00:00
}
2012-08-01 12:43:46 +00:00
2011-11-08 16:15:36 +00:00
else if ( select _val == 'external' ) {
2012-12-07 10:51:06 +00:00
$ ( 'input#_downloadable' ) . prop ( 'checked' , false ) ;
$ ( 'input#_virtual' ) . removeAttr ( 'checked' ) ;
2011-11-08 16:15:36 +00:00
}
2012-08-01 12:43:46 +00:00
2012-12-07 10:51:06 +00:00
show _and _hide _panels ( ) ;
2012-08-15 18:28:08 +00:00
$ ( 'ul.wc-tabs li:visible' ) . eq ( 0 ) . find ( 'a' ) . click ( ) ;
2012-08-01 12:43:46 +00:00
2011-08-10 17:11:11 +00:00
$ ( 'body' ) . trigger ( 'woocommerce-product-type-change' , select _val , $ ( this ) ) ;
2013-10-18 17:10:55 +00:00
2011-08-09 15:16:18 +00:00
} ) . change ( ) ;
2012-08-01 12:43:46 +00:00
2013-10-18 17:10:55 +00:00
$ ( 'ul.wc-tabs li:visible' ) . eq ( 0 ) . find ( 'a' ) . click ( ) ;
2012-12-07 10:51:06 +00:00
$ ( 'input#_downloadable, input#_virtual' ) . change ( function ( ) {
show _and _hide _panels ( ) ;
} ) ;
function show _and _hide _panels ( ) {
var product _type = $ ( 'select#product-type' ) . val ( ) ;
var is _virtual = $ ( 'input#_virtual:checked' ) . size ( ) ;
var is _downloadable = $ ( 'input#_downloadable:checked' ) . size ( ) ;
2012-08-01 12:43:46 +00:00
2012-12-07 10:51:06 +00:00
// Hide/Show all with rules
2013-02-26 15:14:49 +00:00
var hide _classes = '.hide_if_downloadable, .hide_if_virtual' ;
2013-02-28 15:44:27 +00:00
var show _classes = '.show_if_downloadable, .show_if_virtual, .show_if_external' ;
2013-02-26 15:14:49 +00:00
2013-08-06 10:41:20 +00:00
$ . each ( woocommerce _admin _meta _boxes . product _types , function ( index , value ) {
2013-02-26 15:14:49 +00:00
hide _classes = hide _classes + ', .hide_if_' + value ;
show _classes = show _classes + ', .show_if_' + value ;
} ) ;
$ ( hide _classes ) . show ( ) ;
$ ( show _classes ) . hide ( ) ;
2012-08-01 12:43:46 +00:00
2012-12-07 10:51:06 +00:00
// Shows rules
if ( is _downloadable ) {
2011-11-05 19:03:03 +00:00
$ ( '.show_if_downloadable' ) . show ( ) ;
}
2012-12-07 10:51:06 +00:00
if ( is _virtual ) {
$ ( '.show_if_virtual' ) . show ( ) ;
}
2012-08-01 12:43:46 +00:00
2013-02-10 23:02:52 +00:00
$ ( '.show_if_' + product _type ) . show ( ) ;
2012-08-01 12:43:46 +00:00
2012-12-07 10:51:06 +00:00
// Hide rules
if ( is _downloadable ) {
$ ( '.hide_if_downloadable' ) . hide ( ) ;
}
if ( is _virtual ) {
2011-12-24 15:32:18 +00:00
$ ( '.hide_if_virtual' ) . hide ( ) ;
2011-11-06 13:45:18 +00:00
}
2012-08-01 12:43:46 +00:00
2013-02-10 23:02:52 +00:00
$ ( '.hide_if_' + product _type ) . hide ( ) ;
$ ( 'input#_manage_stock' ) . change ( ) ;
2012-12-07 10:51:06 +00:00
}
2012-08-01 12:43:46 +00:00
2011-12-24 15:32:18 +00:00
// Sale price schedule
2012-10-08 11:51:00 +00:00
$ ( '.sale_price_dates_fields' ) . each ( function ( ) {
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
var $these _sale _dates = $ ( this ) ;
var sale _schedule _set = false ;
var $wrap = $these _sale _dates . closest ( 'div, table' ) ;
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
$these _sale _dates . find ( 'input' ) . each ( function ( ) {
2012-11-27 16:22:47 +00:00
if ( $ ( this ) . val ( ) != '' )
2012-10-08 11:51:00 +00:00
sale _schedule _set = true ;
} ) ;
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
if ( sale _schedule _set ) {
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
$wrap . find ( '.sale_schedule' ) . hide ( ) ;
$wrap . find ( '.sale_price_dates_fields' ) . show ( ) ;
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
} else {
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
$wrap . find ( '.sale_schedule' ) . show ( ) ;
$wrap . find ( '.sale_price_dates_fields' ) . hide ( ) ;
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
}
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
$ ( '#woocommerce-product-data' ) . on ( 'click' , '.sale_schedule' , function ( ) {
var $wrap = $ ( this ) . closest ( 'div, table' ) ;
2012-11-27 16:22:47 +00:00
2011-12-24 15:32:18 +00:00
$ ( this ) . hide ( ) ;
2012-10-08 11:51:00 +00:00
$wrap . find ( '.cancel_sale_schedule' ) . show ( ) ;
$wrap . find ( '.sale_price_dates_fields' ) . show ( ) ;
2012-11-27 16:22:47 +00:00
2011-12-24 15:32:18 +00:00
return false ;
} ) ;
2012-10-08 11:51:00 +00:00
$ ( '#woocommerce-product-data' ) . on ( 'click' , '.cancel_sale_schedule' , function ( ) {
var $wrap = $ ( this ) . closest ( 'div, table' ) ;
2012-11-27 16:22:47 +00:00
2012-10-08 11:51:00 +00:00
$ ( this ) . hide ( ) ;
$wrap . find ( '.sale_schedule' ) . show ( ) ;
$wrap . find ( '.sale_price_dates_fields' ) . hide ( ) ;
$wrap . find ( '.sale_price_dates_fields' ) . find ( 'input' ) . val ( '' ) ;
2012-11-27 16:22:47 +00:00
2011-12-24 15:32:18 +00:00
return false ;
} ) ;
2012-11-27 16:22:47 +00:00
2013-09-20 16:01:09 +00:00
// File inputs
2014-03-03 12:09:43 +00:00
$ ( '#woocommerce-product-data' ) . on ( 'click' , '.downloadable_files a.insert' , function ( ) {
2013-09-20 16:01:09 +00:00
$ ( this ) . closest ( '.downloadable_files' ) . find ( 'tbody' ) . append ( $ ( this ) . data ( 'row' ) ) ;
return false ;
} ) ;
2014-03-03 12:09:43 +00:00
$ ( '#woocommerce-product-data' ) . on ( 'click' , '.downloadable_files a.delete' , function ( ) {
2013-09-20 16:01:09 +00:00
$ ( this ) . closest ( 'tr' ) . remove ( ) ;
return false ;
} ) ;
2011-08-09 15:16:18 +00:00
// STOCK OPTIONS
2011-12-24 16:57:36 +00:00
$ ( 'input#_manage_stock' ) . change ( function ( ) {
2011-11-05 19:03:03 +00:00
if ( $ ( this ) . is ( ':checked' ) ) $ ( 'div.stock_fields' ) . show ( ) ;
else $ ( 'div.stock_fields' ) . hide ( ) ;
2011-08-09 15:16:18 +00:00
} ) . change ( ) ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
// DATE PICKER FIELDS
2012-10-08 11:51:00 +00:00
var dates = $ ( ".sale_price_dates_fields input" ) . datepicker ( {
2011-09-19 10:30:23 +00:00
defaultDate : "" ,
dateFormat : "yy-mm-dd" ,
numberOfMonths : 1 ,
showButtonPanel : true ,
showOn : "button" ,
2013-08-06 10:41:20 +00:00
buttonImage : woocommerce _admin _meta _boxes . calendar _image ,
2011-09-19 10:30:23 +00:00
buttonImageOnly : true ,
onSelect : function ( selectedDate ) {
2012-11-13 23:58:32 +00:00
var option = $ ( this ) . is ( '#_sale_price_dates_from, .sale_price_dates_from' ) ? "minDate" : "maxDate" ;
var instance = $ ( this ) . data ( "datepicker" ) ,
2011-11-05 19:03:03 +00:00
date = $ . datepicker . parseDate (
2011-09-19 10:30:23 +00:00
instance . settings . dateFormat ||
2011-11-05 19:03:03 +00:00
$ . datepicker . _defaults . dateFormat ,
2011-09-19 10:30:23 +00:00
selectedDate , instance . settings ) ;
dates . not ( this ) . datepicker ( "option" , option , date ) ;
2011-08-09 15:16:18 +00:00
}
2011-09-19 10:30:23 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2011-11-05 19:03:03 +00:00
$ ( ".date-picker" ) . datepicker ( {
2011-09-20 15:05:07 +00:00
dateFormat : "yy-mm-dd" ,
numberOfMonths : 1 ,
showButtonPanel : true ,
showOn : "button" ,
2013-08-06 10:41:20 +00:00
buttonImage : woocommerce _admin _meta _boxes . calendar _image ,
2011-09-20 15:05:07 +00:00
buttonImageOnly : true
} ) ;
2012-08-01 12:43:46 +00:00
2012-03-26 17:30:00 +00:00
$ ( ".date-picker-field" ) . datepicker ( {
dateFormat : "yy-mm-dd" ,
numberOfMonths : 1 ,
showButtonPanel : true ,
} ) ;
2012-08-01 12:43:46 +00:00
2012-02-25 11:43:25 +00:00
// META BOXES
2012-08-01 12:43:46 +00:00
2012-02-13 19:21:52 +00:00
// Open/close
2012-03-15 13:20:44 +00:00
jQuery ( '.wc-metaboxes-wrapper' ) . on ( 'click' , '.wc-metabox h3' , function ( event ) {
// If the user clicks on some form input inside the h3, like a select list (for variations), the box should not be toggled
2012-03-20 14:59:04 +00:00
if ( $ ( event . target ) . filter ( ':input, option' ) . length ) return ;
2012-03-15 13:20:44 +00:00
2012-02-25 19:48:09 +00:00
jQuery ( this ) . next ( '.wc-metabox-content' ) . toggle ( ) ;
2012-12-18 07:23:13 +00:00
} )
. on ( 'click' , '.expand_all' , function ( event ) {
jQuery ( this ) . closest ( '.wc-metaboxes-wrapper' ) . find ( '.wc-metabox > table' ) . show ( ) ;
return false ;
} )
. on ( 'click' , '.close_all' , function ( event ) {
jQuery ( this ) . closest ( '.wc-metaboxes-wrapper' ) . find ( '.wc-metabox > table' ) . hide ( ) ;
return false ;
2012-02-13 19:21:52 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2012-02-25 11:43:25 +00:00
jQuery ( '.wc-metabox.closed' ) . each ( function ( ) {
2012-02-25 19:48:09 +00:00
jQuery ( this ) . find ( '.wc-metabox-content' ) . hide ( ) ;
2012-02-13 19:21:52 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2012-02-25 11:43:25 +00:00
// ATTRIBUTE TABLES
2011-09-11 17:35:22 +00:00
// Multiselect attributes
2013-11-01 17:06:14 +00:00
$ ( ".product_attributes select.multiselect" ) . chosen ( ) ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
// Initial order
2013-11-01 17:06:14 +00:00
var woocommerce _attribute _items = $ ( '.product_attributes' ) . find ( '.woocommerce_attribute' ) . get ( ) ;
2012-08-01 12:43:46 +00:00
2012-02-13 19:21:52 +00:00
woocommerce _attribute _items . sort ( function ( a , b ) {
var compA = parseInt ( $ ( a ) . attr ( 'rel' ) ) ;
var compB = parseInt ( $ ( b ) . attr ( 'rel' ) ) ;
2011-08-09 15:16:18 +00:00
return ( compA < compB ) ? - 1 : ( compA > compB ) ? 1 : 0 ;
} )
2013-11-01 17:06:14 +00:00
$ ( woocommerce _attribute _items ) . each ( function ( idx , itm ) { $ ( '.product_attributes' ) . append ( itm ) ; } ) ;
2012-08-01 12:43:46 +00:00
2012-03-13 13:26:20 +00:00
function attribute _row _indexes ( ) {
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes .woocommerce_attribute' ) . each ( function ( index , el ) {
$ ( '.attribute_position' , el ) . val ( parseInt ( $ ( el ) . index ( '.product_attributes .woocommerce_attribute' ) ) ) ;
2012-02-13 19:21:52 +00:00
} ) ;
2011-08-09 15:16:18 +00:00
} ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
// Add rows
2012-02-13 19:21:52 +00:00
$ ( 'button.add_attribute' ) . on ( 'click' , function ( ) {
2012-08-01 12:43:46 +00:00
2013-11-01 17:06:14 +00:00
var size = $ ( '.product_attributes .woocommerce_attribute' ) . size ( ) ;
2012-08-01 12:43:46 +00:00
2011-11-05 19:03:03 +00:00
var attribute _type = $ ( 'select.attribute_taxonomy' ) . val ( ) ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
if ( ! attribute _type ) {
2012-08-01 12:43:46 +00:00
2011-11-05 19:03:03 +00:00
var product _type = $ ( 'select#product-type' ) . val ( ) ;
2011-09-11 13:28:15 +00:00
if ( product _type != 'variable' ) enable _variation = 'style="display:none;"' ; else enable _variation = '' ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
// Add custom attribute row
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . append ( ' < div class = "woocommerce_attribute wc-metabox" > \
2012-02-13 19:21:52 +00:00
< h3 > \
2013-08-06 10:41:20 +00:00
< button type = "button" class = "remove_row button" > ' + woocommerce_admin_meta_boxes.remove_label + ' < / b u t t o n > \
< div class = "handlediv" title = "' + woocommerce_admin_meta_boxes.click_to_toggle + '" > < / d i v > \
2012-02-13 19:21:52 +00:00
< strong class = "attribute_name" > < / s t r o n g > \
< / h 3 > \
< table cellpadding = "0" cellspacing = "0" class = "woocommerce_attribute_data" > \
< tbody > \
< tr > \
< td class = "attribute_name" > \
2013-08-06 10:41:20 +00:00
< label > ' + woocommerce_admin_meta_boxes.name_label + ' : < / l a b e l > \
2012-02-13 19:21:52 +00:00
< input type = "text" class = "attribute_name" name = "attribute_names[' + size + ']" / > \
< input type = "hidden" name = "attribute_is_taxonomy[' + size + ']" value = "0" / > \
< input type = "hidden" name = "attribute_position[' + size + ']" class = "attribute_position" value = "' + size + '" / > \
< / t d > \
< td rowspan = "3" > \
2013-08-06 10:41:20 +00:00
< label > ' + woocommerce_admin_meta_boxes.values_label + ' : < / l a b e l > \
< textarea name = "attribute_values[' + size + ']" cols = "5" rows = "5" placeholder = "' + woocommerce_admin_meta_boxes.text_attribute_tip + '" > < / t e x t a r e a > \
2012-02-13 19:21:52 +00:00
< / t d > \
< / t r > \
< tr > \
< td > \
2013-08-06 10:41:20 +00:00
< label > < input type = "checkbox" class = "checkbox" ' + ( woocommerce_admin_meta_boxes.default_attribute_visibility ? ' checked = "checked" ' : ' ' ) + ' name = "attribute_visibility[' + size + ']" value = "1" / > ' + woocommerce_admin_meta_boxes.visible_label + ' < / l a b e l > \
2012-02-13 19:21:52 +00:00
< / t d > \
< / t r > \
< tr > \
< td > \
< div class = "enable_variation show_if_variable" ' + enable_variation + ' > \
2013-08-06 10:41:20 +00:00
< label > < input type = "checkbox" class = "checkbox" ' + ( woocommerce_admin_meta_boxes.default_attribute_variation ? ' checked = "checked" ' : ' ' ) + ' name = "attribute_variation[' + size + ']" value = "1" / > ' + woocommerce_admin_meta_boxes.used_for_variations_label + ' < / l a b e l > \
2012-02-13 19:21:52 +00:00
< / d i v > \
< / t d > \
< / t r > \
< / t b o d y > \
< / t a b l e > \
< / d i v > ' ) ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
} else {
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
// Reveal taxonomy row
2013-11-01 17:06:14 +00:00
var thisrow = $ ( '.product_attributes .woocommerce_attribute.' + attribute _type ) ;
$ ( '.product_attributes' ) . append ( $ ( thisrow ) ) ;
2012-02-13 19:21:52 +00:00
$ ( thisrow ) . show ( ) . find ( '.woocommerce_attribute_data' ) . show ( ) ;
2012-03-13 13:26:20 +00:00
attribute _row _indexes ( ) ;
2012-08-01 12:43:46 +00:00
2011-08-09 15:16:18 +00:00
}
2012-08-01 12:43:46 +00:00
2012-02-09 18:10:38 +00:00
$ ( 'select.attribute_taxonomy' ) . val ( '' ) ;
2011-08-09 15:16:18 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . on ( 'blur' , 'input.attribute_name' , function ( ) {
2012-02-13 19:21:52 +00:00
$ ( this ) . closest ( '.woocommerce_attribute' ) . find ( 'strong.attribute_name' ) . text ( $ ( this ) . val ( ) ) ;
} ) ;
2012-08-01 12:43:46 +00:00
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . on ( 'click' , 'button.select_all_attributes' , function ( ) {
2012-02-13 19:21:52 +00:00
$ ( this ) . closest ( 'td' ) . find ( 'select option' ) . attr ( "selected" , "selected" ) ;
2013-08-02 15:54:28 +00:00
$ ( this ) . closest ( 'td' ) . find ( 'select' ) . trigger ( "chosen:updated" ) ;
2012-02-13 19:21:52 +00:00
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . on ( 'click' , 'button.select_no_attributes' , function ( ) {
2012-02-13 19:21:52 +00:00
$ ( this ) . closest ( 'td' ) . find ( 'select option' ) . removeAttr ( "selected" ) ;
2013-08-02 15:54:28 +00:00
$ ( this ) . closest ( 'td' ) . find ( 'select' ) . trigger ( "chosen:updated" ) ;
2011-08-09 15:16:18 +00:00
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . on ( 'click' , 'button.remove_row' , function ( ) {
2013-08-06 10:41:20 +00:00
var answer = confirm ( woocommerce _admin _meta _boxes . remove _attribute ) ;
2011-08-09 15:16:18 +00:00
if ( answer ) {
2012-02-13 19:21:52 +00:00
var $parent = $ ( this ) . parent ( ) . parent ( ) ;
2012-08-01 12:43:46 +00:00
2012-02-13 19:21:52 +00:00
if ( $parent . is ( '.taxonomy' ) ) {
$parent . find ( 'select, input[type=text]' ) . val ( '' ) ;
$parent . hide ( ) ;
} else {
$parent . find ( 'select, input[type=text]' ) . val ( '' ) ;
$parent . hide ( ) ;
2012-03-13 13:26:20 +00:00
attribute _row _indexes ( ) ;
2012-02-13 19:21:52 +00:00
}
2011-08-09 15:16:18 +00:00
}
return false ;
} ) ;
2012-08-01 12:43:46 +00:00
2011-09-19 14:57:17 +00:00
// Attribute ordering
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . sortable ( {
2012-02-13 19:21:52 +00:00
items : '.woocommerce_attribute' ,
2011-09-19 14:57:17 +00:00
cursor : 'move' ,
axis : 'y' ,
2012-02-13 19:21:52 +00:00
handle : 'h3' ,
2011-09-19 14:57:17 +00:00
scrollSensitivity : 40 ,
2012-02-13 19:21:52 +00:00
forcePlaceholderSize : true ,
helper : 'clone' ,
opacity : 0.65 ,
2012-02-25 11:43:25 +00:00
placeholder : 'wc-metabox-sortable-placeholder' ,
2011-09-19 14:57:17 +00:00
start : function ( event , ui ) {
ui . item . css ( 'background-color' , '#f6f6f6' ) ;
} ,
stop : function ( event , ui ) {
ui . item . removeAttr ( 'style' ) ;
2012-03-13 13:26:20 +00:00
attribute _row _indexes ( ) ;
2011-09-19 14:57:17 +00:00
}
2011-08-09 15:16:18 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2012-04-08 23:57:38 +00:00
// Add a new attribute (via ajax)
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . on ( 'click' , 'button.add_new_attribute' , function ( ) {
2012-08-01 12:43:46 +00:00
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-08-01 12:43:46 +00:00
2012-04-08 23:57:38 +00:00
var attribute = $ ( this ) . attr ( 'data-attribute' ) ;
var $wrapper = $ ( this ) . closest ( '.woocommerce_attribute_data' ) ;
2013-08-06 10:41:20 +00:00
var new _attribute _name = prompt ( woocommerce _admin _meta _boxes . new _attribute _prompt ) ;
2012-08-01 12:43:46 +00:00
2012-04-08 23:57:38 +00:00
if ( new _attribute _name ) {
2012-08-01 12:43:46 +00:00
2012-04-08 23:57:38 +00:00
var data = {
action : 'woocommerce_add_new_attribute' ,
taxonomy : attribute ,
term : new _attribute _name ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . add _attribute _nonce
2012-04-08 23:57:38 +00:00
} ;
2012-08-01 12:43:46 +00:00
2013-08-06 10:41:20 +00:00
$ . post ( woocommerce _admin _meta _boxes . ajax _url , data , function ( response ) {
2012-08-01 12:43:46 +00:00
2013-01-22 16:31:54 +00:00
if ( response . error ) {
2012-04-08 23:57:38 +00:00
// Error
2013-01-22 16:31:54 +00:00
alert ( response . error ) ;
} else if ( response . slug ) {
2012-04-08 23:57:38 +00:00
// Success
2013-01-22 16:31:54 +00:00
$wrapper . find ( 'select.attribute_values' ) . append ( '<option value="' + response . slug + '" selected="selected">' + response . name + '</option>' ) ;
2013-08-02 15:54:28 +00:00
$wrapper . find ( 'select.attribute_values' ) . trigger ( "chosen:updated" ) ;
2012-04-08 23:57:38 +00:00
}
2012-08-01 12:43:46 +00:00
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . unblock ( ) ;
2012-08-01 12:43:46 +00:00
2012-04-08 23:57:38 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2012-05-26 16:42:26 +00:00
} else {
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . unblock ( ) ;
2012-04-08 23:57:38 +00:00
}
2012-08-01 12:43:46 +00:00
2012-04-08 23:57:38 +00:00
return false ;
2012-08-01 12:43:46 +00:00
2012-04-08 23:57:38 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-26 17:27:55 +00:00
// Save attributes and update variations
$ ( '.save_attributes' ) . on ( 'click' , function ( ) {
2012-11-27 16:22:47 +00:00
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-11-27 16:22:47 +00:00
2012-11-26 17:27:55 +00:00
var data = {
2013-08-06 10:41:20 +00:00
post _id : woocommerce _admin _meta _boxes . post _id ,
2013-11-01 17:06:14 +00:00
data : $ ( '.product_attributes' ) . find ( 'input, select, textarea' ) . serialize ( ) ,
2012-11-26 17:27:55 +00:00
action : 'woocommerce_save_attributes' ,
2013-08-06 10:41:20 +00:00
security : woocommerce _admin _meta _boxes . save _attributes _nonce
2012-11-26 17:27:55 +00:00
} ;
2013-08-06 10:41:20 +00:00
$ . post ( woocommerce _admin _meta _boxes . ajax _url , data , function ( response ) {
2012-11-26 17:27:55 +00:00
var this _page = window . location . toString ( ) ;
2012-11-27 16:22:47 +00:00
2013-08-06 10:41:20 +00:00
this _page = this _page . replace ( 'post-new.php?' , 'post.php?post=' + woocommerce _admin _meta _boxes . post _id + '&action=edit&' ) ;
2012-11-27 16:22:47 +00:00
2012-11-26 17:27:55 +00:00
// Load variations panel
2013-08-06 10:41:20 +00:00
$ ( '#variable_product_options' ) . block ( { message : null , overlayCSS : { background : '#fff url(' + woocommerce _admin _meta _boxes . plugin _url + '/assets/images/ajax-loader.gif) no-repeat center' , opacity : 0.6 } } ) ;
2012-11-26 17:27:55 +00:00
$ ( '#variable_product_options' ) . load ( this _page + ' #variable_product_options_inner' , function ( ) {
$ ( '#variable_product_options' ) . unblock ( ) ;
} ) ;
2013-11-01 17:06:14 +00:00
$ ( '.product_attributes' ) . unblock ( ) ;
2012-11-26 17:27:55 +00:00
} ) ;
2012-11-27 16:22:47 +00:00
2012-11-26 17:27:55 +00:00
} ) ;
2012-08-01 12:43:46 +00:00
2011-11-09 23:06:17 +00:00
// Uploading files
2012-12-18 12:04:33 +00:00
var downloadable _file _frame ;
2013-04-15 13:55:00 +00:00
var file _path _field ;
2012-12-18 12:04:33 +00:00
2012-12-28 13:02:12 +00:00
jQuery ( document ) . on ( 'click' , '.upload_file_button' , function ( event ) {
2012-12-18 12:04:33 +00:00
var $el = $ ( this ) ;
2013-04-15 13:55:00 +00:00
2013-09-20 16:01:09 +00:00
file _path _field = $el . closest ( 'tr' ) . find ( 'td.file_url input' ) ;
2012-12-18 12:04:33 +00:00
event . preventDefault ( ) ;
// If the media frame already exists, reopen it.
if ( downloadable _file _frame ) {
downloadable _file _frame . open ( ) ;
return ;
}
2012-12-18 21:56:01 +00:00
var downloadable _file _states = [
// Main states.
new wp . media . controller . Library ( {
library : wp . media . query ( ) ,
multiple : true ,
title : $el . data ( 'choose' ) ,
priority : 20 ,
filterable : 'uploaded' ,
} )
] ;
2012-12-18 12:04:33 +00:00
// Create the media frame.
downloadable _file _frame = wp . media . frames . downloadable _file = wp . media ( {
// Set the title of the modal.
title : $el . data ( 'choose' ) ,
library : {
type : ''
} ,
button : {
text : $el . data ( 'update' ) ,
} ,
multiple : true ,
2012-12-18 21:56:01 +00:00
states : downloadable _file _states ,
2012-12-18 12:04:33 +00:00
} ) ;
// When an image is selected, run a callback.
downloadable _file _frame . on ( 'select' , function ( ) {
2013-09-20 16:01:09 +00:00
var file _path = '' ;
2012-12-18 12:04:33 +00:00
var selection = downloadable _file _frame . state ( ) . get ( 'selection' ) ;
selection . map ( function ( attachment ) {
attachment = attachment . toJSON ( ) ;
if ( attachment . url )
2013-09-20 16:01:09 +00:00
file _path = attachment . url
2012-12-18 12:04:33 +00:00
} ) ;
2013-09-20 16:01:09 +00:00
file _path _field . val ( file _path ) ;
2012-12-18 12:04:33 +00:00
} ) ;
2012-12-18 21:56:01 +00:00
// Set post to 0 and set our custom type
downloadable _file _frame . on ( 'ready' , function ( ) {
downloadable _file _frame . uploader . options . uploader . params = {
type : 'downloadable_product'
} ;
} ) ;
2012-12-18 12:04:33 +00:00
// Finally, open the modal.
downloadable _file _frame . open ( ) ;
} ) ;
2011-08-09 15:16:18 +00:00
2013-09-26 15:35:37 +00:00
// Download ordering
jQuery ( '.downloadable_files tbody' ) . sortable ( {
items : 'tr' ,
cursor : 'move' ,
axis : 'y' ,
handle : 'td.sort' ,
scrollSensitivity : 40 ,
forcePlaceholderSize : true ,
helper : 'clone' ,
opacity : 0.65 ,
} ) ;
2013-11-28 12:37:44 +00:00
// Product gallery file uploads
var product _gallery _frame ;
var $image _gallery _ids = $ ( '#product_image_gallery' ) ;
var $product _images = $ ( '#product_images_container ul.product_images' ) ;
jQuery ( '.add_product_images' ) . on ( 'click' , 'a' , function ( event ) {
var $el = $ ( this ) ;
var attachment _ids = $image _gallery _ids . val ( ) ;
event . preventDefault ( ) ;
// If the media frame already exists, reopen it.
if ( product _gallery _frame ) {
product _gallery _frame . open ( ) ;
return ;
}
// Create the media frame.
2014-02-13 10:37:02 +00:00
product _gallery _frame = wp . media . frames . product _gallery = wp . media ( {
2013-11-28 12:37:44 +00:00
// Set the title of the modal.
title : $el . data ( 'choose' ) ,
button : {
text : $el . data ( 'update' ) ,
} ,
2014-01-08 00:28:39 +00:00
states : [
new wp . media . controller . Library ( {
title : $el . data ( 'choose' ) ,
2014-02-13 10:37:02 +00:00
filterable : 'all' ,
multiple : true ,
2014-01-08 00:28:39 +00:00
} )
]
2013-11-28 12:37:44 +00:00
} ) ;
// When an image is selected, run a callback.
product _gallery _frame . on ( 'select' , function ( ) {
var selection = product _gallery _frame . state ( ) . get ( 'selection' ) ;
selection . map ( function ( attachment ) {
attachment = attachment . toJSON ( ) ;
if ( attachment . id ) {
attachment _ids = attachment _ids ? attachment _ids + "," + attachment . id : attachment . id ;
$product _images . append ( ' \
< li class = "image" data - attachment _id = "' + attachment.id + '" > \
< img src = "' + attachment.url + '" / > \
< ul class = "actions" > \
< li > < a href = "#" class = "delete" title = "' + $el.data('delete') + '" > ' + $el.data(' text ') + ' < / a > < / l i > \
< / u l > \
< / l i > ' ) ;
}
} ) ;
$image _gallery _ids . val ( attachment _ids ) ;
} ) ;
// Finally, open the modal.
product _gallery _frame . open ( ) ;
} ) ;
// Image ordering
$product _images . sortable ( {
items : 'li.image' ,
cursor : 'move' ,
scrollSensitivity : 40 ,
forcePlaceholderSize : true ,
forceHelperSize : false ,
helper : 'clone' ,
opacity : 0.65 ,
placeholder : 'wc-metabox-sortable-placeholder' ,
start : function ( event , ui ) {
ui . item . css ( 'background-color' , '#f6f6f6' ) ;
} ,
stop : function ( event , ui ) {
ui . item . removeAttr ( 'style' ) ;
} ,
update : function ( event , ui ) {
var attachment _ids = '' ;
$ ( '#product_images_container ul li.image' ) . css ( 'cursor' , 'default' ) . each ( function ( ) {
var attachment _id = jQuery ( this ) . attr ( 'data-attachment_id' ) ;
attachment _ids = attachment _ids + attachment _id + ',' ;
} ) ;
$image _gallery _ids . val ( attachment _ids ) ;
}
} ) ;
// Remove images
$ ( '#product_images_container' ) . on ( 'click' , 'a.delete' , function ( ) {
$ ( this ) . closest ( 'li.image' ) . remove ( ) ;
var attachment _ids = '' ;
$ ( '#product_images_container ul li.image' ) . css ( 'cursor' , 'default' ) . each ( function ( ) {
var attachment _id = jQuery ( this ) . attr ( 'data-attachment_id' ) ;
attachment _ids = attachment _ids + attachment _id + ',' ;
} ) ;
$image _gallery _ids . val ( attachment _ids ) ;
return false ;
} ) ;
2014-01-08 00:28:39 +00:00
} ) ;