diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000000..365480cc328 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,29 @@ + + +## EXPLANATION OF THE ISSUE + +What happens, under which versions, under what conditions, when, and what were you expecting instead. + +## STEPS TO REPRODUCE THE ISSUE + +1. List steps to reproduce your issue so we can replicate. + +## SYSTEM STATUS REPORT + +``` +Grab the system status report from WooCommerce > System Status and paste it here. +``` diff --git a/.scrutinizer.yml b/.scrutinizer.yml index a98f292be23..7f292d863dd 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -4,8 +4,7 @@ filter: - apigen/* - dummy-data/* - i18n/* - - includes/api/v1/* - - includes/api/v2/* + - includes/api/legacy/* - includes/libraries/* - includes/updates/* - includes/gateways/simplify-commerce/includes/* diff --git a/.travis.yml b/.travis.yml index dce0e441f28..dc68322dd1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,23 +2,30 @@ language: php sudo: false +# Test main supported versions of PHP and HHVM against latest WP. 5.2 is min supported version. php: + - 5.2 - 5.3 - 5.4 - 5.5 - 5.6 + - 7.0 + - hhvm env: - WP_VERSION=latest WP_MULTISITE=0 - - WP_VERSION=4.3 WP_MULTISITE=0 - - WP_VERSION=4.2 WP_MULTISITE=0 - - WP_VERSION=4.1 WP_MULTISITE=0 - - WP_VERSION=4.0 WP_MULTISITE=0 +# Additonal tests against stable PHP (min recommended version is 5.6) and past supported versions of WP. matrix: include: - - php: 5.3 + - php: 5.6 env: WP_VERSION=latest WP_MULTISITE=1 + - php: 5.6 + env: WP_VERSION=4.3 WP_MULTISITE=0 + - php: 5.6 + env: WP_VERSION=4.2 WP_MULTISITE=0 + - php: 5.6 + env: WP_VERSION=4.1 WP_MULTISITE=0 before_script: - bash tests/bin/install.sh woocommerce_test root '' localhost $WP_VERSION diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 76e5b403625..7c2250736d1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,180 @@ == Changelog == += 2.5.5 - 11/03/2016 = +* Fix - Before running dbdelta, drop indexes to prevent duplicate key notices. +* Fix - Prevent notice when unsetting terms on product edit screen. +* Tweak - zeroclipboard fallback for firefox on system status report. +* Tweak - Check valid product ID is provided on add_to_cart shortcode. + += 2.5.4 - 10/03/2016 = +* Fix - Fix table creation when using utf8mb4 charset. +* Fix - Have wp_insert_post return WP_Error when creating our coupon, so the is_wp_error check can catch it. +* Fix - Clear sale price on save if sale is no longer valid. +* Fix - Round refund values to ensure refunds can be performed. +* Fix - When getting coupon by code used twice, latest should be queried. +* Fix - CLI improvements for setting up variations and deleting orders. +* Fix - Allow big selects when getting variations to support larger queries. +* Fix - Trigger webhook when user edits addresses on frontend. +* Fix - Hide shipping row when calculator is disabled, and shipping costs are hidden. +* Fix - Unset deleted attributes when updating products. +* Tweak - Update date for paid orders during non-manual updates only. +* Tweak - wc_get_page_permalink - if the page ID is not set, redirect home instead to prevent white screens. +* Tweak - Remove log dir from system status report. +* Tweak - When sorting by date, fallback to ID. +* Tweak - Rename pay link for clarity. +* Tweak - Provide a fallback message if copying to the clipboard fails in system status report. + += 2.5.3 - 01/03/2016 = +* Fix - Correct the 'unavailable template' call for variations so the message is displayed correctly, fixing a JS error. +* Fix - Add 'media-models' dependency to write panel scripts. +* Fix - Fix hide empty check in category walkers. +* Fix - Current class fix on some servers when empty. +* Fix - Multibyte safe trim string function. +* Fix - Prevent a notice by stopping a loop in woocommerce_products_will_display from stomping on other variables. +* Fix - If an attribute meta key is not set, technically its 'any', so should match. Prevents issues when meta data is missing after renaming attributes. +* Fix - Make wc_get_product_variation_attributes ignore non variation attributes. +* Fix - Notice when no order notes exist. +* Fix - Removed extra tab from plain email shipping address. +* Fix - Round shipping after tax calculation instead of before to prevent wrong taxes being calculated. +* Fix - State input box was not reappearing when switching from a hidden input to a text input. +* Fix - Don't duplicate rating and review counts. +* Fix - CLI - Allow setting of a single category. +* Fix - API - Replace term_taxonomy_id for term_id whilst creating/editing terms. +* Fix - API - Fix parent_id and menu_order for variations. +* Fix - Combine update post calls when update_status is ran. +* Fix - Total number of comments in the admin panel. +* Tweak - Show customer details for logged in users only on thanks page to prevent customer details being revealed if someone finds out the URL. +* Tweak - Wrap status report in backticks to stop people breaking .org forums. +* Tweak - Error handling for screen ids. +* Tweak - Use $wpdb->replace instead of doing a select and then deciding to do an update or insert in session handler. +* Tweak - Added check for private WooCommerce pages in status report. +* Tweak - Transactional emails for failed -> on hold. +* Dev - Include new triggers when removing and adding the password strength meter. +* Dev - Allow pass objects and arrays as webhook callbacks. + += 2.5.2 - 01/02/2016 = +* Fix - Compatibility with w3 total cache inline minification. +* Fix - Remove stock bw compat code which was preventing manage stock being disabled at variation level. +* Fix - When calculating shipping total, force rounding. +* Fix - Make save button clickable in tax rate table after using autocomplete field. +* Fix - Fix passed image_size variable in email templates. +* Fix - Don't show purchase note to admin in emails. +* Fix - Fix 'hide empty' setting in category widget
. +* Fix - Prevent notice in get_allowed_countries. +* Fix - Prevent add-to-cart querystring in pagination links. +* Tweak - Allow propagation in variation script. +* Tweak - Product image alt text. +* Tweak - Remove notice and add styling for add payment page. +* Tweak - Set input margin and label display for compatibility with themes using bootstrap CSS. +* Tweak - Add context to category term localization. +* Tweak - Moved cart URL functions to core-functions file to make them available in admin area. +* Tweak - Added password hint text and error messages when showing the password strength meter in forms. +* Tweak - Added Saudi Riyal currency. +* Tweak - Added Russian Ruble symbol. +* Tweak - When COOKIEPATH is an empty string, set to '/' so cookies work across all pages. +* Dev - Template - Pass $category into wc_product_cat_class() in content-product_cat.php + += 2.5.1 - 25/01/2016 = +* Fix - Remove usage of get_currentuserinfo() which is deprecated in WordPress 4.5. +* Fix - Fix responsive product sizes when the columns class is missing. +* Fix - Fix function exists check for woocommerce_template_loop_category_title. +* Fix - check_version on all requests so that the installer runs after remote plugin updates. +* Fix - Only show the "add payment method" button when needed, and check for required fields on the add payment method page. +* Fix - Correctly block UI to prevent attribute issues in backend when adding multiple attributes in quick succession. +* Fix - Show SKU in admin emails. +* Fix - Don't show downloads in admin emails. +* Fix - Fix query/missing variable in validate_user_usage_limit function. +* Fix - Prevent endless loading on checkout when reload_checkout session variable was used. +* Fix - Correctly display html entities in tax screen autocomplete. +* Fix - Do sales reports based on refund line items rather than fully refunded orders to prevent double refunds being reported. +* Fix - Qty button can be hidden for variable products sold individually. +* Fix - Show the taxable country rather than base country in "estimated for" text during checkout. +* Fix - Prevent select2 gaining focus on IOS7 scroll. +* Fix - API - Fix indexes on decimal and thousand values. +* Tweak - Clear cron jobs on uninstall
. +* Tweak - Don't disable place order button on checkout if a weak password is used. +* Tweak - Added password strength meter in lost password and edit accout pages. +* Tweak - Pass $args to woocommerce_dropdown_variation_attribute_options_html hook. + += 2.5.0 - 18/01/2016 = +* Feature - New default session handler. Uses custom table to store data rather than the options table for performance and scalability reasons. https://woocommerce.wordpress.com/2015/10/07/new-session-handler-in-2-5/ +* Feature - New tax settings UI - faster, enhanced with ajax, searchable. +* Feature - WP CLI Support. https://woocommerce.wordpress.com/2015/10/01/sneak-peek-wp-cli-support-in-woocommerce/ +* Feature - Added terms and conditions checkbox to pay page. +* Feature - Password strength indicators. +* Feature - Added 'pay' link to order screen. +* Feature - Added admin order/payment failed notification. +* Fix - Check for existence of global attribute when you get_attributes() for a product. +* Fix - Show order by template on product search. +* Fix - Search variation skus in backend search. +* Tweak - For coupons with category restrictions, respect the category hierarchy. +* Tweak - Added wc_array_cartesian function to generate variations in a logical order. +* Tweak - Revised email settings screens to show emails in a table and avoid a long sub-nav. +* Tweak - Default customer role capabilities. +* Tweak - Expire mini-cart cache after 24 hours. +* Tweak - Improved refund error messages in PayPal standard. +* Tweak - Removed language pack downloader in favour of translate.wordpress.org. +* Tweak - Added onboarding wizard button to the contextual help so it can be accessed again. +* Tweak - When a WordPress user is deleted, turn any orders they have into Guest orders. +* Tweak - When calculating order taxes, respect tax settings and default to base country. +* Tweak - Fade in variation images to avoid flicker during load. +* Tweak - Display 2 averages on report (net and gross). +* Tweak - Improve product search and use WPDB instead of several get_posts queries for performance. +* Tweak - Use SKU for stock order notes. +* Tweak - Added order notes for manual email sends. +* Tweak - Sanitize shipping method labels/titles. +* Tweak - Only display the coupon form on the checkout if a coupon hasn't been applied. +* Tweak - Added billing address column to order screen (off for new users). +* Tweak - Created function to disable author archives for customers. +* Tweak - When updating cart hash, refresh all open tabs. +* Tweak - Use new "question" mark icon font for help tips. +* Tweak - Improved review verification status retrieval. +* Tweak - Improve appearance when only 1 gateway is active. +* Tweak - Aligned terms box left and added required asterisk. +* Tweak - Removed dropdown display mode for cart shipping methods - radios are more flexible. +* Dev - API - Added /products/shipping_classes endpoint. +* Dev - API - Added support to POST, PUT, and DELETE categories and tags. +* Dev - API - Added support to filter products by tag, category, shipping class, and attribute. +* Dev - API - Added tax and tax_class endpoints. +* Dev - Template - New star ratings. The old one was 5 separate buttons. This new one consolidates the 5 options into one element making it leaner visually and more intuitive. Works in IE9+ with a graceful degradation for IE8. +* Dev - Template - Added `data-title` attribute to cart table. +* Dev - Template - Product archive anchors are now hooked into templates rather than hard coded. +* Dev - Template - Added template files for the customer details list in emails. emails/email-customer-details.php +* Dev - Template - Revised single variation cart template. Template files now exist for variations, and the cart button will display (disabled) when no selections are made. +* Dev - Template - Made "my orders" columns fully customizable with filters. +* Dev - Template - Unified email template order details tables to use a single template. +* Dev - Allow wc_clean to support arrays. +* Dev - Added a manual update trigger for checkout. +* Dev - Added woocommerce_is_price_filter_active filter to Query class. +* Dev - Replaced some cart methods with dedicated functions. e.g. wc_ship_to_billing_address_only(). +* Localisation - Add Kenyan currency and symbol. + += 2.4.13 - 11/01/2016 = +* Fix - Potential redirect loop when using 'unforce ssl' setting and a https home URL. +* Fix - Escape option names when cleaning up sessions. + += 2.4.12 - 9/12/2015 = +* Fix - 4.4 - Permission error when editing attribute terms. +* Fix - 4.4 - Missing variation images when wp_get_attachment_image_srcset() returns false instead of a string. +* Fix - 4.4 - Use post-thumbnail size in admin to avoid srcset. +* Fix - Webhook status not changed after save with active object-cache. + += 2.4.11 - 7/12/2015 = +* Fix - WordPress 4.4 support. +* Fix - Removes Switzerland from EU VAT definition
. +* Fix - Fix auth endpoint urls. +* Fix - To allow backslash in SKUs. +* Fix - Sanity check for min/max quantity
. +* Fix - 4.4 - Shipping class menu display. +* Fix - 4.4 - Admin menu icons and styling. +* Fix - API - Variable product backorders editing. +* Fix - API - Delete product transients when delete a variable product. +* Fix - API - Returned status when have an invalid oAuth timestamp. +* Fix - API - Early call of order status when editing orders. +* Tweak - 4.4 - Basic support for product embeds. +* Tweak - 4.4 - Support for srcset/sizes and responsive images. +* Tweak - 4.4 - Support for Twenty Sixteen. + = 2.4.10 - 10/11/2015 = * Fix - Geo IP - Correctly parse .dat files. * Fix - Geo IP - Ensure WC_Logger class exists before logging errors. diff --git a/Gruntfile.js b/Gruntfile.js index 9b68e9972f7..a5cb7009852 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -31,7 +31,8 @@ module.exports = function( grunt ) { // Minify .js files. uglify: { options: { - preserveComments: 'some' + // Preserve comments that start with a bang. + preserveComments: /^!/ }, admin: { files: [{ @@ -235,6 +236,12 @@ module.exports = function( grunt ) { 'css' ]); + grunt.registerTask( 'js', [ + 'jshint', + 'uglify:admin', + 'uglify:frontend' + ]); + grunt.registerTask( 'css', [ 'sass', 'cssmin' diff --git a/README.md b/README.md index fda8ca58c57..e9be6979f1b 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,20 @@ Welcome to the WooCommerce repository on GitHub. Here you can browse the source, If you are not a developer, please use the [WooCommerce plugin page](http://wordpress.org/plugins/woocommerce/) on WordPress.org. ## Documentation -* The [WooCommerce docs site](http://docs.woothemes.com/documentation/plugins/woocommerce/) -* [WooCommerce API Docs](http://docs.woothemes.com/wc-apidocs/) +* [WooCommerce Documentation](http://docs.woothemes.com/documentation/plugins/woocommerce/) +* [WooCommerce Knowledge Base](https://support.woothemes.com/hc/en-us/categories/200146917-WooCommerce) +* [WooCommerce Code Reference](http://docs.woothemes.com/wc-apidocs/) * [WooCommerce REST API Docs](http://woothemes.github.io/woocommerce-rest-api-docs/) ## Support This repository is not suitable for support. Please don't use our issue tracker for support requests, but for core WooCommerce issues only. Support can take place in the appropriate channels: * The [WooThemes premium support portal](http://support.woothemes.com/) for customers who have purchased themes or extensions. -* [Our public HelpDesk](https://support.woothemes.com/hc/communities/public/topics) which is available for all WooCommerce users. +* [Our community forum on wp.org](https://wordpress.org/support/plugin/woocommerce) which is available for all WooCommerce users. Support requests in issues on this repository will be closed on sight. ## Contributing to WooCommerce -If you have a patch, or stumbled upon an issue with WooCommerce core, you can contribute this back to the code. Please read our [contributor guidelines](https://github.com/woothemes/woocommerce/blob/master/CONTRIBUTING.md) for more information how you can do this. +If you have a patch, or stumbled upon an issue with WooCommerce core, you can contribute this back to the code. Please read our [contributor guidelines](https://github.com/woothemes/woocommerce/blob/master/.github/CONTRIBUTING.md) for more information how you can do this. If you have an idea for WooCommerce, see the [Roadmap Trello board](https://trello.com/b/YgRbpuze/woocommerce-roadmap). diff --git a/apigen.neon b/apigen.neon index aec9743d1bc..a1c00dd174f 100644 --- a/apigen.neon +++ b/apigen.neon @@ -29,7 +29,7 @@ main: WC title: WooCommerce 2.5.x Code Reference # base url used for sitemap (useful for public doc) -baseUrl: http://docs.woothemes.com/wc-apidocs/ +baseUrl: https://docs.woothemes.com/wc-apidocs/ # choose ApiGen template theme templateTheme: default diff --git a/apigen/hook-docs.php b/apigen/hook-docs.php index 5da84ac48e1..70808ca9771 100644 --- a/apigen/hook-docs.php +++ b/apigen/hook-docs.php @@ -122,6 +122,45 @@ class WC_HookFinder { case 'filter' : case 'action' : $hook = trim( $token[1], "'" ); + $loop = 0; + + if ( '_' === substr( $hook, '-1', 1 ) ) { + $hook .= '{'; + $open = true; + // Keep adding to hook until we find a comma or colon + while ( 1 ) { + $loop ++; + $next_hook = trim( trim( is_string( $tokens[ $index + $loop ] ) ? $tokens[ $index + $loop ] : $tokens[ $index + $loop ][1], '"' ), "'" ); + + if ( in_array( $next_hook, array( '.', '{', '}', '"', "'", ' ' ) ) ) { + continue; + } + + $hook_first = substr( $next_hook, 0, 1 ); + $hook_last = substr( $next_hook, -1, 1 ); + + if ( in_array( $next_hook, array( ',', ';' ) ) ) { + if ( $open ) { + $hook .= '}'; + $open = false; + } + break; + } + + if ( '_' === $hook_first ) { + $next_hook = '}' . $next_hook; + $open = false; + } + + if ( '_' === $hook_last ) { + $next_hook .= '{'; + $open = true; + } + + $hook .= $next_hook; + } + } + if ( isset( self::$custom_hooks_found[ $hook ] ) ) { self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file; } else { @@ -169,13 +208,13 @@ class WC_HookFinder { echo '");c.unblock()}})}});new b}(jQuery); \ No newline at end of file +!function(a){var b=Backbone.View.extend({el:a("#key-fields"),events:{"click input#update_api_key":"saveKey"},initialize:function(){_.bindAll(this,"saveKey")},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},initTipTip:function(b){a(document.body).on("aftercopy",b,function(c){!0===c.success["text/plain"]?(a("#copy-error").text(""),a(b).tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()):(a(b).parent().find("input").focus().select(),a("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed))}).on("click",b,function(){document.queryCommandSupported("copy")||(a(b).parent().find("input").focus().select(),a("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed))}).on("copy",b,function(b){a("#copy-error").text(""),b.clipboardData.clearData(),b.clipboardData.setData("text/plain",a.trim(a(this).prev("input").val())),b.preventDefault()})},createQRCode:function(b,c){a("#keys-qrcode").qrcode({text:b+"|"+c,width:120,height:120})},saveKey:function(b){b.preventDefault();var c=this;c.block(),Backbone.ajax({method:"POST",dataType:"json",url:woocommerce_admin_api_keys.ajax_url,data:{action:"woocommerce_update_api_key",security:woocommerce_admin_api_keys.update_api_nonce,key_id:a("#key_id",c.el).val(),description:a("#key_description",c.el).val(),user:a("#key_user",c.el).val(),permissions:a("#key_permissions",c.el).val()},success:function(b){if(a(".wc-api-message",c.el).remove(),b.success){var d=b.data;if(a("h3",c.el).first().append('

'+d.message+"

"),0

'+b.data.message+"

");c.unblock()}})}});new b}(jQuery); \ No newline at end of file diff --git a/assets/js/admin/order-backbone-modal.js b/assets/js/admin/backbone-modal.js similarity index 81% rename from assets/js/admin/order-backbone-modal.js rename to assets/js/admin/backbone-modal.js index b8d8eb62260..013a40cb787 100644 --- a/assets/js/admin/order-backbone-modal.js +++ b/assets/js/admin/backbone-modal.js @@ -53,15 +53,28 @@ _string: undefined, events: { 'click .modal-close': 'closeButton', - 'click #btn-ok': 'addButton', + 'click #btn-ok' : 'addButton', 'touchstart #btn-ok': 'addButton', - 'keydown': 'keyboardActions' + 'keydown' : 'keyboardActions' + }, + resizeContent: function() { + var $content = $( '.wc-backbone-modal-content' ).find( 'article' ); + var max_h = $( window ).height() * 0.75; + + $content.css({ + 'max-height': max_h + 'px' + }); }, initialize: function( data ) { + var view = this; this._target = data.target; this._string = data.string; _.bindAll( this, 'render' ); this.render(); + + $( window ).resize(function() { + view.resizeContent(); + }); }, render: function() { var template = wp.template( this._target ); @@ -74,30 +87,7 @@ 'overflow': 'hidden' }).append( this.$el ); - var $content = $( '.wc-backbone-modal-content' ).find( 'article' ); - var content_h = ( $content.height() < 90 ) ? 90 : $content.height(); - var max_h = $( window ).height() - 200; - - if ( max_h > 400 ) { - max_h = 400; - } - - if ( content_h > max_h ) { - $content.css({ - 'overflow': 'auto', - height: max_h + 'px' - }); - } else { - $content.css({ - 'overflow': 'visible', - height: ( content_h > 90 ) ? 'auto' : content_h + 'px' - }); - } - - $( '.wc-backbone-modal-content' ).css({ - 'margin-top': '-' + ( $( '.wc-backbone-modal-content' ).height() / 2 ) + 'px', - 'margin-left': '-' + ( $( '.wc-backbone-modal-content' ).width() / 2 ) + 'px' - }); + this.resizeContent(); $( document.body ).trigger( 'wc_backbone_modal_loaded', this._target ); }, diff --git a/assets/js/admin/backbone-modal.min.js b/assets/js/admin/backbone-modal.min.js new file mode 100644 index 00000000000..d8892cb55d9 --- /dev/null +++ b/assets/js/admin/backbone-modal.min.js @@ -0,0 +1 @@ +!function(a,b,c){"use strict";a.fn.WCBackboneModal=function(b){return this.each(function(){new a.WCBackboneModal(a(this),b)})},a.WCBackboneModal=function(b,c){var d=a.extend({},a.WCBackboneModal.defaultOptions,c);d.template&&new a.WCBackboneModal.View({target:d.template,string:d.variable})},a.WCBackboneModal.defaultOptions={template:"",variable:{}},a.WCBackboneModal.View=b.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:void 0,_string:void 0,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions"},resizeContent:function(){var b=a(".wc-backbone-modal-content").find("article"),c=.75*a(window).height();b.css({"max-height":c+"px"})},initialize:function(b){var d=this;this._target=b.target,this._string=b.string,c.bindAll(this,"render"),this.render(),a(window).resize(function(){d.resizeContent()})},render:function(){var b=wp.template(this._target);this.$el.attr("tabindex","0").append(b(this._string)),a(document.body).css({overflow:"hidden"}).append(this.$el),this.resizeContent(),a(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(b){b.preventDefault(),a(document.body).trigger("wc_backbone_modal_before_remove",this._target),this.undelegateEvents(),a(document).off("focusin"),a(document.body).css({overflow:"auto"}),this.remove(),a(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(b){a(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(b)},getFormData:function(){var b={};return a(document.body).trigger("wc_backbone_modal_before_update",this._target),a.each(a("form",this.$el).serializeArray(),function(c,d){b.hasOwnProperty(d.name)?(b[d.name]=a.makeArray(b[d.name]),b[d.name].push(d.value)):b[d.name]=d.value}),b},keyboardActions:function(a){var b=a.keyCode||a.which;13!==b||a.target.tagName&&("input"===a.target.tagName.toLowerCase()||"textarea"===a.target.tagName.toLowerCase())||this.addButton(a),27===b&&this.closeButton(a)}})}(jQuery,Backbone,_); \ No newline at end of file diff --git a/assets/js/admin/meta-boxes-order.js b/assets/js/admin/meta-boxes-order.js index f250f1b53c9..1cb9cd116db 100644 --- a/assets/js/admin/meta-boxes-order.js +++ b/assets/js/admin/meta-boxes-order.js @@ -226,14 +226,17 @@ jQuery( function ( $ ) { .on( 'click', 'button.add-order-fee', this.add_fee ) .on( 'click', 'button.add-order-shipping', this.add_shipping ) .on( 'click', 'button.add-order-tax', this.add_tax ) - .on( 'click', 'input.check-column', this.bulk_actions.check_column ) - .on( 'click', '.do_bulk_action', this.bulk_actions.do_bulk_action ) .on( 'click', 'button.calculate-action', this.calculate_totals ) .on( 'click', 'button.save-action', this.save_line_items ) .on( 'click', 'a.delete-order-tax', this.delete_tax ) .on( 'click', 'button.calculate-tax-action', this.calculate_tax ) .on( 'click', 'a.edit-order-item', this.edit_item ) .on( 'click', 'a.delete-order-item', this.delete_item ) + .on( 'click', 'tr.item, tr.fee, tr.shipping, tr.refund', this.select_row ) + .on( 'click', 'tr.item :input, tr.fee :input, tr.shipping :input, tr.refund :input, tr.item a, tr.fee a, tr.shipping a, tr.refund a', this.select_row_child ) + .on( 'click', 'button.bulk-delete-items', this.bulk_actions.do_delete ) + .on( 'click', 'button.bulk-increase-stock', this.bulk_actions.do_increase_stock ) + .on( 'click', 'button.bulk-decrease-stock', this.bulk_actions.do_reduce_stock ) // Refunds .on( 'click', '.delete_refund', this.refunds.delete_refund ) @@ -246,14 +249,14 @@ jQuery( function ( $ ) { .on( 'change', 'input.quantity', this.quantity_changed ) // Subtotal/total - .on( 'keyup', '.woocommerce_order_items .split-input input:eq(0)', function() { - var $subtotal = $( this ).next(); - if ( $subtotal.val() === '' || $subtotal.is( '.match-total' ) ) { + .on( 'keyup change', '.split-input :input', function() { + var $subtotal = $( this ).parent().prev().find(':input'); + if ( $subtotal && ( $subtotal.val() === '' || $subtotal.is( '.match-total' ) ) ) { $subtotal.val( $( this ).val() ).addClass( 'match-total' ); } }) - .on( 'keyup', '.woocommerce_order_items .split-input input:eq(1)', function() { + .on( 'keyup', '.split-input :input', function() { $( this ).removeClass( 'match-total' ); }) @@ -327,21 +330,23 @@ jQuery( function ( $ ) { ); // Taxes - $( 'td.line_tax', $row ).each(function() { - var line_total_tax = $( 'input.line_tax', $( this ) ); - var unit_total_tax = accounting.unformat( line_total_tax.attr( 'data-total_tax' ), woocommerce_admin.mon_decimal_point ) / o_qty; + $( 'input.line_tax', $row ).each( function() { + var $line_total_tax = $( this ); + var tax_id = $line_total_tax.data( 'tax_id' ); + var unit_total_tax = accounting.unformat( $line_total_tax.attr( 'data-total_tax' ), woocommerce_admin.mon_decimal_point ) / o_qty; + var $line_subtotal_tax = $( 'input.line_subtotal_tax[data-tax_id="' + tax_id + '"]', $row ); + var unit_subtotal_tax = accounting.unformat( $line_subtotal_tax.attr( 'data-subtotal_tax' ), woocommerce_admin.mon_decimal_point ) / o_qty; + if ( 0 < unit_total_tax ) { - line_total_tax.val( + $line_total_tax.val( parseFloat( accounting.formatNumber( unit_total_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) ) .toString() .replace( '.', woocommerce_admin.mon_decimal_point ) ); } - var line_subtotal_tax = $( 'input.line_subtotal_tax', $( this ) ); - var unit_subtotal_tax = accounting.unformat( line_subtotal_tax.attr( 'data-subtotal_tax' ), woocommerce_admin.mon_decimal_point ) / o_qty; if ( 0 < unit_subtotal_tax ) { - line_subtotal_tax.val( + $line_subtotal_tax.val( parseFloat( accounting.formatNumber( unit_subtotal_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) ) .toString() .replace( '.', woocommerce_admin.mon_decimal_point ) @@ -354,13 +359,13 @@ jQuery( function ( $ ) { add_line_item: function() { $( 'div.wc-order-add-item' ).slideDown(); - $( 'div.wc-order-bulk-actions' ).slideUp(); + $( 'div.wc-order-data-row-toggle' ).not( 'div.wc-order-add-item' ).slideUp(); return false; }, refund_items: function() { $( 'div.wc-order-refund-items' ).slideDown(); - $( 'div.wc-order-bulk-actions' ).slideUp(); + $( 'div.wc-order-data-row-toggle' ).not( 'div.wc-order-refund-items' ).slideUp(); $( 'div.wc-order-totals-items' ).slideUp(); $( '#woocommerce-order-items' ).find( 'div.refund' ).show(); $( '.wc-order-edit-line-item .wc-order-edit-line-item-actions' ).hide(); @@ -368,7 +373,7 @@ jQuery( function ( $ ) { }, cancel: function() { - $( this ).closest( 'div.wc-order-data-row' ).slideUp(); + $( 'div.wc-order-data-row-toggle' ).not( 'div.wc-order-bulk-actions' ).slideUp(); $( 'div.wc-order-bulk-actions' ).slideDown(); $( 'div.wc-order-totals-items' ).slideDown(); $( '#woocommerce-order-items' ).find( 'div.refund' ).hide(); @@ -666,7 +671,7 @@ jQuery( function ( $ ) { line_item_totals: JSON.stringify( line_item_totals, null, '' ), line_item_tax_totals: JSON.stringify( line_item_tax_totals, null, '' ), api_refund: $( this ).is( '.do-api-refund' ), - restock_refunded_items: $( '#restock_refunded_items:checked' ).size() ? 'true' : 'false', + restock_refunded_items: $( '#restock_refunded_items:checked' ).length ? 'true' : 'false', security: woocommerce_admin_meta_boxes.order_item_nonce }; @@ -766,19 +771,20 @@ jQuery( function ( $ ) { ).change(); // Taxes - $( 'td.line_tax', $row ).each( function() { - var line_total_tax = $( 'input.line_tax', $( this ) ); - var refund_line_total_tax = $( 'input.refund_line_tax', $( this ) ); - var unit_total_tax = accounting.unformat( line_total_tax.attr( 'data-total_tax' ), woocommerce_admin.mon_decimal_point ) / qty; + $( '.refund_line_tax', $row ).each( function() { + var $refund_line_total_tax = $( this ); + var tax_id = $refund_line_total_tax.data( 'tax_id' ); + var line_total_tax = $( 'input.line_tax[data-tax_id="' + tax_id + '"]', $row ); + var unit_total_tax = accounting.unformat( line_total_tax.data( 'total_tax' ), woocommerce_admin.mon_decimal_point ) / qty; if ( 0 < unit_total_tax ) { - refund_line_total_tax.val( + $refund_line_total_tax.val( parseFloat( accounting.formatNumber( unit_total_tax * refund_qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) ) .toString() .replace( '.', woocommerce_admin.mon_decimal_point ) ).change(); } else { - refund_line_total_tax.val( 0 ).change(); + $refund_line_total_tax.val( 0 ).change(); } }); @@ -802,7 +808,7 @@ jQuery( function ( $ ) { add: function() { var $button = $( this ); - var $item = $button.closest( 'tr.item' ); + var $item = $button.closest( 'tr.item, tr.shipping' ); var data = { order_item_id: $item.attr( 'data-order_item_id' ), @@ -842,7 +848,7 @@ jQuery( function ( $ ) { data: data, type: 'POST', success: function() { - $row.hide(); + $row.remove(); wc_meta_boxes_order_items.unblock(); } }); @@ -851,77 +857,124 @@ jQuery( function ( $ ) { } }, - bulk_actions: { + select_row: function() { + var $row = false; + if ( $( this ).is( 'tr' ) ) { + $row = $( this ); + } else { + $row = $( this ).closest( 'tr' ); + } + var $table = $( this ).closest( 'table' ); - 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' ); - } - }, + if ( $row.is( '.selected' ) ) { + $row.removeClass( 'selected' ); + } else { + $row.addClass( 'selected' ); + } - do_bulk_action: function() { - var action = $( this ).closest( '.bulk-actions' ).find( 'select' ).val(); - var selected_rows = $( '#woocommerce-order-items' ).find( '.check-column input:checked' ); - var item_ids = []; + var $rows = $table.find( 'tr.selected' ); - $( selected_rows ).each( function() { - var $item = $( this ).closest( 'tr' ); + if ( $rows.length ) { + $( 'div.wc-order-item-bulk-edit' ).slideDown(); - if ( $item.attr( 'data-order_item_id' ) ) { - item_ids.push( $item.attr( 'data-order_item_id' ) ); + var selected_product = false; + + $rows.each( function() { + if ( $( this ).is( 'tr.item' ) ) { + selected_product = true; } } ); - if ( item_ids.length === 0 ) { - window.alert( woocommerce_admin_meta_boxes.i18n_select_items ); - return; + if ( selected_product ) { + $( '.bulk-increase-stock, .bulk-decrease-stock' ).show(); + } else { + $( '.bulk-increase-stock, .bulk-decrease-stock' ).hide(); } + } else { + $( 'div.wc-order-item-bulk-edit' ).slideUp(); + } + }, - if ( wc_meta_boxes_order_items.bulk_actions[ 'do_' + action ] ) { - wc_meta_boxes_order_items.bulk_actions[ 'do_' + action ]( selected_rows, item_ids ); - } + select_row_child: function( e ) { + e.stopPropagation(); + }, - return false; - }, + bulk_actions: { - do_delete: function( selected_rows, item_ids ) { - if ( window.confirm( woocommerce_admin_meta_boxes.remove_item_notice ) ) { + do_delete: function( e ) { + e.preventDefault(); + var $table = $( 'table.woocommerce_order_items' ); + var $rows = $table.find( 'tr.selected' ); + + if ( $rows.length && window.confirm( woocommerce_admin_meta_boxes.remove_item_notice ) ) { wc_meta_boxes_order_items.block(); - var data = { - order_item_ids: item_ids, - action: 'woocommerce_remove_order_item', - security: woocommerce_admin_meta_boxes.order_item_nonce - }; + var delete_items = []; + var delete_refunds = []; + var deferred = []; - $.ajax({ - url: woocommerce_admin_meta_boxes.ajax_url, - data: data, - type: 'POST', - success: function() { - $( selected_rows ).each(function() { - $( this ).closest( 'tr' ).remove(); - }); - wc_meta_boxes_order_items.unblock(); + $.map( $rows, function( row ) { + var $row = $( row ); + + if ( $row.is( '.refund' ) ) { + delete_refunds.push( parseInt( $( $row ).data( 'order_refund_id' ), 10 ) ); + } else { + delete_items.push( parseInt( $( $row ).data( 'order_item_id' ), 10 ) ); } + return ; }); + + if ( delete_items.length ) { + deferred.push( $.ajax({ + url : woocommerce_admin_meta_boxes.ajax_url, + data: { + order_item_ids: delete_items, + action: 'woocommerce_remove_order_item', + security: woocommerce_admin_meta_boxes.order_item_nonce + }, + type: 'POST' + } ) ); + } + + if ( delete_refunds.length ) { + deferred.push( $.ajax( { + url : woocommerce_admin_meta_boxes.ajax_url, + data: { + action: 'woocommerce_delete_refund', + refund_id: delete_refunds, + security: woocommerce_admin_meta_boxes.order_item_nonce + }, + type: 'POST' + } ) ); + } + + if ( deferred ) { + $.when.apply( $, deferred ).done( function() { + wc_meta_boxes_order_items.reload_items(); + wc_meta_boxes_order_items.unblock(); + } ); + } else { + wc_meta_boxes_order_items.unblock(); + } } }, - do_increase_stock: function( selected_rows, item_ids ) { + do_increase_stock: function( e ) { + e.preventDefault(); wc_meta_boxes_order_items.block(); + var $table = $( 'table.woocommerce_order_items' ); + var $rows = $table.find( 'tr.selected' ); var quantities = {}; + var item_ids = $.map( $rows, function( $row ) { + return parseInt( $( $row ).data( 'order_item_id' ), 10 ); + }); - $( selected_rows ).each(function() { - - var $item = $( this ).closest( 'tr.item, tr.fee' ); - var $qty = $item.find( 'input.quantity' ); - - quantities[ $item.attr( 'data-order_item_id' ) ] = $qty.val(); + $rows.each(function() { + if ( $( this ).find( 'input.quantity' ).length ) { + quantities[ $( this ).attr( 'data-order_item_id' ) ] = $( this ).find( 'input.quantity' ).val(); + } }); var data = { @@ -943,17 +996,21 @@ jQuery( function ( $ ) { }); }, - do_reduce_stock: function( selected_rows, item_ids ) { + do_reduce_stock: function( e ) { + e.preventDefault(); wc_meta_boxes_order_items.block(); + var $table = $( 'table.woocommerce_order_items' ); + var $rows = $table.find( 'tr.selected' ); var quantities = {}; + var item_ids = $.map( $rows, function( $row ) { + return parseInt( $( $row ).data( 'order_item_id' ), 10 ); + }); - $( selected_rows ).each(function() { - - var $item = $( this ).closest( 'tr.item, tr.fee' ); - var $qty = $item.find( 'input.quantity' ); - - quantities[ $item.attr( 'data-order_item_id' ) ] = $qty.val(); + $rows.each(function() { + if ( $( this ).find( 'input.quantity' ).length ) { + quantities[ $( this ).attr( 'data-order_item_id' ) ] = $( this ).find( 'input.quantity' ).val(); + } }); var data = { @@ -1076,18 +1133,14 @@ jQuery( function ( $ ) { stupidtable: { init: function() { - $( '.woocommerce_order_items' ).stupidtable().on( 'aftertablesort', this.add_arrows ); + $( '.woocommerce_order_items' ).stupidtable(); + $( '.woocommerce_order_items' ).on( 'aftertablesort', this.add_arrows ); }, add_arrows: function( event, data ) { var th = $( this ).find( 'th' ); var arrow = data.direction === 'asc' ? '↑' : '↓'; var index = data.column; - - if ( 1 < index ) { - index = index - 1; - } - th.find( '.wc-arrow' ).remove(); th.eq( index ).append( '' + arrow + '' ); } @@ -1188,7 +1241,7 @@ jQuery( function ( $ ) { var data = { action: 'woocommerce_grant_access_to_download', product_ids: products, - loop: $('.order_download_permissions .wc-metabox').size(), + loop: $('.order_download_permissions .wc-metabox').length, order_id: woocommerce_admin_meta_boxes.post_id, security: woocommerce_admin_meta_boxes.grant_access_nonce }; diff --git a/assets/js/admin/meta-boxes-order.min.js b/assets/js/admin/meta-boxes-order.min.js index 9e5ffc6dca9..92a6845e739 100644 --- a/assets/js/admin/meta-boxes-order.min.js +++ b/assets/js/admin/meta-boxes-order.min.js @@ -1 +1 @@ -jQuery(function(a){var b={states:null,init:function(){"undefined"!=typeof woocommerce_admin_meta_boxes_order&&"undefined"!=typeof woocommerce_admin_meta_boxes_order.countries&&(this.states=a.parseJSON(woocommerce_admin_meta_boxes_order.countries.replace(/"/g,'"'))),a(".js_field-country").select2().change(this.change_country),a(".js_field-country").trigger("change",[!0]),a(document.body).on("change","select.js_field-state",this.change_state),a("#woocommerce-order-actions input, #woocommerce-order-actions a").click(function(){window.onbeforeunload=""}),a("a.edit_address").click(this.edit_address),a("a.billing-same-as-shipping").on("click",this.copy_billing_to_shipping),a("a.load_customer_billing").on("click",this.load_billing),a("a.load_customer_shipping").on("click",this.load_shipping),a("#customer_user").on("change",this.change_customer_user)},change_country:function(c,d){if("undefined"==typeof d&&(d=!1),null!==b.states){var e=a(this),f=e.val(),g=e.parents("div.edit_address").find(":input.js_field-state"),h=g.parent(),i=g.attr("name"),j=g.attr("id"),k=e.data("woocommerce.stickState-"+f)?e.data("woocommerce.stickState-"+f):g.val(),l=g.attr("placeholder");if(d&&e.data("woocommerce.stickState-"+f,k),h.show().find(".select2-container").remove(),a.isEmptyObject(b.states[f]))g.replaceWith('');else{var m=a(''),n=b.states[f];m.append(a('")),a.each(n,function(b){m.append(a('"))}),m.val(k),g.replaceWith(m),m.show().select2().hide().change()}a(document.body).trigger("contry-change.woocommerce",[f,a(this).closest("div")]),a(document.body).trigger("country-change.woocommerce",[f,a(this).closest("div")])}},change_state:function(){var b=a(this),c=b.val(),d=b.parents("div.edit_address").find(":input.js_field-country"),e=d.val();d.data("woocommerce.stickState-"+e,c)},init_tiptip:function(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})},edit_address:function(b){b.preventDefault(),a(this).hide(),a(this).parent().find("a:not(.edit_address)").show(),a(this).closest(".order_data_column").find("div.address").hide(),a(this).closest(".order_data_column").find("div.edit_address").show()},change_customer_user:function(){a("#_billing_country").val()||(a("a.edit_address").click(),b.load_billing(!0),b.load_shipping(!0))},load_billing:function(b){if(!0===b||window.confirm(woocommerce_admin_meta_boxes.load_billing)){var c=a("#customer_user").val();if(!c)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var d={user_id:c,type_to_load:"billing",action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};a(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(b){b&&a.each(b,function(b,c){a(":input#_"+b).val(c).change()}),a("div.edit_address").unblock()}})}return!1},load_shipping:function(b){if(!0===b||window.confirm(woocommerce_admin_meta_boxes.load_shipping)){var c=a("#customer_user").val();if(!c)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var d={user_id:c,type_to_load:"shipping",action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};a(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(b){b&&a.each(b,function(b,c){a(":input#_"+b).val(c).change()}),a("div.edit_address").unblock()}})}return!1},copy_billing_to_shipping:function(){return window.confirm(woocommerce_admin_meta_boxes.copy_billing)&&a('.order_data_column :input[name^="_billing_"]').each(function(){var b=a(this).attr("name");b=b.replace("_billing_","_shipping_"),a(":input#"+b).val(a(this).val()).change()}),!1}},c={init:function(){this.stupidtable.init(),a("#woocommerce-order-items").on("click","button.add-line-item",this.add_line_item).on("click","button.refund-items",this.refund_items).on("click",".cancel-action",this.cancel).on("click","button.add-order-item",this.add_item).on("click","button.add-order-fee",this.add_fee).on("click","button.add-order-shipping",this.add_shipping).on("click","button.add-order-tax",this.add_tax).on("click","input.check-column",this.bulk_actions.check_column).on("click",".do_bulk_action",this.bulk_actions.do_bulk_action).on("click","button.calculate-action",this.calculate_totals).on("click","button.save-action",this.save_line_items).on("click","a.delete-order-tax",this.delete_tax).on("click","button.calculate-tax-action",this.calculate_tax).on("click","a.edit-order-item",this.edit_item).on("click","a.delete-order-item",this.delete_item).on("click",".delete_refund",this.refunds.delete_refund).on("click","button.do-api-refund, button.do-manual-refund",this.refunds.do_refund).on("change",".refund input.refund_line_total, .refund input.refund_line_tax",this.refunds.input_changed).on("change keyup",".wc-order-refund-items #refund_amount",this.refunds.amount_changed).on("change","input.refund_order_item_qty",this.refunds.refund_quantity_changed).on("change","input.quantity",this.quantity_changed).on("keyup",".woocommerce_order_items .split-input input:eq(0)",function(){var b=a(this).next();(""===b.val()||b.is(".match-total"))&&b.val(a(this).val()).addClass("match-total")}).on("keyup",".woocommerce_order_items .split-input input:eq(1)",function(){a(this).removeClass("match-total")}).on("click","button.add_order_item_meta",this.item_meta.add).on("click","button.remove_order_item_meta",this.item_meta.remove),a(document.body).on("wc_backbone_modal_loaded",this.backbone.init).on("wc_backbone_modal_response",this.backbone.response)},block:function(){a("#woocommerce-order-items").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a("#woocommerce-order-items").unblock()},reload_items:function(){var d={order_id:woocommerce_admin_meta_boxes.post_id,action:"woocommerce_load_order_items",security:woocommerce_admin_meta_boxes.order_item_nonce};c.block(),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}})},quantity_changed:function(){var b=a(this).closest("tr.item"),c=a(this).val(),d=a(this).attr("data-qty"),e=a("input.line_total",b),f=a("input.line_subtotal",b),g=accounting.unformat(e.attr("data-total"),woocommerce_admin.mon_decimal_point)/d;e.val(parseFloat(accounting.formatNumber(g*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point));var h=accounting.unformat(f.attr("data-subtotal"),woocommerce_admin.mon_decimal_point)/d;f.val(parseFloat(accounting.formatNumber(h*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)),a("td.line_tax",b).each(function(){var b=a("input.line_tax",a(this)),e=accounting.unformat(b.attr("data-total_tax"),woocommerce_admin.mon_decimal_point)/d;e>0&&b.val(parseFloat(accounting.formatNumber(e*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point));var f=a("input.line_subtotal_tax",a(this)),g=accounting.unformat(f.attr("data-subtotal_tax"),woocommerce_admin.mon_decimal_point)/d;g>0&&f.val(parseFloat(accounting.formatNumber(g*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point))}),a(this).trigger("quantity_changed")},add_line_item:function(){return a("div.wc-order-add-item").slideDown(),a("div.wc-order-bulk-actions").slideUp(),!1},refund_items:function(){return a("div.wc-order-refund-items").slideDown(),a("div.wc-order-bulk-actions").slideUp(),a("div.wc-order-totals-items").slideUp(),a("#woocommerce-order-items").find("div.refund").show(),a(".wc-order-edit-line-item .wc-order-edit-line-item-actions").hide(),!1},cancel:function(){return a(this).closest("div.wc-order-data-row").slideUp(),a("div.wc-order-bulk-actions").slideDown(),a("div.wc-order-totals-items").slideDown(),a("#woocommerce-order-items").find("div.refund").hide(),a(".wc-order-edit-line-item .wc-order-edit-line-item-actions").show(),"true"===a(this).attr("data-reload")&&c.reload_items(),!1},add_item:function(){return a(this).WCBackboneModal({template:"wc-modal-add-products"}),!1},add_fee:function(){c.block();var b={action:"woocommerce_add_order_fee",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(b){a("table.woocommerce_order_items tbody#order_fee_line_items").append(b),c.unblock()}),!1},add_shipping:function(){c.block();var b={action:"woocommerce_add_order_shipping",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(b){a("table.woocommerce_order_items tbody#order_shipping_line_items").append(b),c.unblock()}),!1},add_tax:function(){return a(this).WCBackboneModal({template:"wc-modal-add-tax"}),!1},edit_item:function(){return a(this).closest("tr").find(".view").hide(),a(this).closest("tr").find(".edit").show(),a(this).hide(),a("button.add-line-item").click(),a("button.cancel-action").attr("data-reload",!0),!1},delete_item:function(){var b=window.confirm(woocommerce_admin_meta_boxes.remove_item_notice);if(b){var d=a(this).closest("tr.item, tr.fee, tr.shipping"),e=d.attr("data-order_item_id");c.block();var f={order_item_ids:e,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:f,type:"POST",success:function(){d.remove(),c.unblock()}})}return!1},delete_tax:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_tax)){c.block();var d={action:"woocommerce_remove_order_tax",rate_id:a(this).attr("data-rate_id"),order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}})}return!1},calculate_tax:function(){if(window.confirm(woocommerce_admin_meta_boxes.calc_line_taxes)){c.block();var d="",e="",f="",g="";"shipping"===woocommerce_admin_meta_boxes.tax_based_on&&(d=a("#_shipping_country").val(),e=a("#_shipping_state").val(),f=a("#_shipping_postcode").val(),g=a("#_shipping_city").val()),"billing"!==woocommerce_admin_meta_boxes.tax_based_on&&d||(d=a("#_billing_country").val(),e=a("#_billing_state").val(),f=a("#_billing_postcode").val(),g=a("#_billing_city").val());var h={action:"woocommerce_calc_line_taxes",order_id:woocommerce_admin_meta_boxes.post_id,items:a("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize(),country:d,state:e,postcode:f,city:g,security:woocommerce_admin_meta_boxes.calc_totals_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:h,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}})}return!1},calculate_totals:function(){if(window.confirm(woocommerce_admin_meta_boxes.calc_totals)){c.block();var b=0,d=0,e=0;a(".woocommerce_order_items tr.shipping input.line_total").each(function(){var b=a(this).val()||"0";b=accounting.unformat(b,woocommerce_admin.mon_decimal_point),e+=parseFloat(b)}),a(".woocommerce_order_items input.line_tax").each(function(){var b=a(this).val()||"0";b=accounting.unformat(b,woocommerce_admin.mon_decimal_point),d+=parseFloat(b)}),a(".woocommerce_order_items tr.item, .woocommerce_order_items tr.fee").each(function(){var c=a(this).find("input.line_total").val()||"0";b+=accounting.unformat(c.replace(",","."))}),"yes"===woocommerce_admin_meta_boxes.round_at_subtotal&&(d=parseFloat(accounting.toFixed(d,woocommerce_admin_meta_boxes.rounding_precision))),a("#_order_total").val(accounting.formatNumber(b+d+e,woocommerce_admin_meta_boxes.currency_format_num_decimals,"",woocommerce_admin.mon_decimal_point)).change(),a("button.save-action").click()}return!1},save_line_items:function(){var d={order_id:woocommerce_admin_meta_boxes.post_id,items:a("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize(),action:"woocommerce_save_order_items",security:woocommerce_admin_meta_boxes.order_item_nonce};return c.block(),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}}),a(this).trigger("items_saved"),!1},refunds:{do_refund:function(){if(c.block(),window.confirm(woocommerce_admin_meta_boxes.i18n_do_refund)){var b=a("input#refund_amount").val(),d=a("input#refund_reason").val(),e={},f={},g={};a(".refund input.refund_order_item_qty").each(function(b,c){a(c).closest("tr").data("order_item_id")&&c.value&&(e[a(c).closest("tr").data("order_item_id")]=c.value)}),a(".refund input.refund_line_total").each(function(b,c){a(c).closest("tr").data("order_item_id")&&(f[a(c).closest("tr").data("order_item_id")]=accounting.unformat(c.value,woocommerce_admin.mon_decimal_point))}),a(".refund input.refund_line_tax").each(function(b,c){if(a(c).closest("tr").data("order_item_id")){var d=a(c).data("tax_id");g[a(c).closest("tr").data("order_item_id")]||(g[a(c).closest("tr").data("order_item_id")]={}),g[a(c).closest("tr").data("order_item_id")][d]=accounting.unformat(c.value,woocommerce_admin.mon_decimal_point)}});var h={action:"woocommerce_refund_line_items",order_id:woocommerce_admin_meta_boxes.post_id,refund_amount:b,refund_reason:d,line_item_qtys:JSON.stringify(e,null,""),line_item_totals:JSON.stringify(f,null,""),line_item_tax_totals:JSON.stringify(g,null,""),api_refund:a(this).is(".do-api-refund"),restock_refunded_items:a("#restock_refunded_items:checked").size()?"true":"false",security:woocommerce_admin_meta_boxes.order_item_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,h,function(a){!0===a.success?(c.reload_items(),"fully_refunded"===a.data.status&&(window.location.href=window.location.href)):(window.alert(a.data.error),c.unblock())})}else c.unblock()},delete_refund:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_refund)){var b=a(this).closest("tr.refund"),d=b.attr("data-order_refund_id");c.block();var e={action:"woocommerce_delete_refund",refund_id:d,security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(){c.reload_items()}})}return!1},input_changed:function(){var b=0,c=a(".woocommerce_order_items").find("tr.item, tr.fee, tr.shipping");c.each(function(){var c=a(this),d=c.find(".refund input:not(.refund_order_item_qty)");d.each(function(c,d){b+=parseFloat(accounting.unformat(a(d).val()||0,woocommerce_admin.mon_decimal_point))})}),a("#refund_amount").val(accounting.formatNumber(b,woocommerce_admin_meta_boxes.currency_format_num_decimals,"",woocommerce_admin.mon_decimal_point)).change()},amount_changed:function(){var b=accounting.unformat(a(this).val(),woocommerce_admin.mon_decimal_point);a("button .wc-order-refund-amount .amount").text(accounting.formatMoney(b,{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}))},refund_quantity_changed:function(){var b=a(this).closest("tr.item"),c=b.find("input.quantity").val(),d=a(this).val(),e=a("input.line_total",b),f=a("input.refund_line_total",b),g=accounting.unformat(e.attr("data-total"),woocommerce_admin.mon_decimal_point)/c;f.val(parseFloat(accounting.formatNumber(g*d,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)).change(),a("td.line_tax",b).each(function(){var b=a("input.line_tax",a(this)),e=a("input.refund_line_tax",a(this)),f=accounting.unformat(b.attr("data-total_tax"),woocommerce_admin.mon_decimal_point)/c;f>0?e.val(parseFloat(accounting.formatNumber(f*d,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)).change():e.val(0).change()}),d>0?a("#restock_refunded_items").closest("tr").show():(a("#restock_refunded_items").closest("tr").hide(),a(".woocommerce_order_items input.refund_order_item_qty").each(function(){a(this).val()>0&&a("#restock_refunded_items").closest("tr").show()})),a(this).trigger("refund_quantity_changed")}},item_meta:{add:function(){var b=a(this),d=b.closest("tr.item"),e={order_item_id:d.attr("data-order_item_id"),action:"woocommerce_add_order_item_meta",security:woocommerce_admin_meta_boxes.order_item_nonce};return c.block(),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(a){d.find("tbody.meta_items").append(a),c.unblock()}}),!1},remove:function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_item_meta)){var b=a(this).closest("tr"),d={meta_id:b.attr("data-meta_id"),action:"woocommerce_remove_order_item_meta",security:woocommerce_admin_meta_boxes.order_item_nonce};c.block(),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(){b.hide(),c.unblock()}})}return!1}},bulk_actions:{check_column:function(){a(this).is(":checked")?a("#woocommerce-order-items").find(".check-column input").attr("checked","checked"):a("#woocommerce-order-items").find(".check-column input").removeAttr("checked")},do_bulk_action:function(){var b=a(this).closest(".bulk-actions").find("select").val(),d=a("#woocommerce-order-items").find(".check-column input:checked"),e=[];return a(d).each(function(){var b=a(this).closest("tr");b.attr("data-order_item_id")&&e.push(b.attr("data-order_item_id"))}),0===e.length?void window.alert(woocommerce_admin_meta_boxes.i18n_select_items):(c.bulk_actions["do_"+b]&&c.bulk_actions["do_"+b](d,e),!1)},do_delete:function(b,d){if(window.confirm(woocommerce_admin_meta_boxes.remove_item_notice)){c.block();var e={order_item_ids:d,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(){a(b).each(function(){a(this).closest("tr").remove()}),c.unblock()}})}},do_increase_stock:function(b,d){c.block();var e={};a(b).each(function(){var b=a(this).closest("tr.item, tr.fee"),c=b.find("input.quantity");e[b.attr("data-order_item_id")]=c.val()});var f={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:d,order_item_qty:e,action:"woocommerce_increase_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:f,type:"POST",success:function(a){window.alert(a),c.unblock()}})},do_reduce_stock:function(b,d){c.block();var e={};a(b).each(function(){var b=a(this).closest("tr.item, tr.fee"),c=b.find("input.quantity");e[b.attr("data-order_item_id")]=c.val()});var f={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:d,order_item_qty:e,action:"woocommerce_reduce_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:f,type:"POST",success:function(a){window.alert(a),c.unblock()}})}},backbone:{init:function(b,c){"wc-modal-add-products"===c&&a(document.body).trigger("wc-enhanced-select-init")},response:function(a,b,d){if("wc-modal-add-tax"===b){var e=d.add_order_tax,f="";d.manual_tax_rate_id&&(f=d.manual_tax_rate_id),c.backbone.add_tax(e,f)}"wc-modal-add-products"===b&&c.backbone.add_item(d.add_order_items)},add_item:function(d){if(d=d.split(",")){var e=d.length;c.block(),a.each(d,function(d,f){var g={action:"woocommerce_add_order_item",item_to_add:f,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,g,function(d){a("table.woocommerce_order_items tbody#order_line_items").append(d),--e||(b.init_tiptip(),c.unblock())})})}},add_tax:function(d,e){if(e&&(d=e),!d)return!1;var f=a(".order-tax-id").map(function(){return a(this).val()}).get();if(-1===a.inArray(d,f)){c.block();var g={action:"woocommerce_add_order_tax",rate_id:d,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:g,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}})}else window.alert(woocommerce_admin_meta_boxes.i18n_tax_rate_already_exists)}},stupidtable:{init:function(){a(".woocommerce_order_items").stupidtable().on("aftertablesort",this.add_arrows)},add_arrows:function(b,c){var d=a(this).find("th"),e="asc"===c.direction?"↑":"↓",f=c.column;f>1&&(f-=1),d.find(".wc-arrow").remove(),d.eq(f).append(''+e+"")}}},d={init:function(){a("#woocommerce-order-notes").on("click","a.add_note",this.add_order_note).on("click","a.delete_note",this.delete_order_note)},add_order_note:function(){if(a("textarea#add_order_note").val()){a("#woocommerce-order-notes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b={action:"woocommerce_add_order_note",post_id:woocommerce_admin_meta_boxes.post_id,note:a("textarea#add_order_note").val(),note_type:a("select#order_note_type").val(),security:woocommerce_admin_meta_boxes.add_order_note_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(b){a("ul.order_notes").prepend(b),a("#woocommerce-order-notes").unblock(),a("#add_order_note").val("")}),!1}},delete_order_note:function(){var b=a(this).closest("li.note");a(b).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var c={action:"woocommerce_delete_order_note",note_id:a(b).attr("rel"),security:woocommerce_admin_meta_boxes.delete_order_note_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,c,function(){a(b).remove()}),!1}},e={init:function(){a(".order_download_permissions").on("click","button.grant_access",this.grant_access).on("click","button.revoke_access",this.revoke_access)},grant_access:function(){var b=a("#grant_access_id").val();if(b){a(".order_download_permissions").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var c={action:"woocommerce_grant_access_to_download",product_ids:b,loop:a(".order_download_permissions .wc-metabox").size(),order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.grant_access_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,c,function(b){b?a(".order_download_permissions .wc-metaboxes").append(b):window.alert(woocommerce_admin_meta_boxes.i18n_download_permission_fail),a(document.body).trigger("wc-init-datepickers"),a("#grant_access_id").val("").change(),a(".order_download_permissions").unblock()}),!1}},revoke_access:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_permission_revoke)){var b=a(this).parent().parent(),c=a(this).attr("rel").split(",")[0],d=a(this).attr("rel").split(",")[1];if(c>0){a(b).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e={action:"woocommerce_revoke_access_to_download",product_id:c,download_id:d,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.revoke_access_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,e,function(){a(b).fadeOut("300",function(){a(b).remove()})})}else a(b).fadeOut("300",function(){a(b).remove()})}return!1}};b.init(),c.init(),d.init(),e.init()}); \ No newline at end of file +jQuery(function(a){var b={states:null,init:function(){"undefined"!=typeof woocommerce_admin_meta_boxes_order&&"undefined"!=typeof woocommerce_admin_meta_boxes_order.countries&&(this.states=a.parseJSON(woocommerce_admin_meta_boxes_order.countries.replace(/"/g,'"'))),a(".js_field-country").select2().change(this.change_country),a(".js_field-country").trigger("change",[!0]),a(document.body).on("change","select.js_field-state",this.change_state),a("#woocommerce-order-actions input, #woocommerce-order-actions a").click(function(){window.onbeforeunload=""}),a("a.edit_address").click(this.edit_address),a("a.billing-same-as-shipping").on("click",this.copy_billing_to_shipping),a("a.load_customer_billing").on("click",this.load_billing),a("a.load_customer_shipping").on("click",this.load_shipping),a("#customer_user").on("change",this.change_customer_user)},change_country:function(c,d){if("undefined"==typeof d&&(d=!1),null!==b.states){var e=a(this),f=e.val(),g=e.parents("div.edit_address").find(":input.js_field-state"),h=g.parent(),i=g.attr("name"),j=g.attr("id"),k=e.data("woocommerce.stickState-"+f)?e.data("woocommerce.stickState-"+f):g.val(),l=g.attr("placeholder");if(d&&e.data("woocommerce.stickState-"+f,k),h.show().find(".select2-container").remove(),a.isEmptyObject(b.states[f]))g.replaceWith('');else{var m=a(''),n=b.states[f];m.append(a('")),a.each(n,function(b){m.append(a('"))}),m.val(k),g.replaceWith(m),m.show().select2().hide().change()}a(document.body).trigger("contry-change.woocommerce",[f,a(this).closest("div")]),a(document.body).trigger("country-change.woocommerce",[f,a(this).closest("div")])}},change_state:function(){var b=a(this),c=b.val(),d=b.parents("div.edit_address").find(":input.js_field-country"),e=d.val();d.data("woocommerce.stickState-"+e,c)},init_tiptip:function(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})},edit_address:function(b){b.preventDefault(),a(this).hide(),a(this).parent().find("a:not(.edit_address)").show(),a(this).closest(".order_data_column").find("div.address").hide(),a(this).closest(".order_data_column").find("div.edit_address").show()},change_customer_user:function(){a("#_billing_country").val()||(a("a.edit_address").click(),b.load_billing(!0),b.load_shipping(!0))},load_billing:function(b){if(!0===b||window.confirm(woocommerce_admin_meta_boxes.load_billing)){var c=a("#customer_user").val();if(!c)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var d={user_id:c,type_to_load:"billing",action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};a(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(b){b&&a.each(b,function(b,c){a(":input#_"+b).val(c).change()}),a("div.edit_address").unblock()}})}return!1},load_shipping:function(b){if(!0===b||window.confirm(woocommerce_admin_meta_boxes.load_shipping)){var c=a("#customer_user").val();if(!c)return window.alert(woocommerce_admin_meta_boxes.no_customer_selected),!1;var d={user_id:c,type_to_load:"shipping",action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};a(this).closest("div.edit_address").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(b){b&&a.each(b,function(b,c){a(":input#_"+b).val(c).change()}),a("div.edit_address").unblock()}})}return!1},copy_billing_to_shipping:function(){return window.confirm(woocommerce_admin_meta_boxes.copy_billing)&&a('.order_data_column :input[name^="_billing_"]').each(function(){var b=a(this).attr("name");b=b.replace("_billing_","_shipping_"),a(":input#"+b).val(a(this).val()).change()}),!1}},c={init:function(){this.stupidtable.init(),a("#woocommerce-order-items").on("click","button.add-line-item",this.add_line_item).on("click","button.refund-items",this.refund_items).on("click",".cancel-action",this.cancel).on("click","button.add-order-item",this.add_item).on("click","button.add-order-fee",this.add_fee).on("click","button.add-order-shipping",this.add_shipping).on("click","button.add-order-tax",this.add_tax).on("click","button.calculate-action",this.calculate_totals).on("click","button.save-action",this.save_line_items).on("click","a.delete-order-tax",this.delete_tax).on("click","button.calculate-tax-action",this.calculate_tax).on("click","a.edit-order-item",this.edit_item).on("click","a.delete-order-item",this.delete_item).on("click","tr.item, tr.fee, tr.shipping, tr.refund",this.select_row).on("click","tr.item :input, tr.fee :input, tr.shipping :input, tr.refund :input, tr.item a, tr.fee a, tr.shipping a, tr.refund a",this.select_row_child).on("click","button.bulk-delete-items",this.bulk_actions.do_delete).on("click","button.bulk-increase-stock",this.bulk_actions.do_increase_stock).on("click","button.bulk-decrease-stock",this.bulk_actions.do_reduce_stock).on("click",".delete_refund",this.refunds.delete_refund).on("click","button.do-api-refund, button.do-manual-refund",this.refunds.do_refund).on("change",".refund input.refund_line_total, .refund input.refund_line_tax",this.refunds.input_changed).on("change keyup",".wc-order-refund-items #refund_amount",this.refunds.amount_changed).on("change","input.refund_order_item_qty",this.refunds.refund_quantity_changed).on("change","input.quantity",this.quantity_changed).on("keyup change",".split-input :input",function(){var b=a(this).parent().prev().find(":input");b&&(""===b.val()||b.is(".match-total"))&&b.val(a(this).val()).addClass("match-total")}).on("keyup",".split-input :input",function(){a(this).removeClass("match-total")}).on("click","button.add_order_item_meta",this.item_meta.add).on("click","button.remove_order_item_meta",this.item_meta.remove),a(document.body).on("wc_backbone_modal_loaded",this.backbone.init).on("wc_backbone_modal_response",this.backbone.response)},block:function(){a("#woocommerce-order-items").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a("#woocommerce-order-items").unblock()},reload_items:function(){var d={order_id:woocommerce_admin_meta_boxes.post_id,action:"woocommerce_load_order_items",security:woocommerce_admin_meta_boxes.order_item_nonce};c.block(),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}})},quantity_changed:function(){var b=a(this).closest("tr.item"),c=a(this).val(),d=a(this).attr("data-qty"),e=a("input.line_total",b),f=a("input.line_subtotal",b),g=accounting.unformat(e.attr("data-total"),woocommerce_admin.mon_decimal_point)/d;e.val(parseFloat(accounting.formatNumber(g*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point));var h=accounting.unformat(f.attr("data-subtotal"),woocommerce_admin.mon_decimal_point)/d;f.val(parseFloat(accounting.formatNumber(h*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)),a("input.line_tax",b).each(function(){var e=a(this),f=e.data("tax_id"),g=accounting.unformat(e.attr("data-total_tax"),woocommerce_admin.mon_decimal_point)/d,h=a('input.line_subtotal_tax[data-tax_id="'+f+'"]',b),i=accounting.unformat(h.attr("data-subtotal_tax"),woocommerce_admin.mon_decimal_point)/d;g>0&&e.val(parseFloat(accounting.formatNumber(g*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)),i>0&&h.val(parseFloat(accounting.formatNumber(i*c,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point))}),a(this).trigger("quantity_changed")},add_line_item:function(){return a("div.wc-order-add-item").slideDown(),a("div.wc-order-data-row-toggle").not("div.wc-order-add-item").slideUp(),!1},refund_items:function(){return a("div.wc-order-refund-items").slideDown(),a("div.wc-order-data-row-toggle").not("div.wc-order-refund-items").slideUp(),a("div.wc-order-totals-items").slideUp(),a("#woocommerce-order-items").find("div.refund").show(),a(".wc-order-edit-line-item .wc-order-edit-line-item-actions").hide(),!1},cancel:function(){return a("div.wc-order-data-row-toggle").not("div.wc-order-bulk-actions").slideUp(),a("div.wc-order-bulk-actions").slideDown(),a("div.wc-order-totals-items").slideDown(),a("#woocommerce-order-items").find("div.refund").hide(),a(".wc-order-edit-line-item .wc-order-edit-line-item-actions").show(),"true"===a(this).attr("data-reload")&&c.reload_items(),!1},add_item:function(){return a(this).WCBackboneModal({template:"wc-modal-add-products"}),!1},add_fee:function(){c.block();var b={action:"woocommerce_add_order_fee",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(b){a("table.woocommerce_order_items tbody#order_fee_line_items").append(b),c.unblock()}),!1},add_shipping:function(){c.block();var b={action:"woocommerce_add_order_shipping",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(b){a("table.woocommerce_order_items tbody#order_shipping_line_items").append(b),c.unblock()}),!1},add_tax:function(){return a(this).WCBackboneModal({template:"wc-modal-add-tax"}),!1},edit_item:function(){return a(this).closest("tr").find(".view").hide(),a(this).closest("tr").find(".edit").show(),a(this).hide(),a("button.add-line-item").click(),a("button.cancel-action").attr("data-reload",!0),!1},delete_item:function(){var b=window.confirm(woocommerce_admin_meta_boxes.remove_item_notice);if(b){var d=a(this).closest("tr.item, tr.fee, tr.shipping"),e=d.attr("data-order_item_id");c.block();var f={order_item_ids:e,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:f,type:"POST",success:function(){d.remove(),c.unblock()}})}return!1},delete_tax:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_tax)){c.block();var d={action:"woocommerce_remove_order_tax",rate_id:a(this).attr("data-rate_id"),order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}})}return!1},calculate_tax:function(){if(window.confirm(woocommerce_admin_meta_boxes.calc_line_taxes)){c.block();var d="",e="",f="",g="";"shipping"===woocommerce_admin_meta_boxes.tax_based_on&&(d=a("#_shipping_country").val(),e=a("#_shipping_state").val(),f=a("#_shipping_postcode").val(),g=a("#_shipping_city").val()),"billing"!==woocommerce_admin_meta_boxes.tax_based_on&&d||(d=a("#_billing_country").val(),e=a("#_billing_state").val(),f=a("#_billing_postcode").val(),g=a("#_billing_city").val());var h={action:"woocommerce_calc_line_taxes",order_id:woocommerce_admin_meta_boxes.post_id,items:a("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize(),country:d,state:e,postcode:f,city:g,security:woocommerce_admin_meta_boxes.calc_totals_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:h,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}})}return!1},calculate_totals:function(){if(window.confirm(woocommerce_admin_meta_boxes.calc_totals)){c.block();var b=0,d=0,e=0;a(".woocommerce_order_items tr.shipping input.line_total").each(function(){var b=a(this).val()||"0";b=accounting.unformat(b,woocommerce_admin.mon_decimal_point),e+=parseFloat(b)}),a(".woocommerce_order_items input.line_tax").each(function(){var b=a(this).val()||"0";b=accounting.unformat(b,woocommerce_admin.mon_decimal_point),d+=parseFloat(b)}),a(".woocommerce_order_items tr.item, .woocommerce_order_items tr.fee").each(function(){var c=a(this).find("input.line_total").val()||"0";b+=accounting.unformat(c.replace(",","."))}),"yes"===woocommerce_admin_meta_boxes.round_at_subtotal&&(d=parseFloat(accounting.toFixed(d,woocommerce_admin_meta_boxes.rounding_precision))),a("#_order_total").val(accounting.formatNumber(b+d+e,woocommerce_admin_meta_boxes.currency_format_num_decimals,"",woocommerce_admin.mon_decimal_point)).change(),a("button.save-action").click()}return!1},save_line_items:function(){var d={order_id:woocommerce_admin_meta_boxes.post_id,items:a("table.woocommerce_order_items :input[name], .wc-order-totals-items :input[name]").serialize(),action:"woocommerce_save_order_items",security:woocommerce_admin_meta_boxes.order_item_nonce};return c.block(),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}}),a(this).trigger("items_saved"),!1},refunds:{do_refund:function(){if(c.block(),window.confirm(woocommerce_admin_meta_boxes.i18n_do_refund)){var b=a("input#refund_amount").val(),d=a("input#refund_reason").val(),e={},f={},g={};a(".refund input.refund_order_item_qty").each(function(b,c){a(c).closest("tr").data("order_item_id")&&c.value&&(e[a(c).closest("tr").data("order_item_id")]=c.value)}),a(".refund input.refund_line_total").each(function(b,c){a(c).closest("tr").data("order_item_id")&&(f[a(c).closest("tr").data("order_item_id")]=accounting.unformat(c.value,woocommerce_admin.mon_decimal_point))}),a(".refund input.refund_line_tax").each(function(b,c){if(a(c).closest("tr").data("order_item_id")){var d=a(c).data("tax_id");g[a(c).closest("tr").data("order_item_id")]||(g[a(c).closest("tr").data("order_item_id")]={}),g[a(c).closest("tr").data("order_item_id")][d]=accounting.unformat(c.value,woocommerce_admin.mon_decimal_point)}});var h={action:"woocommerce_refund_line_items",order_id:woocommerce_admin_meta_boxes.post_id,refund_amount:b,refund_reason:d,line_item_qtys:JSON.stringify(e,null,""),line_item_totals:JSON.stringify(f,null,""),line_item_tax_totals:JSON.stringify(g,null,""),api_refund:a(this).is(".do-api-refund"),restock_refunded_items:a("#restock_refunded_items:checked").length?"true":"false",security:woocommerce_admin_meta_boxes.order_item_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,h,function(a){!0===a.success?(c.reload_items(),"fully_refunded"===a.data.status&&(window.location.href=window.location.href)):(window.alert(a.data.error),c.unblock())})}else c.unblock()},delete_refund:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_delete_refund)){var b=a(this).closest("tr.refund"),d=b.attr("data-order_refund_id");c.block();var e={action:"woocommerce_delete_refund",refund_id:d,security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(){c.reload_items()}})}return!1},input_changed:function(){var b=0,c=a(".woocommerce_order_items").find("tr.item, tr.fee, tr.shipping");c.each(function(){var c=a(this),d=c.find(".refund input:not(.refund_order_item_qty)");d.each(function(c,d){b+=parseFloat(accounting.unformat(a(d).val()||0,woocommerce_admin.mon_decimal_point))})}),a("#refund_amount").val(accounting.formatNumber(b,woocommerce_admin_meta_boxes.currency_format_num_decimals,"",woocommerce_admin.mon_decimal_point)).change()},amount_changed:function(){var b=accounting.unformat(a(this).val(),woocommerce_admin.mon_decimal_point);a("button .wc-order-refund-amount .amount").text(accounting.formatMoney(b,{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}))},refund_quantity_changed:function(){var b=a(this).closest("tr.item"),c=b.find("input.quantity").val(),d=a(this).val(),e=a("input.line_total",b),f=a("input.refund_line_total",b),g=accounting.unformat(e.attr("data-total"),woocommerce_admin.mon_decimal_point)/c;f.val(parseFloat(accounting.formatNumber(g*d,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)).change(),a(".refund_line_tax",b).each(function(){var e=a(this),f=e.data("tax_id"),g=a('input.line_tax[data-tax_id="'+f+'"]',b),h=accounting.unformat(g.data("total_tax"),woocommerce_admin.mon_decimal_point)/c;h>0?e.val(parseFloat(accounting.formatNumber(h*d,woocommerce_admin_meta_boxes.rounding_precision,"")).toString().replace(".",woocommerce_admin.mon_decimal_point)).change():e.val(0).change()}),d>0?a("#restock_refunded_items").closest("tr").show():(a("#restock_refunded_items").closest("tr").hide(),a(".woocommerce_order_items input.refund_order_item_qty").each(function(){a(this).val()>0&&a("#restock_refunded_items").closest("tr").show()})),a(this).trigger("refund_quantity_changed")}},item_meta:{add:function(){var b=a(this),d=b.closest("tr.item, tr.shipping"),e={order_item_id:d.attr("data-order_item_id"),action:"woocommerce_add_order_item_meta",security:woocommerce_admin_meta_boxes.order_item_nonce};return c.block(),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:e,type:"POST",success:function(a){d.find("tbody.meta_items").append(a),c.unblock()}}),!1},remove:function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_item_meta)){var b=a(this).closest("tr"),d={meta_id:b.attr("data-meta_id"),action:"woocommerce_remove_order_item_meta",security:woocommerce_admin_meta_boxes.order_item_nonce};c.block(),a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:d,type:"POST",success:function(){b.remove(),c.unblock()}})}return!1}},select_row:function(){var b=!1;b=a(this).is("tr")?a(this):a(this).closest("tr");var c=a(this).closest("table");b.is(".selected")?b.removeClass("selected"):b.addClass("selected");var d=c.find("tr.selected");if(d.length){a("div.wc-order-item-bulk-edit").slideDown();var e=!1;d.each(function(){a(this).is("tr.item")&&(e=!0)}),e?a(".bulk-increase-stock, .bulk-decrease-stock").show():a(".bulk-increase-stock, .bulk-decrease-stock").hide()}else a("div.wc-order-item-bulk-edit").slideUp()},select_row_child:function(a){a.stopPropagation()},bulk_actions:{do_delete:function(b){b.preventDefault();var d=a("table.woocommerce_order_items"),e=d.find("tr.selected");if(e.length&&window.confirm(woocommerce_admin_meta_boxes.remove_item_notice)){c.block();var f=[],g=[],h=[];a.map(e,function(b){var c=a(b);c.is(".refund")?g.push(parseInt(a(c).data("order_refund_id"),10)):f.push(parseInt(a(c).data("order_item_id"),10))}),f.length&&h.push(a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:{order_item_ids:f,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce},type:"POST"})),g.length&&h.push(a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:{action:"woocommerce_delete_refund",refund_id:g,security:woocommerce_admin_meta_boxes.order_item_nonce},type:"POST"})),h?a.when.apply(a,h).done(function(){c.reload_items(),c.unblock()}):c.unblock()}},do_increase_stock:function(b){b.preventDefault(),c.block();var d=a("table.woocommerce_order_items"),e=d.find("tr.selected"),f={},g=a.map(e,function(b){return parseInt(a(b).data("order_item_id"),10)});e.each(function(){a(this).find("input.quantity").length&&(f[a(this).attr("data-order_item_id")]=a(this).find("input.quantity").val())});var h={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:g,order_item_qty:f,action:"woocommerce_increase_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:h,type:"POST",success:function(a){window.alert(a),c.unblock()}})},do_reduce_stock:function(b){b.preventDefault(),c.block();var d=a("table.woocommerce_order_items"),e=d.find("tr.selected"),f={},g=a.map(e,function(b){return parseInt(a(b).data("order_item_id"),10)});e.each(function(){a(this).find("input.quantity").length&&(f[a(this).attr("data-order_item_id")]=a(this).find("input.quantity").val())});var h={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:g,order_item_qty:f,action:"woocommerce_reduce_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:h,type:"POST",success:function(a){window.alert(a),c.unblock()}})}},backbone:{init:function(b,c){"wc-modal-add-products"===c&&a(document.body).trigger("wc-enhanced-select-init")},response:function(a,b,d){if("wc-modal-add-tax"===b){var e=d.add_order_tax,f="";d.manual_tax_rate_id&&(f=d.manual_tax_rate_id),c.backbone.add_tax(e,f)}"wc-modal-add-products"===b&&c.backbone.add_item(d.add_order_items)},add_item:function(d){if(d=d.split(",")){var e=d.length;c.block(),a.each(d,function(d,f){var g={action:"woocommerce_add_order_item",item_to_add:f,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,g,function(d){a("table.woocommerce_order_items tbody#order_line_items").append(d),--e||(b.init_tiptip(),c.unblock())})})}},add_tax:function(d,e){if(e&&(d=e),!d)return!1;var f=a(".order-tax-id").map(function(){return a(this).val()}).get();if(-1===a.inArray(d,f)){c.block();var g={action:"woocommerce_add_order_tax",rate_id:d,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};a.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:g,type:"POST",success:function(d){a("#woocommerce-order-items").find(".inside").empty(),a("#woocommerce-order-items").find(".inside").append(d),b.init_tiptip(),c.unblock(),c.stupidtable.init()}})}else window.alert(woocommerce_admin_meta_boxes.i18n_tax_rate_already_exists)}},stupidtable:{init:function(){a(".woocommerce_order_items").stupidtable(),a(".woocommerce_order_items").on("aftertablesort",this.add_arrows)},add_arrows:function(b,c){var d=a(this).find("th"),e="asc"===c.direction?"↑":"↓",f=c.column;d.find(".wc-arrow").remove(),d.eq(f).append(''+e+"")}}},d={init:function(){a("#woocommerce-order-notes").on("click","a.add_note",this.add_order_note).on("click","a.delete_note",this.delete_order_note)},add_order_note:function(){if(a("textarea#add_order_note").val()){a("#woocommerce-order-notes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b={action:"woocommerce_add_order_note",post_id:woocommerce_admin_meta_boxes.post_id,note:a("textarea#add_order_note").val(),note_type:a("select#order_note_type").val(),security:woocommerce_admin_meta_boxes.add_order_note_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(b){a("ul.order_notes").prepend(b),a("#woocommerce-order-notes").unblock(),a("#add_order_note").val("")}),!1}},delete_order_note:function(){var b=a(this).closest("li.note");a(b).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var c={action:"woocommerce_delete_order_note",note_id:a(b).attr("rel"),security:woocommerce_admin_meta_boxes.delete_order_note_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,c,function(){a(b).remove()}),!1}},e={init:function(){a(".order_download_permissions").on("click","button.grant_access",this.grant_access).on("click","button.revoke_access",this.revoke_access)},grant_access:function(){var b=a("#grant_access_id").val();if(b){a(".order_download_permissions").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var c={action:"woocommerce_grant_access_to_download",product_ids:b,loop:a(".order_download_permissions .wc-metabox").length,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.grant_access_nonce};return a.post(woocommerce_admin_meta_boxes.ajax_url,c,function(b){b?a(".order_download_permissions .wc-metaboxes").append(b):window.alert(woocommerce_admin_meta_boxes.i18n_download_permission_fail),a(document.body).trigger("wc-init-datepickers"),a("#grant_access_id").val("").change(),a(".order_download_permissions").unblock()}),!1}},revoke_access:function(){if(window.confirm(woocommerce_admin_meta_boxes.i18n_permission_revoke)){var b=a(this).parent().parent(),c=a(this).attr("rel").split(",")[0],d=a(this).attr("rel").split(",")[1];if(c>0){a(b).block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e={action:"woocommerce_revoke_access_to_download",product_id:c,download_id:d,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.revoke_access_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,e,function(){a(b).fadeOut("300",function(){a(b).remove()})})}else a(b).fadeOut("300",function(){a(b).remove()})}return!1}};b.init(),c.init(),d.init(),e.init()}); \ No newline at end of file diff --git a/assets/js/admin/meta-boxes-product-variation.js b/assets/js/admin/meta-boxes-product-variation.js index fff33f6b644..5e0e86a7a86 100644 --- a/assets/js/admin/meta-boxes-product-variation.js +++ b/assets/js/admin/meta-boxes-product-variation.js @@ -554,7 +554,7 @@ jQuery( function( $ ) { var data = { action: 'woocommerce_add_variation', post_id: woocommerce_admin_meta_boxes_variations.post_id, - loop: $( '.woocommerce_variation' ).size(), + loop: $( '.woocommerce_variation' ).length, security: woocommerce_admin_meta_boxes_variations.add_variation_nonce }; diff --git a/assets/js/admin/meta-boxes-product-variation.min.js b/assets/js/admin/meta-boxes-product-variation.min.js index 3163ebbf7aa..9161bcea599 100644 --- a/assets/js/admin/meta-boxes-product-variation.min.js +++ b/assets/js/admin/meta-boxes-product-variation.min.js @@ -1 +1 @@ -jQuery(function(a){var b={init:function(){a("#variable_product_options").on("change","input.variable_is_downloadable",this.variable_is_downloadable).on("change","input.variable_is_virtual",this.variable_is_virtual).on("change","input.variable_manage_stock",this.variable_manage_stock).on("click","button.notice-dismiss",this.notice_dismiss).on("click","h3 .sort",this.set_menu_order).on("reload",this.reload),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),a("#woocommerce-product-data").on("woocommerce_variations_loaded",this.variations_loaded),a(document.body).on("woocommerce_variations_added",this.variation_added)},reload:function(){d.load_variations(1)},variable_is_downloadable:function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()},variable_is_virtual:function(){a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()},variable_manage_stock:function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").show()},notice_dismiss:function(){a(this).closest("div.notice").remove()},variations_loaded:function(c,d){d=d||!1;var e=a("#woocommerce-product-data");d||(a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock",e).change(),a(".woocommerce_variation",e).each(function(b,c){var d=a(c),e=a(".sale_price_dates_from",d).val(),f=a(".sale_price_dates_to",d).val();(""!==e||""!==f)&&a("a.sale_schedule",d).click()}),a(".woocommerce_variations .variation-needs-update",e).removeClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes",e).attr("disabled","disabled")),a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".woocommerce_variations .tips, .woocommerce_variations .help_tip, .woocommerce_variations .woocommerce-help-tip",e).tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}),a(".sale_price_dates_fields",e).each(function(){var b=a(this).find("input").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,onSelect:function(c){var d=a(this).is(".sale_price_dates_from")?"minDate":"maxDate",e=a(this).data("datepicker"),f=a.datepicker.parseDate(e.settings.dateFormat||a.datepicker._defaults.dateFormat,c,e.settings);b.not(this).datepicker("option",d,f),a(this).change()}})}),a(".woocommerce_variations",e).sortable({items:".woocommerce_variation",cursor:"move",axis:"y",handle:".sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,stop:function(){b.variation_row_indexes()}}),a(document.body).trigger("wc-enhanced-select-init")},variation_added:function(a,c){1===c&&b.variations_loaded(null,!0)},set_menu_order:function(b){b.preventDefault();var c=a(this).closest(".woocommerce_variation").find(".variation_menu_order"),e=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_menu_order,c.val());null!=e&&(c.val(parseInt(e,10)).change(),d.save_variations())},variation_row_indexes:function(){var b=a("#variable_product_options").find(".woocommerce_variations"),c=parseInt(b.attr("data-page"),10),d=parseInt((c-1)*woocommerce_admin_meta_boxes_variations.variations_per_page,10);a(".woocommerce_variations .woocommerce_variation").each(function(b,c){a(".variation_menu_order",c).val(parseInt(a(c).index(".woocommerce_variations .woocommerce_variation"),10)+1+d).change()})}},c={variable_image_frame:null,setting_variation_image_id:null,setting_variation_image:null,wp_media_post_id:wp.media.model.settings.post.id,init:function(){a("#variable_product_options").on("click",".upload_image_button",this.add_image),a("a.add_media").on("click",this.restore_wp_media_post_id)},add_image:function(b){var d=a(this),e=d.attr("rel"),f=d.closest(".upload_image");if(c.setting_variation_image=f,c.setting_variation_image_id=e,b.preventDefault(),d.is(".remove"))a(".upload_image_id",c.setting_variation_image).val("").change(),c.setting_variation_image.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),c.setting_variation_image.find(".upload_image_button").removeClass("remove");else{if(c.variable_image_frame)return c.variable_image_frame.uploader.uploader.param("post_id",c.setting_variation_image_id),void c.variable_image_frame.open();wp.media.model.settings.post.id=c.setting_variation_image_id,c.variable_image_frame=wp.media.frames.variable_image=wp.media({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,button:{text:woocommerce_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),c.variable_image_frame.on("select",function(){var b=c.variable_image_frame.state().get("selection").first().toJSON(),d=b.sizes&&b.sizes.thumbnail?b.sizes.thumbnail.url:b.url;a(".upload_image_id",c.setting_variation_image).val(b.id).change(),c.setting_variation_image.find(".upload_image_button").addClass("remove"),c.setting_variation_image.find("img").eq(0).attr("src",d),wp.media.model.settings.post.id=c.wp_media_post_id}),c.variable_image_frame.open()}},restore_wp_media_post_id:function(){wp.media.model.settings.post.id=c.wp_media_post_id}},d={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("#variable_product_options").on("click","button.save-variation-changes",this.save_variations).on("click","button.cancel-variation-changes",this.cancel_variations).on("click",".remove_variation",this.remove_variation),a(document.body).on("change","#variable_product_options .woocommerce_variations :input",this.input_changed).on("change",".variations-defaults select",this.defaults_changed),a("form#post").on("submit",this.save_on_submit),a(".wc-metaboxes-wrapper").on("click","a.do_variation_action",this.do_variation_action)},check_for_changes:function(){var b=a("#variable_product_options").find(".woocommerce_variations .variation-needs-update");if(00?(c.push(b),f.variation_ids=c,f.security=woocommerce_admin_meta_boxes_variations.delete_variations_nonce,a.post(woocommerce_admin_meta_boxes_variations.ajax_url,f,function(){var b=a("#variable_product_options").find(".woocommerce_variations"),c=parseInt(b.attr("data-page"),10),d=Math.ceil((parseInt(b.attr("data-total"),10)-1)/woocommerce_admin_meta_boxes_variations.variations_per_page),f=1;a("#woocommerce-product-data").trigger("woocommerce_variations_removed"),c===d||d>=c?f=c:c>d&&0!==d&&(f=d),e.go_to_page(f,-1)})):d.unblock()}return!1},link_all_variations:function(){if(d.check_for_changes(),window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations)){d.block();var b={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,b,function(b){var c=parseInt(b,10);1===c?window.alert(c+" "+woocommerce_admin_meta_boxes_variations.i18n_variation_added):0===c||c>1?window.alert(c+" "+woocommerce_admin_meta_boxes_variations.i18n_variations_added):window.alert(woocommerce_admin_meta_boxes_variations.i18n_no_variations_added),c>0?(e.go_to_page(1,c),a("#variable_product_options").trigger("woocommerce_variations_added",c)):d.unblock()})}return!1},input_changed:function(){a(this).closest(".woocommerce_variation").addClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes").removeAttr("disabled"),a("#variable_product_options").trigger("woocommerce_variations_input_changed")},defaults_changed:function(){a(this).closest("#variable_product_options").find(".woocommerce_variation:first").addClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes").removeAttr("disabled"),a("#variable_product_options").trigger("woocommerce_variations_defaults_changed")},do_variation_action:function(){var b,c=a("select.variation_actions").val(),f={},g=0;switch(c){case"add_variation":return void d.add_variation();case"link_all_variations":return void d.link_all_variations();case"delete_all":window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations)&&window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning)&&(f.allowed=!0,g=-1*parseInt(a("#variable_product_options").find(".woocommerce_variations").attr("data-total"),10));break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":b=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),null!=b&&(b.indexOf("%")>=0?f.value=accounting.unformat(b.replace(/\%/,""),woocommerce_admin.mon_decimal_point)+"%":f.value=accounting.unformat(b,woocommerce_admin.mon_decimal_point));break;case"variable_regular_price":case"variable_sale_price":case"variable_stock":case"variable_weight":case"variable_length":case"variable_width":case"variable_height":case"variable_download_limit":case"variable_download_expiry":b=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),null!=b&&(f.value=b);break;case"variable_sale_schedule":f.date_from=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),f.date_to=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),null===f.date_from&&(f.date_from=!1),null===f.date_to&&(f.date_to=!1);break;default:a("select.variation_actions").trigger(c),f=a("select.variation_actions").triggerHandler(c+"_ajax_data",f)}"delete_all"===c&&f.allowed?a("#variable_product_options").find(".variation-needs-update").removeClass("variation-needs-update"):d.check_for_changes(),d.block(),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:{action:"woocommerce_bulk_edit_variations",security:woocommerce_admin_meta_boxes_variations.bulk_edit_variations_nonce,product_id:woocommerce_admin_meta_boxes_variations.post_id,product_type:a("#product-type").val(),bulk_action:c,data:f},type:"POST",success:function(){e.go_to_page(1,g)}})}},e={init:function(){a(document.body).on("woocommerce_variations_added",this.update_single_quantity).on("change",".variations-pagenav .page-selector",this.page_selector).on("click",".variations-pagenav .first-page",this.first_page).on("click",".variations-pagenav .prev-page",this.prev_page).on("click",".variations-pagenav .next-page",this.next_page).on("click",".variations-pagenav .last-page",this.last_page)},update_variations_count:function(b){var c=a("#variable_product_options").find(".woocommerce_variations"),d=parseInt(c.attr("data-total"),10)+b,e=a(".variations-pagenav .displaying-num");return c.attr("data-total",d),1===d?e.text(woocommerce_admin_meta_boxes_variations.i18n_variation_count_single.replace("%qty%",d)):e.text(woocommerce_admin_meta_boxes_variations.i18n_variation_count_plural.replace("%qty%",d)),d},update_single_quantity:function(b,c){if(1===c){var d=a(".variations-pagenav");e.update_variations_count(c),d.is(":hidden")&&(a("option, optgroup",".variation_actions").show(),a(".variation_actions").val("add_variation"),a("#variable_product_options").find(".toolbar").show(),d.show(),a(".pagination-links",d).hide())}},set_paginav:function(b){var c=a("#variable_product_options").find(".woocommerce_variations"),d=e.update_variations_count(b),f=a("#variable_product_options").find(".toolbar"),g=a(".variation_actions"),h=a(".variations-pagenav"),i=a(".pagination-links",h),j=Math.ceil(d/woocommerce_admin_meta_boxes_variations.variations_per_page),k="";c.attr("data-total_pages",j),a(".total-pages",h).text(j);for(var l=1;j>=l;l++)k+='";a(".page-selector",h).empty().html(k),0===d?(f.not(".toolbar-top, .toolbar-buttons").hide(),h.hide(),a("option, optgroup",g).hide(),a(".variation_actions").val("add_variation"),a('option[data-global="true"]',g).show()):(f.show(),h.show(),a("option, optgroup",g).show(),a(".variation_actions").val("add_variation"),1===j?i.hide():i.show())},check_is_enabled:function(b){return!a(b).hasClass("disabled")},change_classes:function(b,c){var d=a(".variations-pagenav .first-page"),e=a(".variations-pagenav .prev-page"),f=a(".variations-pagenav .next-page"),g=a(".variations-pagenav .last-page");1===b?(d.addClass("disabled"),e.addClass("disabled")):(d.removeClass("disabled"),e.removeClass("disabled")),c===b?(f.addClass("disabled"),g.addClass("disabled")):(f.removeClass("disabled"),g.removeClass("disabled"))},set_page:function(b){a(".variations-pagenav .page-selector").val(b).first().change()},go_to_page:function(a,b){a=a||1,b=b||0,e.set_paginav(b),e.set_page(a)},page_selector:function(){var b=parseInt(a(this).val(),10),c=a("#variable_product_options").find(".woocommerce_variations");a(".variations-pagenav .page-selector").val(b),d.check_for_changes(),e.change_classes(b,parseInt(c.attr("data-total_pages"),10)),d.load_variations(b)},first_page:function(){return e.check_is_enabled(this)&&e.set_page(1),!1},prev_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options").find(".woocommerce_variations"),c=parseInt(b.attr("data-page"),10)-1,d=c>0?c:1;e.set_page(d)}return!1},next_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options").find(".woocommerce_variations"),c=parseInt(b.attr("data-total_pages"),10),d=parseInt(b.attr("data-page"),10)+1,f=c>=d?d:c;e.set_page(f)}return!1},last_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options").find(".woocommerce_variations").attr("data-total_pages");e.set_page(b)}return!1}};b.init(),c.init(),d.init(),e.init()}); \ No newline at end of file +jQuery(function(a){var b={init:function(){a("#variable_product_options").on("change","input.variable_is_downloadable",this.variable_is_downloadable).on("change","input.variable_is_virtual",this.variable_is_virtual).on("change","input.variable_manage_stock",this.variable_manage_stock).on("click","button.notice-dismiss",this.notice_dismiss).on("click","h3 .sort",this.set_menu_order).on("reload",this.reload),a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock").change(),a("#woocommerce-product-data").on("woocommerce_variations_loaded",this.variations_loaded),a(document.body).on("woocommerce_variations_added",this.variation_added)},reload:function(){d.load_variations(1)},variable_is_downloadable:function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_downloadable").show()},variable_is_virtual:function(){a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").show(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".hide_if_variation_virtual").hide()},variable_manage_stock:function(){a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").hide(),a(this).is(":checked")&&a(this).closest(".woocommerce_variation").find(".show_if_variation_manage_stock").show()},notice_dismiss:function(){a(this).closest("div.notice").remove()},variations_loaded:function(c,d){d=d||!1;var e=a("#woocommerce-product-data");d||(a("input.variable_is_downloadable, input.variable_is_virtual, input.variable_manage_stock",e).change(),a(".woocommerce_variation",e).each(function(b,c){var d=a(c),e=a(".sale_price_dates_from",d).val(),f=a(".sale_price_dates_to",d).val();""===e&&""===f||a("a.sale_schedule",d).click()}),a(".woocommerce_variations .variation-needs-update",e).removeClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes",e).attr("disabled","disabled")),a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".woocommerce_variations .tips, .woocommerce_variations .help_tip, .woocommerce_variations .woocommerce-help-tip",e).tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}),a(".sale_price_dates_fields",e).each(function(){var b=a(this).find("input").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,onSelect:function(c){var d=a(this).is(".sale_price_dates_from")?"minDate":"maxDate",e=a(this).data("datepicker"),f=a.datepicker.parseDate(e.settings.dateFormat||a.datepicker._defaults.dateFormat,c,e.settings);b.not(this).datepicker("option",d,f),a(this).change()}})}),a(".woocommerce_variations",e).sortable({items:".woocommerce_variation",cursor:"move",axis:"y",handle:".sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,stop:function(){b.variation_row_indexes()}}),a(document.body).trigger("wc-enhanced-select-init")},variation_added:function(a,c){1===c&&b.variations_loaded(null,!0)},set_menu_order:function(b){b.preventDefault();var c=a(this).closest(".woocommerce_variation").find(".variation_menu_order"),e=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_menu_order,c.val());null!=e&&(c.val(parseInt(e,10)).change(),d.save_variations())},variation_row_indexes:function(){var b=a("#variable_product_options").find(".woocommerce_variations"),c=parseInt(b.attr("data-page"),10),d=parseInt((c-1)*woocommerce_admin_meta_boxes_variations.variations_per_page,10);a(".woocommerce_variations .woocommerce_variation").each(function(b,c){a(".variation_menu_order",c).val(parseInt(a(c).index(".woocommerce_variations .woocommerce_variation"),10)+1+d).change()})}},c={variable_image_frame:null,setting_variation_image_id:null,setting_variation_image:null,wp_media_post_id:wp.media.model.settings.post.id,init:function(){a("#variable_product_options").on("click",".upload_image_button",this.add_image),a("a.add_media").on("click",this.restore_wp_media_post_id)},add_image:function(b){var d=a(this),e=d.attr("rel"),f=d.closest(".upload_image");if(c.setting_variation_image=f,c.setting_variation_image_id=e,b.preventDefault(),d.is(".remove"))a(".upload_image_id",c.setting_variation_image).val("").change(),c.setting_variation_image.find("img").eq(0).attr("src",woocommerce_admin_meta_boxes_variations.woocommerce_placeholder_img_src),c.setting_variation_image.find(".upload_image_button").removeClass("remove");else{if(c.variable_image_frame)return c.variable_image_frame.uploader.uploader.param("post_id",c.setting_variation_image_id),void c.variable_image_frame.open();wp.media.model.settings.post.id=c.setting_variation_image_id,c.variable_image_frame=wp.media.frames.variable_image=wp.media({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,button:{text:woocommerce_admin_meta_boxes_variations.i18n_set_image},states:[new wp.media.controller.Library({title:woocommerce_admin_meta_boxes_variations.i18n_choose_image,filterable:"all"})]}),c.variable_image_frame.on("select",function(){var b=c.variable_image_frame.state().get("selection").first().toJSON(),d=b.sizes&&b.sizes.thumbnail?b.sizes.thumbnail.url:b.url;a(".upload_image_id",c.setting_variation_image).val(b.id).change(),c.setting_variation_image.find(".upload_image_button").addClass("remove"),c.setting_variation_image.find("img").eq(0).attr("src",d),wp.media.model.settings.post.id=c.wp_media_post_id}),c.variable_image_frame.open()}},restore_wp_media_post_id:function(){wp.media.model.settings.post.id=c.wp_media_post_id}},d={init:function(){a("li.variations_tab a").on("click",this.initial_load),a("#variable_product_options").on("click","button.save-variation-changes",this.save_variations).on("click","button.cancel-variation-changes",this.cancel_variations).on("click",".remove_variation",this.remove_variation),a(document.body).on("change","#variable_product_options .woocommerce_variations :input",this.input_changed).on("change",".variations-defaults select",this.defaults_changed),a("form#post").on("submit",this.save_on_submit),a(".wc-metaboxes-wrapper").on("click","a.do_variation_action",this.do_variation_action)},check_for_changes:function(){var b=a("#variable_product_options").find(".woocommerce_variations .variation-needs-update");if(00?(c.push(b),f.variation_ids=c,f.security=woocommerce_admin_meta_boxes_variations.delete_variations_nonce,a.post(woocommerce_admin_meta_boxes_variations.ajax_url,f,function(){var b=a("#variable_product_options").find(".woocommerce_variations"),c=parseInt(b.attr("data-page"),10),d=Math.ceil((parseInt(b.attr("data-total"),10)-1)/woocommerce_admin_meta_boxes_variations.variations_per_page),f=1;a("#woocommerce-product-data").trigger("woocommerce_variations_removed"),c===d||d>=c?f=c:c>d&&0!==d&&(f=d),e.go_to_page(f,-1)})):d.unblock()}return!1},link_all_variations:function(){if(d.check_for_changes(),window.confirm(woocommerce_admin_meta_boxes_variations.i18n_link_all_variations)){d.block();var b={action:"woocommerce_link_all_variations",post_id:woocommerce_admin_meta_boxes_variations.post_id,security:woocommerce_admin_meta_boxes_variations.link_variation_nonce};a.post(woocommerce_admin_meta_boxes_variations.ajax_url,b,function(b){var c=parseInt(b,10);1===c?window.alert(c+" "+woocommerce_admin_meta_boxes_variations.i18n_variation_added):0===c||c>1?window.alert(c+" "+woocommerce_admin_meta_boxes_variations.i18n_variations_added):window.alert(woocommerce_admin_meta_boxes_variations.i18n_no_variations_added),c>0?(e.go_to_page(1,c),a("#variable_product_options").trigger("woocommerce_variations_added",c)):d.unblock()})}return!1},input_changed:function(){a(this).closest(".woocommerce_variation").addClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes").removeAttr("disabled"),a("#variable_product_options").trigger("woocommerce_variations_input_changed")},defaults_changed:function(){a(this).closest("#variable_product_options").find(".woocommerce_variation:first").addClass("variation-needs-update"),a("button.cancel-variation-changes, button.save-variation-changes").removeAttr("disabled"),a("#variable_product_options").trigger("woocommerce_variations_defaults_changed")},do_variation_action:function(){var b,c=a("select.variation_actions").val(),f={},g=0;switch(c){case"add_variation":return void d.add_variation();case"link_all_variations":return void d.link_all_variations();case"delete_all":window.confirm(woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations)&&window.confirm(woocommerce_admin_meta_boxes_variations.i18n_last_warning)&&(f.allowed=!0,g=-1*parseInt(a("#variable_product_options").find(".woocommerce_variations").attr("data-total"),10));break;case"variable_regular_price_increase":case"variable_regular_price_decrease":case"variable_sale_price_increase":case"variable_sale_price_decrease":b=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value_fixed_or_percent),null!=b&&(b.indexOf("%")>=0?f.value=accounting.unformat(b.replace(/\%/,""),woocommerce_admin.mon_decimal_point)+"%":f.value=accounting.unformat(b,woocommerce_admin.mon_decimal_point));break;case"variable_regular_price":case"variable_sale_price":case"variable_stock":case"variable_weight":case"variable_length":case"variable_width":case"variable_height":case"variable_download_limit":case"variable_download_expiry":b=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_enter_a_value),null!=b&&(f.value=b);break;case"variable_sale_schedule":f.date_from=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_start),f.date_to=window.prompt(woocommerce_admin_meta_boxes_variations.i18n_scheduled_sale_end),null===f.date_from&&(f.date_from=!1),null===f.date_to&&(f.date_to=!1);break;default:a("select.variation_actions").trigger(c),f=a("select.variation_actions").triggerHandler(c+"_ajax_data",f)}"delete_all"===c&&f.allowed?a("#variable_product_options").find(".variation-needs-update").removeClass("variation-needs-update"):d.check_for_changes(),d.block(),a.ajax({url:woocommerce_admin_meta_boxes_variations.ajax_url,data:{action:"woocommerce_bulk_edit_variations",security:woocommerce_admin_meta_boxes_variations.bulk_edit_variations_nonce,product_id:woocommerce_admin_meta_boxes_variations.post_id,product_type:a("#product-type").val(),bulk_action:c,data:f},type:"POST",success:function(){e.go_to_page(1,g)}})}},e={init:function(){a(document.body).on("woocommerce_variations_added",this.update_single_quantity).on("change",".variations-pagenav .page-selector",this.page_selector).on("click",".variations-pagenav .first-page",this.first_page).on("click",".variations-pagenav .prev-page",this.prev_page).on("click",".variations-pagenav .next-page",this.next_page).on("click",".variations-pagenav .last-page",this.last_page)},update_variations_count:function(b){var c=a("#variable_product_options").find(".woocommerce_variations"),d=parseInt(c.attr("data-total"),10)+b,e=a(".variations-pagenav .displaying-num");return c.attr("data-total",d),1===d?e.text(woocommerce_admin_meta_boxes_variations.i18n_variation_count_single.replace("%qty%",d)):e.text(woocommerce_admin_meta_boxes_variations.i18n_variation_count_plural.replace("%qty%",d)),d},update_single_quantity:function(b,c){if(1===c){var d=a(".variations-pagenav");e.update_variations_count(c),d.is(":hidden")&&(a("option, optgroup",".variation_actions").show(),a(".variation_actions").val("add_variation"),a("#variable_product_options").find(".toolbar").show(),d.show(),a(".pagination-links",d).hide())}},set_paginav:function(b){var c=a("#variable_product_options").find(".woocommerce_variations"),d=e.update_variations_count(b),f=a("#variable_product_options").find(".toolbar"),g=a(".variation_actions"),h=a(".variations-pagenav"),i=a(".pagination-links",h),j=Math.ceil(d/woocommerce_admin_meta_boxes_variations.variations_per_page),k="";c.attr("data-total_pages",j),a(".total-pages",h).text(j);for(var l=1;j>=l;l++)k+='";a(".page-selector",h).empty().html(k),0===d?(f.not(".toolbar-top, .toolbar-buttons").hide(),h.hide(),a("option, optgroup",g).hide(),a(".variation_actions").val("add_variation"),a('option[data-global="true"]',g).show()):(f.show(),h.show(),a("option, optgroup",g).show(),a(".variation_actions").val("add_variation"),1===j?i.hide():i.show())},check_is_enabled:function(b){return!a(b).hasClass("disabled")},change_classes:function(b,c){var d=a(".variations-pagenav .first-page"),e=a(".variations-pagenav .prev-page"),f=a(".variations-pagenav .next-page"),g=a(".variations-pagenav .last-page");1===b?(d.addClass("disabled"),e.addClass("disabled")):(d.removeClass("disabled"),e.removeClass("disabled")),c===b?(f.addClass("disabled"),g.addClass("disabled")):(f.removeClass("disabled"),g.removeClass("disabled"))},set_page:function(b){a(".variations-pagenav .page-selector").val(b).first().change()},go_to_page:function(a,b){a=a||1,b=b||0,e.set_paginav(b),e.set_page(a)},page_selector:function(){var b=parseInt(a(this).val(),10),c=a("#variable_product_options").find(".woocommerce_variations");a(".variations-pagenav .page-selector").val(b),d.check_for_changes(),e.change_classes(b,parseInt(c.attr("data-total_pages"),10)),d.load_variations(b)},first_page:function(){return e.check_is_enabled(this)&&e.set_page(1),!1},prev_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options").find(".woocommerce_variations"),c=parseInt(b.attr("data-page"),10)-1,d=c>0?c:1;e.set_page(d)}return!1},next_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options").find(".woocommerce_variations"),c=parseInt(b.attr("data-total_pages"),10),d=parseInt(b.attr("data-page"),10)+1,f=c>=d?d:c;e.set_page(f)}return!1},last_page:function(){if(e.check_is_enabled(this)){var b=a("#variable_product_options").find(".woocommerce_variations").attr("data-total_pages");e.set_page(b)}return!1}};b.init(),c.init(),d.init(),e.init()}); \ No newline at end of file diff --git a/assets/js/admin/meta-boxes-product.js b/assets/js/admin/meta-boxes-product.js index 2d0c31b3a40..e02f910ccb8 100644 --- a/assets/js/admin/meta-boxes-product.js +++ b/assets/js/admin/meta-boxes-product.js @@ -126,17 +126,17 @@ jQuery( function( $ ) { 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(); + var is_virtual = $( 'input#_virtual:checked' ).length; + var is_downloadable = $( 'input#_downloadable:checked' ).length; // Hide/Show all with rules var hide_classes = '.hide_if_downloadable, .hide_if_virtual'; - var show_classes = '.show_if_downloadable, .show_if_virtual, .show_if_external'; + var show_classes = '.show_if_downloadable, .show_if_virtual'; $.each( woocommerce_admin_meta_boxes.product_types, function( index, value ) { hide_classes = hide_classes + ', .hide_if_' + value; show_classes = show_classes + ', .show_if_' + value; - } ); + }); $( hide_classes ).show(); $( show_classes ).hide(); @@ -268,9 +268,10 @@ jQuery( function( $ ) { // Add rows $( 'button.add_attribute' ).on( 'click', function() { - var size = $( '.product_attributes .woocommerce_attribute' ).size(); + var size = $( '.product_attributes .woocommerce_attribute' ).length; var attribute = $( 'select.attribute_taxonomy' ).val(); - var $wrapper = $( this ).closest( '#product_attributes' ).find( '.product_attributes' ); + var $wrapper = $( this ).closest( '#product_attributes' ); + var $attributes = $wrapper.find( '.product_attributes' ); var product_type = $( 'select#product-type' ).val(); var data = { action: 'woocommerce_add_attribute', @@ -288,10 +289,10 @@ jQuery( function( $ ) { }); $.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) { - $wrapper.append( response ); + $attributes.append( response ); if ( product_type !== 'variable' ) { - $wrapper.find( '.enable_variation' ).hide(); + $attributes.find( '.enable_variation' ).hide(); } $( document.body ).trigger( 'wc-enhanced-select-init' ); @@ -485,7 +486,7 @@ jQuery( function( $ ) { } }); - file_path_field.val( file_path ); + file_path_field.val( file_path ).change(); }); // Set post to 0 and set our custom type diff --git a/assets/js/admin/meta-boxes-product.min.js b/assets/js/admin/meta-boxes-product.min.js index 61461ee6d24..ad859216672 100644 --- a/assets/js/admin/meta-boxes-product.min.js +++ b/assets/js/admin/meta-boxes-product.min.js @@ -1 +1 @@ -jQuery(function(a){function b(){var b=a("select#product-type").val(),c=a("input#_virtual:checked").size(),d=a("input#_downloadable:checked").size(),e=".hide_if_downloadable, .hide_if_virtual",f=".show_if_downloadable, .show_if_virtual, .show_if_external";a.each(woocommerce_admin_meta_boxes.product_types,function(a,b){e=e+", .hide_if_"+b,f=f+", .show_if_"+b}),a(e).show(),a(f).hide(),d&&a(".show_if_downloadable").show(),c&&a(".show_if_virtual").show(),a(".show_if_"+b).show(),d&&a(".hide_if_downloadable").hide(),c&&a(".hide_if_virtual").hide(),a(".hide_if_"+b).hide(),a("input#_manage_stock").change()}function c(){a(".product_attributes .woocommerce_attribute").each(function(b,c){a(".attribute_position",c).val(parseInt(a(c).index(".product_attributes .woocommerce_attribute"),10))})}a(function(){a('[id$="-all"] > ul.categorychecklist').each(function(){var b=a(this),c=b.find(":checked").first();if(c.length){var d=b.find("input").position().top,e=c.position().top;b.closest(".tabs-panel").scrollTop(e-d+5)}})}),a("#upsell_product_data").bind("keypress",function(a){return 13===a.keyCode?!1:void 0}),a(".type_box").appendTo("#woocommerce-product-data .hndle span"),a(function(){a("#woocommerce-product-data").find(".hndle").unbind("click.postboxes"),jQuery("#woocommerce-product-data").on("click",".hndle",function(b){a(b.target).filter("input, option, label, select").length||a("#woocommerce-product-data").toggleClass("closed")})}),a("#catalog-visibility").find(".edit-catalog-visibility").click(function(){return a("#catalog-visibility-select").is(":hidden")&&(a("#catalog-visibility-select").slideDown("fast"),a(this).hide()),!1}),a("#catalog-visibility").find(".save-post-visibility").click(function(){a("#catalog-visibility-select").slideUp("fast"),a("#catalog-visibility").find(".edit-catalog-visibility").show();var b=a("input[name=_visibility]:checked").attr("data-label");return a("input[name=_featured]").is(":checked")&&(b=b+", "+woocommerce_admin_meta_boxes.featured_label,a("input[name=_featured]").attr("checked","checked")),a("#catalog-visibility-display").text(b),!1}),a("#catalog-visibility").find(".cancel-post-visibility").click(function(){a("#catalog-visibility-select").slideUp("fast"),a("#catalog-visibility").find(".edit-catalog-visibility").show();var b=a("#current_visibility").val(),c=a("#current_featured").val();a("input[name=_visibility]").removeAttr("checked"),a("input[name=_visibility][value="+b+"]").attr("checked","checked");var d=a("input[name=_visibility]:checked").attr("data-label");return"yes"===c?(d=d+", "+woocommerce_admin_meta_boxes.featured_label,a("input[name=_featured]").attr("checked","checked")):a("input[name=_featured]").removeAttr("checked"),a("#catalog-visibility-display").text(d),!1}),a("select#product-type").change(function(){var c=a(this).val();"variable"===c?(a("input#_manage_stock").change(),a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")):"grouped"===c?(a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")):"external"===c&&(a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")),b(),a("ul.wc-tabs li:visible").eq(0).find("a").click(),a(document.body).trigger("woocommerce-product-type-change",c,a(this))}).change(),a(document.body).on("woocommerce-product-type-change",function(b,c){"variable"!==c&&0d?-1:d>e?1:0}),a(d).each(function(b,c){a(".product_attributes").append(c)}),a(".product_attributes .woocommerce_attribute").each(function(b,c){"none"!==a(c).css("display")&&a(c).is(".taxonomy")&&a("select.attribute_taxonomy").find('option[value="'+a(c).data("taxonomy")+'"]').attr("disabled","disabled")}),a("button.add_attribute").on("click",function(){var b=a(".product_attributes .woocommerce_attribute").size(),d=a("select.attribute_taxonomy").val(),e=a(this).closest("#product_attributes").find(".product_attributes"),f=a("select#product-type").val(),g={action:"woocommerce_add_attribute",taxonomy:d,i:b,security:woocommerce_admin_meta_boxes.add_attribute_nonce};return e.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.post(woocommerce_admin_meta_boxes.ajax_url,g,function(b){e.append(b),"variable"!==f&&e.find(".enable_variation").hide(),a(document.body).trigger("wc-enhanced-select-init"),c(),e.unblock(),a(document.body).trigger("woocommerce_added_attribute")}),d&&(a("select.attribute_taxonomy").find('option[value="'+d+'"]').attr("disabled","disabled"),a("select.attribute_taxonomy").val("")),!1}),a(".product_attributes").on("blur","input.attribute_name",function(){a(this).closest(".woocommerce_attribute").find("strong.attribute_name").text(a(this).val())}),a(".product_attributes").on("click","button.select_all_attributes",function(){return a(this).closest("td").find("select option").attr("selected","selected"),a(this).closest("td").find("select").change(),!1}),a(".product_attributes").on("click","button.select_no_attributes",function(){return a(this).closest("td").find("select option").removeAttr("selected"),a(this).closest("td").find("select").change(),!1}),a(".product_attributes").on("click",".remove_row",function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_attribute)){var b=a(this).parent().parent();b.is(".taxonomy")?(b.find("select, input[type=text]").val(""),b.hide(),a("select.attribute_taxonomy").find('option[value="'+b.data("taxonomy")+'"]').removeAttr("disabled")):(b.find("select, input[type=text]").val(""),b.hide(),c())}return!1}),a(".product_attributes").sortable({items:".woocommerce_attribute",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style"),c()}}),a(".product_attributes").on("click","button.add_new_attribute",function(){a(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b=a(this).closest(".woocommerce_attribute"),c=b.data("taxonomy"),d=window.prompt(woocommerce_admin_meta_boxes.new_attribute_prompt);if(d){var e={action:"woocommerce_add_new_attribute",taxonomy:c,term:d,security:woocommerce_admin_meta_boxes.add_attribute_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,e,function(c){c.error?window.alert(c.error):c.slug&&(b.find("select.attribute_values").append('"),b.find("select.attribute_values").change()),a(".product_attributes").unblock()})}else a(".product_attributes").unblock();return!1}),a(".save_attributes").on("click",function(){a("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b={post_id:woocommerce_admin_meta_boxes.post_id,data:a(".product_attributes").find("input, select, textarea").serialize(),action:"woocommerce_save_attributes",security:woocommerce_admin_meta_boxes.save_attributes_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(){var b=window.location.toString();b=b.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&"),a("#variable_product_options").load(b+" #variable_product_options_inner",function(){a("#variable_product_options").trigger("reload")})})});var e,f;jQuery(document.body).on("click",".upload_file_button",function(b){var c=a(this);if(f=c.closest("tr").find("td.file_url input"),b.preventDefault(),e)return void e.open();var d=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:c.data("choose"),priority:20,filterable:"uploaded"})];e=wp.media.frames.downloadable_file=wp.media({title:c.data("choose"),library:{type:""},button:{text:c.data("update")},multiple:!0,states:d}),e.on("select",function(){var a="",b=e.state().get("selection");b.map(function(b){b=b.toJSON(),b.url&&(a=b.url)}),f.val(a)}),e.on("ready",function(){e.uploader.options.uploader.params={type:"downloadable_product"}}),e.open()}),jQuery(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65});var g,h=a("#product_image_gallery"),i=a("#product_images_container").find("ul.product_images");jQuery(".add_product_images").on("click","a",function(b){var c=a(this);return b.preventDefault(),g?void g.open():(g=wp.media.frames.product_gallery=wp.media({title:c.data("choose"),button:{text:c.data("update")},states:[new wp.media.controller.Library({title:c.data("choose"),filterable:"all",multiple:!0})]}),g.on("select",function(){var a=g.state().get("selection"),b=h.val();a.map(function(a){if(a=a.toJSON(),a.id){b=b?b+","+a.id:a.id;var d=a.sizes&&a.sizes.thumbnail?a.sizes.thumbnail.url:a.url;i.append('
  • ")}}),h.val(b)}),void g.open())}),i.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")},update:function(){var b="";a("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var a=jQuery(this).attr("data-attachment_id");b=b+a+","}),h.val(b)}}),a("#product_images_container").on("click","a.delete",function(){a(this).closest("li.image").remove();var b="";return a("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var a=jQuery(this).attr("data-attachment_id");b=b+a+","}),h.val(b),a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),!1})}); \ No newline at end of file +jQuery(function(a){function b(){var b=a("select#product-type").val(),c=a("input#_virtual:checked").length,d=a("input#_downloadable:checked").length,e=".hide_if_downloadable, .hide_if_virtual",f=".show_if_downloadable, .show_if_virtual";a.each(woocommerce_admin_meta_boxes.product_types,function(a,b){e=e+", .hide_if_"+b,f=f+", .show_if_"+b}),a(e).show(),a(f).hide(),d&&a(".show_if_downloadable").show(),c&&a(".show_if_virtual").show(),a(".show_if_"+b).show(),d&&a(".hide_if_downloadable").hide(),c&&a(".hide_if_virtual").hide(),a(".hide_if_"+b).hide(),a("input#_manage_stock").change()}function c(){a(".product_attributes .woocommerce_attribute").each(function(b,c){a(".attribute_position",c).val(parseInt(a(c).index(".product_attributes .woocommerce_attribute"),10))})}a(function(){a('[id$="-all"] > ul.categorychecklist').each(function(){var b=a(this),c=b.find(":checked").first();if(c.length){var d=b.find("input").position().top,e=c.position().top;b.closest(".tabs-panel").scrollTop(e-d+5)}})}),a("#upsell_product_data").bind("keypress",function(a){return 13===a.keyCode?!1:void 0}),a(".type_box").appendTo("#woocommerce-product-data .hndle span"),a(function(){a("#woocommerce-product-data").find(".hndle").unbind("click.postboxes"),jQuery("#woocommerce-product-data").on("click",".hndle",function(b){a(b.target).filter("input, option, label, select").length||a("#woocommerce-product-data").toggleClass("closed")})}),a("#catalog-visibility").find(".edit-catalog-visibility").click(function(){return a("#catalog-visibility-select").is(":hidden")&&(a("#catalog-visibility-select").slideDown("fast"),a(this).hide()),!1}),a("#catalog-visibility").find(".save-post-visibility").click(function(){a("#catalog-visibility-select").slideUp("fast"),a("#catalog-visibility").find(".edit-catalog-visibility").show();var b=a("input[name=_visibility]:checked").attr("data-label");return a("input[name=_featured]").is(":checked")&&(b=b+", "+woocommerce_admin_meta_boxes.featured_label,a("input[name=_featured]").attr("checked","checked")),a("#catalog-visibility-display").text(b),!1}),a("#catalog-visibility").find(".cancel-post-visibility").click(function(){a("#catalog-visibility-select").slideUp("fast"),a("#catalog-visibility").find(".edit-catalog-visibility").show();var b=a("#current_visibility").val(),c=a("#current_featured").val();a("input[name=_visibility]").removeAttr("checked"),a("input[name=_visibility][value="+b+"]").attr("checked","checked");var d=a("input[name=_visibility]:checked").attr("data-label");return"yes"===c?(d=d+", "+woocommerce_admin_meta_boxes.featured_label,a("input[name=_featured]").attr("checked","checked")):a("input[name=_featured]").removeAttr("checked"),a("#catalog-visibility-display").text(d),!1}),a("select#product-type").change(function(){var c=a(this).val();"variable"===c?(a("input#_manage_stock").change(),a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")):"grouped"===c?(a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")):"external"===c&&(a("input#_downloadable").prop("checked",!1),a("input#_virtual").removeAttr("checked")),b(),a("ul.wc-tabs li:visible").eq(0).find("a").click(),a(document.body).trigger("woocommerce-product-type-change",c,a(this))}).change(),a(document.body).on("woocommerce-product-type-change",function(b,c){"variable"!==c&&0d?-1:d>e?1:0}),a(d).each(function(b,c){a(".product_attributes").append(c)}),a(".product_attributes .woocommerce_attribute").each(function(b,c){"none"!==a(c).css("display")&&a(c).is(".taxonomy")&&a("select.attribute_taxonomy").find('option[value="'+a(c).data("taxonomy")+'"]').attr("disabled","disabled")}),a("button.add_attribute").on("click",function(){var b=a(".product_attributes .woocommerce_attribute").length,d=a("select.attribute_taxonomy").val(),e=a(this).closest("#product_attributes"),f=e.find(".product_attributes"),g=a("select#product-type").val(),h={action:"woocommerce_add_attribute",taxonomy:d,i:b,security:woocommerce_admin_meta_boxes.add_attribute_nonce};return e.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.post(woocommerce_admin_meta_boxes.ajax_url,h,function(b){f.append(b),"variable"!==g&&f.find(".enable_variation").hide(),a(document.body).trigger("wc-enhanced-select-init"),c(),e.unblock(),a(document.body).trigger("woocommerce_added_attribute")}),d&&(a("select.attribute_taxonomy").find('option[value="'+d+'"]').attr("disabled","disabled"),a("select.attribute_taxonomy").val("")),!1}),a(".product_attributes").on("blur","input.attribute_name",function(){a(this).closest(".woocommerce_attribute").find("strong.attribute_name").text(a(this).val())}),a(".product_attributes").on("click","button.select_all_attributes",function(){return a(this).closest("td").find("select option").attr("selected","selected"),a(this).closest("td").find("select").change(),!1}),a(".product_attributes").on("click","button.select_no_attributes",function(){return a(this).closest("td").find("select option").removeAttr("selected"),a(this).closest("td").find("select").change(),!1}),a(".product_attributes").on("click",".remove_row",function(){if(window.confirm(woocommerce_admin_meta_boxes.remove_attribute)){var b=a(this).parent().parent();b.is(".taxonomy")?(b.find("select, input[type=text]").val(""),b.hide(),a("select.attribute_taxonomy").find('option[value="'+b.data("taxonomy")+'"]').removeAttr("disabled")):(b.find("select, input[type=text]").val(""),b.hide(),c())}return!1}),a(".product_attributes").sortable({items:".woocommerce_attribute",cursor:"move",axis:"y",handle:"h3",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style"),c()}}),a(".product_attributes").on("click","button.add_new_attribute",function(){a(".product_attributes").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b=a(this).closest(".woocommerce_attribute"),c=b.data("taxonomy"),d=window.prompt(woocommerce_admin_meta_boxes.new_attribute_prompt);if(d){var e={action:"woocommerce_add_new_attribute",taxonomy:c,term:d,security:woocommerce_admin_meta_boxes.add_attribute_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,e,function(c){c.error?window.alert(c.error):c.slug&&(b.find("select.attribute_values").append('"),b.find("select.attribute_values").change()),a(".product_attributes").unblock()})}else a(".product_attributes").unblock();return!1}),a(".save_attributes").on("click",function(){a("#woocommerce-product-data").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var b={post_id:woocommerce_admin_meta_boxes.post_id,data:a(".product_attributes").find("input, select, textarea").serialize(),action:"woocommerce_save_attributes",security:woocommerce_admin_meta_boxes.save_attributes_nonce};a.post(woocommerce_admin_meta_boxes.ajax_url,b,function(){var b=window.location.toString();b=b.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&"),a("#variable_product_options").load(b+" #variable_product_options_inner",function(){a("#variable_product_options").trigger("reload")})})});var e,f;jQuery(document.body).on("click",".upload_file_button",function(b){var c=a(this);if(f=c.closest("tr").find("td.file_url input"),b.preventDefault(),e)return void e.open();var d=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:c.data("choose"),priority:20,filterable:"uploaded"})];e=wp.media.frames.downloadable_file=wp.media({title:c.data("choose"),library:{type:""},button:{text:c.data("update")},multiple:!0,states:d}),e.on("select",function(){var a="",b=e.state().get("selection");b.map(function(b){b=b.toJSON(),b.url&&(a=b.url)}),f.val(a).change()}),e.on("ready",function(){e.uploader.options.uploader.params={type:"downloadable_product"}}),e.open()}),jQuery(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65});var g,h=a("#product_image_gallery"),i=a("#product_images_container").find("ul.product_images");jQuery(".add_product_images").on("click","a",function(b){var c=a(this);return b.preventDefault(),g?void g.open():(g=wp.media.frames.product_gallery=wp.media({title:c.data("choose"),button:{text:c.data("update")},states:[new wp.media.controller.Library({title:c.data("choose"),filterable:"all",multiple:!0})]}),g.on("select",function(){var a=g.state().get("selection"),b=h.val();a.map(function(a){if(a=a.toJSON(),a.id){b=b?b+","+a.id:a.id;var d=a.sizes&&a.sizes.thumbnail?a.sizes.thumbnail.url:a.url;i.append('
  • ")}}),h.val(b)}),void g.open())}),i.sortable({items:"li.image",cursor:"move",scrollSensitivity:40,forcePlaceholderSize:!0,forceHelperSize:!1,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")},update:function(){var b="";a("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var a=jQuery(this).attr("data-attachment_id");b=b+a+","}),h.val(b)}}),a("#product_images_container").on("click","a.delete",function(){a(this).closest("li.image").remove();var b="";return a("#product_images_container").find("ul li.image").css("cursor","default").each(function(){var a=jQuery(this).attr("data-attachment_id");b=b+a+","}),h.val(b),a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),!1})}); \ No newline at end of file diff --git a/assets/js/admin/meta-boxes.js b/assets/js/admin/meta-boxes.js index bb5624a5781..39c35e4da06 100644 --- a/assets/js/admin/meta-boxes.js +++ b/assets/js/admin/meta-boxes.js @@ -20,7 +20,7 @@ jQuery( function ( $ ) { var code = event.keyCode || event.which; // Tab key - if ( code === '9' && $( '#woocommerce-coupon-description' ).size() > 0 ) { + if ( code === '9' && $( '#woocommerce-coupon-description' ).length > 0 ) { event.stopPropagation(); $( '#woocommerce-coupon-description' ).focus(); return false; diff --git a/assets/js/admin/meta-boxes.min.js b/assets/js/admin/meta-boxes.min.js index cf4df08995b..2c8b16c9a51 100644 --- a/assets/js/admin/meta-boxes.min.js +++ b/assets/js/admin/meta-boxes.min.js @@ -1 +1 @@ -jQuery(function(a){function b(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})}b(),a("#titlediv").find("#title").keyup(function(b){var c=b.keyCode||b.which;return"9"===c&&a("#woocommerce-coupon-description").size()>0?(b.stopPropagation(),a("#woocommerce-coupon-description").focus(),!1):void 0}),a(".wc-metaboxes-wrapper").on("click",".wc-metabox > h3",function(){a(this).parent(".wc-metabox").toggleClass("closed").toggleClass("open")}),a(document.body).on("wc-init-tabbed-panels",function(){a("ul.wc-tabs").show(),a("ul.wc-tabs a").click(function(b){b.preventDefault();var c=a(this).closest("div.panel-wrap");a("ul.wc-tabs li",c).removeClass("active"),a(this).parent().addClass("active"),a("div.panel",c).hide(),a(a(this).attr("href")).show()}),a("div.panel-wrap").each(function(){a(this).find("ul.wc-tabs li").eq(0).find("a").click()})}).trigger("wc-init-tabbed-panels"),a(document.body).on("wc-init-datepickers",function(){a(".date-picker-field, .date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0})}).trigger("wc-init-datepickers"),a(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(b){a(b.target).filter(":input, option, .sort").length||a(this).next(".wc-metabox-content").stop().slideToggle()}).on("click",".expand_all",function(){return a(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > .wc-metabox-content").show(),!1}).on("click",".close_all",function(){return a(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > .wc-metabox-content").hide(),!1}),a(".wc-metabox.closed").each(function(){a(this).find(".wc-metabox-content").hide()})}); \ No newline at end of file +jQuery(function(a){function b(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})}b(),a("#titlediv").find("#title").keyup(function(b){var c=b.keyCode||b.which;return"9"===c&&a("#woocommerce-coupon-description").length>0?(b.stopPropagation(),a("#woocommerce-coupon-description").focus(),!1):void 0}),a(".wc-metaboxes-wrapper").on("click",".wc-metabox > h3",function(){a(this).parent(".wc-metabox").toggleClass("closed").toggleClass("open")}),a(document.body).on("wc-init-tabbed-panels",function(){a("ul.wc-tabs").show(),a("ul.wc-tabs a").click(function(b){b.preventDefault();var c=a(this).closest("div.panel-wrap");a("ul.wc-tabs li",c).removeClass("active"),a(this).parent().addClass("active"),a("div.panel",c).hide(),a(a(this).attr("href")).show()}),a("div.panel-wrap").each(function(){a(this).find("ul.wc-tabs li").eq(0).find("a").click()})}).trigger("wc-init-tabbed-panels"),a(document.body).on("wc-init-datepickers",function(){a(".date-picker-field, .date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0})}).trigger("wc-init-datepickers"),a(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(b){a(b.target).filter(":input, option, .sort").length||a(this).next(".wc-metabox-content").stop().slideToggle()}).on("click",".expand_all",function(){return a(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > .wc-metabox-content").show(),!1}).on("click",".close_all",function(){return a(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > .wc-metabox-content").hide(),!1}),a(".wc-metabox.closed").each(function(){a(this).find(".wc-metabox-content").hide()})}); \ No newline at end of file diff --git a/assets/js/admin/order-backbone-modal.min.js b/assets/js/admin/order-backbone-modal.min.js deleted file mode 100644 index a3721ff1122..00000000000 --- a/assets/js/admin/order-backbone-modal.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(a,b,c){"use strict";a.fn.WCBackboneModal=function(b){return this.each(function(){new a.WCBackboneModal(a(this),b)})},a.WCBackboneModal=function(b,c){var d=a.extend({},a.WCBackboneModal.defaultOptions,c);d.template&&new a.WCBackboneModal.View({target:d.template,string:d.variable})},a.WCBackboneModal.defaultOptions={template:"",variable:{}},a.WCBackboneModal.View=b.View.extend({tagName:"div",id:"wc-backbone-modal-dialog",_target:void 0,_string:void 0,events:{"click .modal-close":"closeButton","click #btn-ok":"addButton","touchstart #btn-ok":"addButton",keydown:"keyboardActions"},initialize:function(a){this._target=a.target,this._string=a.string,c.bindAll(this,"render"),this.render()},render:function(){var b=wp.template(this._target);this.$el.attr("tabindex","0").append(b(this._string)),a(document.body).css({overflow:"hidden"}).append(this.$el);var c=a(".wc-backbone-modal-content").find("article"),d=c.height()<90?90:c.height(),e=a(window).height()-200;e>400&&(e=400),d>e?c.css({overflow:"auto",height:e+"px"}):c.css({overflow:"visible",height:d>90?"auto":d+"px"}),a(".wc-backbone-modal-content").css({"margin-top":"-"+a(".wc-backbone-modal-content").height()/2+"px","margin-left":"-"+a(".wc-backbone-modal-content").width()/2+"px"}),a(document.body).trigger("wc_backbone_modal_loaded",this._target)},closeButton:function(b){b.preventDefault(),a(document.body).trigger("wc_backbone_modal_before_remove",this._target),this.undelegateEvents(),a(document).off("focusin"),a(document.body).css({overflow:"auto"}),this.remove(),a(document.body).trigger("wc_backbone_modal_removed",this._target)},addButton:function(b){a(document.body).trigger("wc_backbone_modal_response",[this._target,this.getFormData()]),this.closeButton(b)},getFormData:function(){var b={};return a(document.body).trigger("wc_backbone_modal_before_update",this._target),a.each(a("form",this.$el).serializeArray(),function(c,d){b.hasOwnProperty(d.name)?(b[d.name]=a.makeArray(b[d.name]),b[d.name].push(d.value)):b[d.name]=d.value}),b},keyboardActions:function(a){var b=a.keyCode||a.which;13!==b||a.target.tagName&&("input"===a.target.tagName.toLowerCase()||"textarea"===a.target.tagName.toLowerCase())||this.addButton(a),27===b&&this.closeButton(a)}})}(jQuery,Backbone,_); \ No newline at end of file diff --git a/assets/js/admin/quick-edit.js b/assets/js/admin/quick-edit.js index ca1dbfaf630..f5df4259fc2 100644 --- a/assets/js/admin/quick-edit.js +++ b/assets/js/admin/quick-edit.js @@ -1,4 +1,4 @@ -/*global ajaxurl, inlineEditPost, inlineEditL10n */ +/*global ajaxurl, inlineEditPost, inlineEditL10n, woocommerce_admin */ jQuery(function( $ ) { $( '#the-list' ).on( 'click', '.editinline', function() { @@ -28,9 +28,12 @@ jQuery(function( $ ) { tax_class = $wc_inline_data.find( '.tax_class' ).text(), backorders = $wc_inline_data.find( '.backorders' ).text(); + var formatted_regular_price = regular_price.replace('.', woocommerce_admin.mon_decimal_point ), + formatted_sale_price = sale_price.replace('.', woocommerce_admin.mon_decimal_point ); + $( 'input[name="_sku"]', '.inline-edit-row' ).val( sku ); - $( 'input[name="_regular_price"]', '.inline-edit-row' ).val( regular_price ); - $( 'input[name="_sale_price"]', '.inline-edit-row' ).val( sale_price ); + $( 'input[name="_regular_price"]', '.inline-edit-row' ).val( formatted_regular_price ); + $( 'input[name="_sale_price"]', '.inline-edit-row' ).val( formatted_sale_price ); $( 'input[name="_weight"]', '.inline-edit-row' ).val( weight ); $( 'input[name="_length"]', '.inline-edit-row' ).val( length ); $( 'input[name="_width"]', '.inline-edit-row' ).val( width ); @@ -104,7 +107,7 @@ jQuery(function( $ ) { // Autosuggest product tags on bulk edit var tax = 'product_tag'; - $( 'tr.inline-editor textarea[name="tax_input[' + tax + ']"]' ).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma } ); + $( 'tr.inline-editor textarea[name="tax_input[' + tax + ']"]' ).suggest( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma } ); }); $( '#wpbody' ).on( 'change', '#woocommerce-fields-bulk .inline-edit-group .change_to', function() { diff --git a/assets/js/admin/quick-edit.min.js b/assets/js/admin/quick-edit.min.js index 549395d247c..8757867c0cd 100644 --- a/assets/js/admin/quick-edit.min.js +++ b/assets/js/admin/quick-edit.min.js @@ -1 +1 @@ -jQuery(function(a){a("#the-list").on("click",".editinline",function(){inlineEditPost.revert();var b=a(this).closest("tr").attr("id");b=b.replace("post-","");var c=a("#woocommerce_inline_"+b),d=c.find(".sku").text(),e=c.find(".regular_price").text(),f=c.find(".sale_price ").text(),g=c.find(".weight").text(),h=c.find(".length").text(),i=c.find(".width").text(),j=c.find(".height").text(),k=c.find(".shipping_class").text(),l=c.find(".visibility").text(),m=c.find(".stock_status").text(),n=c.find(".stock").text(),o=c.find(".featured").text(),p=c.find(".manage_stock").text(),q=c.find(".menu_order").text(),r=c.find(".tax_status").text(),s=c.find(".tax_class").text(),t=c.find(".backorders").text();a('input[name="_sku"]',".inline-edit-row").val(d),a('input[name="_regular_price"]',".inline-edit-row").val(e),a('input[name="_sale_price"]',".inline-edit-row").val(f),a('input[name="_weight"]',".inline-edit-row").val(g),a('input[name="_length"]',".inline-edit-row").val(h),a('input[name="_width"]',".inline-edit-row").val(i),a('input[name="_height"]',".inline-edit-row").val(j),a('select[name="_shipping_class"] option:selected',".inline-edit-row").attr("selected",!1).change(),a('select[name="_shipping_class"] option[value="'+k+'"]').attr("selected","selected").change(),a('input[name="_stock"]',".inline-edit-row").val(n),a('input[name="menu_order"]',".inline-edit-row").val(q),a('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"),a('select[name="_tax_status"] option[value="'+r+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_tax_class"] option[value="'+s+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_visibility"] option[value="'+l+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_stock_status"] option[value="'+m+'"]',".inline-edit-row").attr("selected","selected"),a('select[name="_backorders"] option[value="'+t+'"]',".inline-edit-row").attr("selected","selected"),"yes"===o?a('input[name="_featured"]',".inline-edit-row").attr("checked","checked"):a('input[name="_featured"]',".inline-edit-row").removeAttr("checked"),"yes"===p?(a(".stock_qty_field",".inline-edit-row").show().removeAttr("style"),a('input[name="_manage_stock"]',".inline-edit-row").attr("checked","checked")):(a(".stock_qty_field",".inline-edit-row").hide(),a('input[name="_manage_stock"]',".inline-edit-row").removeAttr("checked"));var u=c.find(".product_type").text(),v=c.find(".product_is_virtual").text();"simple"===u||"external"===u?a(".price_fields",".inline-edit-row").show().removeAttr("style"):a(".price_fields",".inline-edit-row").hide(),"yes"===v?a(".dimension_fields",".inline-edit-row").hide():a(".dimension_fields",".inline-edit-row").show().removeAttr("style"),"grouped"===u?a(".stock_fields",".inline-edit-row").hide():a(".stock_fields",".inline-edit-row").show().removeAttr("style")}),a("#the-list").on("change",'.inline-edit-row input[name="_manage_stock"]',function(){a(this).is(":checked")?a(".stock_qty_field",".inline-edit-row").show().removeAttr("style"):a(".stock_qty_field",".inline-edit-row").hide()}),a("#wpbody").on("click","#doaction, #doaction2",function(){a("input.text",".inline-edit-row").val(""),a("#woocommerce-fields").find("select").prop("selectedIndex",0),a("#woocommerce-fields-bulk").find(".inline-edit-group .change-input").hide();var b="product_tag";a('tr.inline-editor textarea[name="tax_input['+b+']"]').suggest(ajaxurl+"?action=ajax-tag-search&tax="+b,{delay:500,minchars:2,multiple:!0,multipleSep:inlineEditL10n.comma})}),a("#wpbody").on("change","#woocommerce-fields-bulk .inline-edit-group .change_to",function(){00?"&":"?")+"action=ajax-tag-search&tax="+b,{delay:500,minchars:2,multiple:!0,multipleSep:inlineEditL10n.comma})}),a("#wpbody").on("change","#woocommerce-fields-bulk .inline-edit-group .change_to",function(){0'+d+"").css({top:c-16,left:b+20}).appendTo("body").fadeIn(200)}var c=null,d=null;a(".chart-placeholder").bind("plothover",function(e,f,g){if(g){if((c!==g.dataIndex||d!==g.seriesIndex)&&(c=g.dataIndex,d=g.seriesIndex,a(".chart-tooltip").remove(),g.series.points.show||g.series.enable_tooltip)){var h=g.series.data[g.dataIndex][1],i="";g.series.prepend_label&&(i=i+g.series.label+": "),g.series.prepend_tooltip&&(i+=g.series.prepend_tooltip),i+=h,g.series.append_tooltip&&(i+=g.series.append_tooltip),g.series.pie.show?b(f.pageX,f.pageY,i):b(g.pageX,g.pageY,i)}}else a(".chart-tooltip").remove(),c=null}),a(".wc_sparkline.bars").each(function(){var b=a(this).data("sparkline"),c={grid:{show:!1}},d=[{data:b,color:a(this).data("color"),bars:{fillColor:a(this).data("color"),fill:!0,show:!0,lineWidth:1,barWidth:a(this).data("barwidth"),align:"center"},shadowSize:0}];a.plot(a(this),d,c)}),a(".wc_sparkline.lines").each(function(){var b=a(this).data("sparkline"),c={grid:{show:!1}},d=[{data:b,color:a(this).data("color"),lines:{fill:!1,show:!0,lineWidth:1,align:"center"},shadowSize:0}];a.plot(a(this),d,c)});var e=a(".range_datepicker").datepicker({changeMonth:!0,changeYear:!0,defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,maxDate:"+0D",showButtonPanel:!0,showOn:"focus",buttonImageOnly:!0,onSelect:function(b){var c=a(this).is(".from")?"minDate":"maxDate",d=a(this).data("datepicker"),f=a.datepicker.parseDate(d.settings.dateFormat||a.datepicker._defaults.dateFormat,b,d.settings);e.not(this).datepicker("option",c,f)}}),f=document.createElement("a");"undefined"==typeof f.download&&a(".export_csv").hide(),a(".export_csv").click(function(){var b=a(this).data("exclude_series")||"";b=b.toString(),b=b.split(",");var c,d,e,f=a(this).data("xaxes"),g=a(this).data("groupby"),h=a(this).data("export"),i="data:application/csv;charset=utf-8,";if("table"===h)a(this).closest("div").find("thead tr,tbody tr").each(function(){a(this).find("th, td").each(function(){var b=a(this).text();b=b.replace("[?]",""),i+='"'+b+'",'}),i=i.substring(0,i.length-1),i+="\n"}),a(this).closest("div").find("tfoot tr").each(function(){a(this).find("th, td").each(function(){var b=a(this).text();if(b=b.replace("[?]",""),i+='"'+b+'",',a(this).attr("colspan")>0)for(m=1;m'+d+"").css({top:c-16,left:b+20}).appendTo("body").fadeIn(200)}var c=null,d=null;a(".chart-placeholder").bind("plothover",function(e,f,g){if(g){if((c!==g.dataIndex||d!==g.seriesIndex)&&(c=g.dataIndex,d=g.seriesIndex,a(".chart-tooltip").remove(),g.series.points.show||g.series.enable_tooltip)){var h=g.series.data[g.dataIndex][1],i="";g.series.prepend_label&&(i=i+g.series.label+": "),g.series.prepend_tooltip&&(i+=g.series.prepend_tooltip),i+=h,g.series.append_tooltip&&(i+=g.series.append_tooltip),g.series.pie.show?b(f.pageX,f.pageY,i):b(g.pageX,g.pageY,i)}}else a(".chart-tooltip").remove(),c=null}),a(".wc_sparkline.bars").each(function(){var b=a(this).data("sparkline"),c={grid:{show:!1}},d=[{data:b,color:a(this).data("color"),bars:{fillColor:a(this).data("color"),fill:!0,show:!0,lineWidth:1,barWidth:a(this).data("barwidth"),align:"center"},shadowSize:0}];a.plot(a(this),d,c)}),a(".wc_sparkline.lines").each(function(){var b=a(this).data("sparkline"),c={grid:{show:!1}},d=[{data:b,color:a(this).data("color"),lines:{fill:!1,show:!0,lineWidth:1,align:"center"},shadowSize:0}];a.plot(a(this),d,c)});var e=a(".range_datepicker").datepicker({changeMonth:!0,changeYear:!0,defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,maxDate:"+0D",showButtonPanel:!0,showOn:"focus",buttonImageOnly:!0,onSelect:function(b){var c=a(this).is(".from")?"minDate":"maxDate",d=a(this).data("datepicker"),f=a.datepicker.parseDate(d.settings.dateFormat||a.datepicker._defaults.dateFormat,b,d.settings);e.not(this).datepicker("option",c,f)}}),f=document.createElement("a");"undefined"==typeof f.download&&a(".export_csv").hide(),a(".export_csv").click(function(){var b=a(this).data("exclude_series")||"";b=b.toString(),b=b.split(",");var c,d,e,f=a(this).data("xaxes"),g=a(this).data("groupby"),h=a(this).data("export"),i="data:application/csv;charset=utf-8,";if("table"===h)a(this).closest("div").find("thead tr,tbody tr").each(function(){a(this).find("th, td").each(function(){var b=a(this).text();b=b.replace("[?]",""),i+='"'+b+'",'}),i=i.substring(0,i.length-1),i+="\n"}),a(this).closest("div").find("tfoot tr").each(function(){a(this).find("th, td").each(function(){var b=a(this).text();if(b=b.replace("[?]",""),i+='"'+b+'",',a(this).attr("colspan")>0)for(m=1;m 0 ? '&' : '?' ) + 'action=woocommerce_tax_rates_save_changes', + data: { + current_class: data.current_class, + wc_tax_nonce: data.wc_tax_nonce, + changes: self.changes + }, + success: function( response, textStatus ) { + if ( 'success' === textStatus ) { + WCTaxTableModelInstance.set( 'rates', response.data.rates ); + WCTaxTableModelInstance.trigger( 'change:rates' ); + + WCTaxTableModelInstance.changes = {}; + WCTaxTableModelInstance.trigger( 'saved:rates' ); + + // Reload view. + WCTaxTableInstance.render(); + } + + self.unblock(); + } + }); } } ), WCTaxTableViewConstructor = Backbone.View.extend({ @@ -91,7 +119,7 @@ this.listenTo( this.model, 'change:rates', this.setUnloadConfirmation ); this.listenTo( this.model, 'saved:rates', this.clearUnloadConfirmation ); - $tbody.on( 'change', { view: this }, this.updateModelOnChange ); + $tbody.on( 'change autocompletechange', ':input', { view: this }, this.updateModelOnChange ); $tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort ); $search_field.on( 'keyup search', { view: this }, this.onSearchField ); $pagination.on( 'click', 'a', { view: this }, this.onPageChange ); @@ -150,6 +178,9 @@ current_page: this.page, qty_pages: qty_pages } ) ); + } else { + $pagination.empty(); + view.page = 1; } // Disable sorting if there is a search term filtering the items. @@ -220,6 +251,8 @@ return parseInt( val, 10 ); } ); + // Move the last page + view.page = view.qty_pages; } rates[ newRow.tax_rate_id ] = newRow; @@ -235,27 +268,13 @@ model = view.model, rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ), changes = {}, - $current, current_id, current_order, rates_to_reorder, reordered_rates; + $current, current_id; event.preventDefault(); if ( $current = $tbody.children( '.current' ) ) { $current.each(function(){ current_id = $( this ).data('id'); - current_order = parseInt( rates[ current_id ].tax_rate_order, 10 ); - - rates_to_reorder = _.filter( rates, function( rate ) { - if ( parseInt( rate.tax_rate_order, 10 ) > current_order ) { - return true; - } - return false; - } ); - - reordered_rates = _.map( rates_to_reorder, function( rate ) { - rate.tax_rate_order--; - changes[ rate.tax_rate_id ] = _.extend( changes[ rate.tax_rate_id ] || {}, { tax_rate_order : rate.tax_rate_order } ); - return rate; - } ); delete rates[ current_id ]; @@ -345,53 +364,29 @@ model.setRateAttribute( id, attribute, val ); }, - updateModelOnSort: function( event, ui ) { + updateModelOnSort: function( event ) { var view = event.data.view, model = view.model, - $tr = ui.item, - tax_rate_id = $tr.data( 'id' ), rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ), - old_position = rates[ tax_rate_id ].tax_rate_order, - new_position = $tr.index() + ( ( view.page - 1 ) * view.per_page ), - which_way = ( new_position > old_position ) ? 'higher' : 'lower', - changes = {}, - rates_to_reorder, reordered_rates; + changes = {}; - rates_to_reorder = _.filter( rates, function( rate ) { - var order = parseInt( rate.tax_rate_order, 10 ), - limits = [ old_position, new_position ]; + _.each( rates, function( rate ) { + var new_position = 0; + var old_position = parseInt( rate.tax_rate_order, 10 ); - if ( parseInt( rate.tax_rate_id, 10 ) === parseInt( tax_rate_id, 10 ) ) { - return true; - } else if ( order > _.min( limits ) && order < _.max( limits ) ) { - return true; - } else if ( 'higher' === which_way && order === _.max( limits ) ) { - return true; - } else if ( 'lower' === which_way && order === _.min( limits ) ) { - return true; - } - return false; - } ); - - reordered_rates = _.map( rates_to_reorder, function( rate ) { - var order = parseInt( rate.tax_rate_order, 10 ); - - if ( parseInt( rate.tax_rate_id, 10 ) === parseInt( tax_rate_id, 10 ) ) { - rate.tax_rate_order = new_position; - } else if ( 'higher' === which_way ) { - rate.tax_rate_order = order - 1; - } else if ( 'lower' === which_way ) { - rate.tax_rate_order = order + 1; + if ( $table.find( 'tr[data-id="' + rate.tax_rate_id + '"]').length ) { + new_position = parseInt( $table.find( 'tr[data-id="' + rate.tax_rate_id + '"]').index(), 10 ) + parseInt( ( view.page - 1 ) * view.per_page, 10 ); + } else { + new_position = old_position; } - changes[ rate.tax_rate_id ] = _.extend( changes[ rate.tax_rate_id ] || {}, { tax_rate_order : rate.tax_rate_order } ); - - return rate; + if ( old_position !== new_position ) { + changes[ rate.tax_rate_id ] = _.extend( changes[ rate.tax_rate_id ] || {}, { tax_rate_order : new_position } ); + } } ); - if ( reordered_rates.length ) { + if ( _.size( changes ) ) { model.logChanges( changes ); - view.render(); // temporary, probably should get yanked. } }, sanitizePage: function( page_num ) { @@ -409,8 +404,6 @@ } ), WCTaxTableInstance = new WCTaxTableViewConstructor({ model: WCTaxTableModelInstance, - // page: data.page, // I'd prefer to have these two specified down here in the instance, - // per_page: data.limit, // but it doesn't seem to recognize them in render if I do. :\ el: '#rates' } ); diff --git a/assets/js/admin/settings-views-html-settings-tax.min.js b/assets/js/admin/settings-views-html-settings-tax.min.js index a4e3170e5f8..7c4e185bcd1 100644 --- a/assets/js/admin/settings-views-html-settings-tax.min.js +++ b/assets/js/admin/settings-views-html-settings-tax.min.js @@ -1 +1 @@ -!function(a,b,c,d){a(function(){String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});var e=c.template("wc-tax-table-row"),f=c.template("wc-tax-table-row-empty"),g=c.template("wc-tax-table-pagination"),h=a(".wc_tax_rates"),i=a("#rates"),j=a('input[name="save"]'),k=a("#rates-pagination"),l=a("#rates-search .wc-tax-rates-search-field"),m=a(".submit .button-primary[type=submit]"),n=Backbone.Model.extend({changes:{},setRateAttribute:function(a,b,c){var d=_.indexBy(this.get("rates"),"tax_rate_id"),e={};d[a][b]!==c&&(e[a]={},e[a][b]=c,d[a][b]=c),this.logChanges(e)},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{tax_rate_id:c},a)}),this.changes=b,this.trigger("change:rates")},getFilteredRates:function(){var a=this.get("rates"),b=l.val().toLowerCase();return b.length&&(a=_.filter(a,function(a){var c=_.toArray(a).join(" ").toLowerCase();return-1!==c.indexOf(b)})),a=_.sortBy(a,function(a){return parseInt(a.tax_rate_order,10)})},save:function(){a.post(d+"?action=woocommerce_tax_rates_save_changes",{current_class:b.current_class,wc_tax_nonce:b.wc_tax_nonce,changes:this.changes},this.onSaveResponse,"json")},onSaveResponse:function(a,b){"success"===b&&(p.set("rates",a.data.rates),p.trigger("change:rates"),p.changes={},p.trigger("saved:rates"))}}),o=Backbone.View.extend({rowTemplate:e,per_page:b.limit,page:b.page,initialize:function(){var c=Math.ceil(_.toArray(this.model.get("rates")).length/this.per_page);this.qty_pages=0===c?1:c,this.page=this.sanitizePage(b.page),this.listenTo(this.model,"change:rates",this.setUnloadConfirmation),this.listenTo(this.model,"saved:rates",this.clearUnloadConfirmation),i.on("change",{view:this},this.updateModelOnChange),i.on("sortupdate",{view:this},this.updateModelOnSort),l.on("keyup search",{view:this},this.onSearchField),k.on("click","a",{view:this},this.onPageChange),k.on("change","input",{view:this},this.onPageChange),a(window).on("beforeunload",{view:this},this.unloadConfirmation),m.on("click",{view:this},this.onSubmit),j.attr("disabled","disabled"),h.find(".insert").on("click",{view:this},this.onAddNewRow),h.find(".remove_tax_rates").on("click",{view:this},this.onDeleteRow),h.find(".export").on("click",{view:this},this.onExport)},render:function(){var c=this.model.getFilteredRates(),d=_.size(c),e=Math.ceil(d/this.per_page),h=0===d?0:this.per_page*(this.page-1),j=this.per_page*this.page,m=_.toArray(c).slice(h,j),n=this;this.$el.empty(),m.length?a.each(m,function(a,b){n.$el.append(n.rowTemplate(b))}):n.$el.append(f()),this.$el.find("td.country input").autocomplete({source:b.countries,minLength:2}),this.$el.find("td.state input").autocomplete({source:b.states,minLength:3}),this.$el.find("td.postcode input, td.city input").change(function(){a(this).attr("name",a(this).data("name"))}),e>1&&k.html(g({qty_rates:d,current_page:this.page,qty_pages:e})),l.val()?i.sortable("disable"):i.sortable("enable")},updateUrl:function(){if(window.history.replaceState){var a=b.base_url,c=l.val();1e?!0:!1}),g=_.map(f,function(a){return a.tax_rate_order++,l[a.tax_rate_id]=_.extend(l[a.tax_rate_id]||{},{tax_rate_order:a.tax_rate_order}),a})):n.tax_rate_order=1+_.max(_.pluck(k,"tax_rate_order"),function(a){return parseInt(a,10)}),k[n.tax_rate_id]=n,l[n.tax_rate_id]=n,j.set("rates",k),j.logChanges(l),h.render()},onDeleteRow:function(c){var d,e,f,g,h,j=c.data.view,k=j.model,l=_.indexBy(k.get("rates"),"tax_rate_id"),m={};c.preventDefault(),(d=i.children(".current"))?(d.each(function(){e=a(this).data("id"),f=parseInt(l[e].tax_rate_order,10),g=_.filter(l,function(a){return parseInt(a.tax_rate_order,10)>f?!0:!1}),h=_.map(g,function(a){return a.tax_rate_order--,m[a.tax_rate_id]=_.extend(m[a.tax_rate_id]||{},{tax_rate_order:a.tax_rate_order}),a}),delete l[e],m[e]=_.extend(m[e]||{},{deleted:"deleted"})}),k.set("rates",l),k.logChanges(m),j.render()):window.alert(b.strings.no_rows_selected)},onSearchField:function(a){a.data.view.updateUrl(),a.data.view.render()},onPageChange:function(b){var c=a(b.currentTarget);b.preventDefault(),b.data.view.page=c.data("goto")?c.data("goto"):c.val(),b.data.view.render(),b.data.view.updateUrl()},onExport:function(c){var d="data:application/csv;charset=utf-8,"+b.strings.csv_data_cols.join(",")+"\n";return a.each(c.data.view.model.getFilteredRates(),function(a,c){var e="";e+=c.tax_rate_country+",",e+=c.tax_rate_state+",",e+=(c.postcode?c.postcode.join("; "):"")+",",e+=(c.city?c.city.join("; "):"")+",",e+=c.tax_rate+",",e+=c.tax_rate_name+",",e+=c.tax_rate_priority+",",e+=c.tax_rate_compound+",",e+=c.tax_rate_shipping+",",e+=b.current_class,d+=e+"\n"}),a(this).attr("href",encodeURI(d)),!0},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,j.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,j.attr("disabled","disabled")},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val();("city"===f||"postcode"===f)&&(g=g.split(";"),g=a.map(g,function(a){return a.trim()})),("tax_rate_compound"===f||"tax_rate_shipping"===f)&&(g=d.is(":checked")?1:0),c.setRateAttribute(e,f,g)},updateModelOnSort:function(a,b){var c,d,e=a.data.view,f=e.model,g=b.item,h=g.data("id"),i=_.indexBy(f.get("rates"),"tax_rate_id"),j=i[h].tax_rate_order,k=g.index()+(e.page-1)*e.per_page,l=k>j?"higher":"lower",m={};c=_.filter(i,function(a){var b=parseInt(a.tax_rate_order,10),c=[j,k];return parseInt(a.tax_rate_id,10)===parseInt(h,10)?!0:b>_.min(c)&&b<_.max(c)?!0:"higher"===l&&b===_.max(c)?!0:"lower"===l&&b===_.min(c)?!0:!1}),d=_.map(c,function(a){var b=parseInt(a.tax_rate_order,10);return parseInt(a.tax_rate_id,10)===parseInt(h,10)?a.tax_rate_order=k:"higher"===l?a.tax_rate_order=b-1:"lower"===l&&(a.tax_rate_order=b+1),m[a.tax_rate_id]=_.extend(m[a.tax_rate_id]||{},{tax_rate_order:a.tax_rate_order}),a}),d.length&&(f.logChanges(m),e.render())},sanitizePage:function(a){return a=parseInt(a,10),1>a?a=1:a>this.qty_pages&&(a=this.qty_pages),a}}),p=new n({rates:b.rates}),q=new o({model:p,el:"#rates"});q.render()})}(jQuery,htmlSettingsTaxLocalizeScript,wp,ajaxurl); \ No newline at end of file +!function(a,b,c,d){a(function(){String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});var e=c.template("wc-tax-table-row"),f=c.template("wc-tax-table-row-empty"),g=c.template("wc-tax-table-pagination"),h=a(".wc_tax_rates"),i=a("#rates"),j=a('input[name="save"]'),k=a("#rates-pagination"),l=a("#rates-search .wc-tax-rates-search-field"),m=a(".submit .button-primary[type=submit]"),n=Backbone.Model.extend({changes:{},setRateAttribute:function(a,b,c){var d=_.indexBy(this.get("rates"),"tax_rate_id"),e={};d[a][b]!==c&&(e[a]={},e[a][b]=c,d[a][b]=c),this.logChanges(e)},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{tax_rate_id:c},a)}),this.changes=b,this.trigger("change:rates")},getFilteredRates:function(){var a=this.get("rates"),b=l.val().toLowerCase();return b.length&&(a=_.filter(a,function(a){var c=_.toArray(a).join(" ").toLowerCase();return-1!==c.indexOf(b)})),a=_.sortBy(a,function(a){return parseInt(a.tax_rate_order,10)})},block:function(){a(".wc_tax_rates").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(".wc_tax_rates").unblock()},save:function(){var a=this;a.block(),Backbone.ajax({method:"POST",dataType:"json",url:d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_tax_rates_save_changes",data:{current_class:b.current_class,wc_tax_nonce:b.wc_tax_nonce,changes:a.changes},success:function(b,c){"success"===c&&(p.set("rates",b.data.rates),p.trigger("change:rates"),p.changes={},p.trigger("saved:rates"),q.render()),a.unblock()}})}}),o=Backbone.View.extend({rowTemplate:e,per_page:b.limit,page:b.page,initialize:function(){var c=Math.ceil(_.toArray(this.model.get("rates")).length/this.per_page);this.qty_pages=0===c?1:c,this.page=this.sanitizePage(b.page),this.listenTo(this.model,"change:rates",this.setUnloadConfirmation),this.listenTo(this.model,"saved:rates",this.clearUnloadConfirmation),i.on("change autocompletechange",":input",{view:this},this.updateModelOnChange),i.on("sortupdate",{view:this},this.updateModelOnSort),l.on("keyup search",{view:this},this.onSearchField),k.on("click","a",{view:this},this.onPageChange),k.on("change","input",{view:this},this.onPageChange),a(window).on("beforeunload",{view:this},this.unloadConfirmation),m.on("click",{view:this},this.onSubmit),j.attr("disabled","disabled"),h.find(".insert").on("click",{view:this},this.onAddNewRow),h.find(".remove_tax_rates").on("click",{view:this},this.onDeleteRow),h.find(".export").on("click",{view:this},this.onExport)},render:function(){var c=this.model.getFilteredRates(),d=_.size(c),e=Math.ceil(d/this.per_page),h=0===d?0:this.per_page*(this.page-1),j=this.per_page*this.page,m=_.toArray(c).slice(h,j),n=this;this.$el.empty(),m.length?a.each(m,function(a,b){n.$el.append(n.rowTemplate(b))}):n.$el.append(f()),this.$el.find("td.country input").autocomplete({source:b.countries,minLength:2}),this.$el.find("td.state input").autocomplete({source:b.states,minLength:3}),this.$el.find("td.postcode input, td.city input").change(function(){a(this).attr("name",a(this).data("name"))}),e>1?k.html(g({qty_rates:d,current_page:this.page,qty_pages:e})):(k.empty(),n.page=1),l.val()?i.sortable("disable"):i.sortable("enable")},updateUrl:function(){if(window.history.replaceState){var a=b.base_url,c=l.val();1e}),g=_.map(f,function(a){return a.tax_rate_order++,l[a.tax_rate_id]=_.extend(l[a.tax_rate_id]||{},{tax_rate_order:a.tax_rate_order}),a})):(n.tax_rate_order=1+_.max(_.pluck(k,"tax_rate_order"),function(a){return parseInt(a,10)}),h.page=h.qty_pages),k[n.tax_rate_id]=n,l[n.tax_rate_id]=n,j.set("rates",k),j.logChanges(l),h.render()},onDeleteRow:function(c){var d,e,f=c.data.view,g=f.model,h=_.indexBy(g.get("rates"),"tax_rate_id"),j={};c.preventDefault(),(d=i.children(".current"))?(d.each(function(){e=a(this).data("id"),delete h[e],j[e]=_.extend(j[e]||{},{deleted:"deleted"})}),g.set("rates",h),g.logChanges(j),f.render()):window.alert(b.strings.no_rows_selected)},onSearchField:function(a){a.data.view.updateUrl(),a.data.view.render()},onPageChange:function(b){var c=a(b.currentTarget);b.preventDefault(),b.data.view.page=c.data("goto")?c.data("goto"):c.val(),b.data.view.render(),b.data.view.updateUrl()},onExport:function(c){var d="data:application/csv;charset=utf-8,"+b.strings.csv_data_cols.join(",")+"\n";return a.each(c.data.view.model.getFilteredRates(),function(a,c){var e="";e+=c.tax_rate_country+",",e+=c.tax_rate_state+",",e+=(c.postcode?c.postcode.join("; "):"")+",",e+=(c.city?c.city.join("; "):"")+",",e+=c.tax_rate+",",e+=c.tax_rate_name+",",e+=c.tax_rate_priority+",",e+=c.tax_rate_compound+",",e+=c.tax_rate_shipping+",",e+=b.current_class,d+=e+"\n"}),a(this).attr("href",encodeURI(d)),!0},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,j.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,j.attr("disabled","disabled")},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val();"city"!==f&&"postcode"!==f||(g=g.split(";"),g=a.map(g,function(a){return a.trim()})),"tax_rate_compound"!==f&&"tax_rate_shipping"!==f||(g=d.is(":checked")?1:0),c.setRateAttribute(e,f,g)},updateModelOnSort:function(a){var b=a.data.view,c=b.model,d=_.indexBy(c.get("rates"),"tax_rate_id"),e={};_.each(d,function(a){var c=0,d=parseInt(a.tax_rate_order,10);c=h.find('tr[data-id="'+a.tax_rate_id+'"]').length?parseInt(h.find('tr[data-id="'+a.tax_rate_id+'"]').index(),10)+parseInt((b.page-1)*b.per_page,10):d,d!==c&&(e[a.tax_rate_id]=_.extend(e[a.tax_rate_id]||{},{tax_rate_order:c}))}),_.size(e)&&c.logChanges(e)},sanitizePage:function(a){return a=parseInt(a,10),1>a?a=1:a>this.qty_pages&&(a=this.qty_pages),a}}),p=new n({rates:b.rates}),q=new o({model:p,el:"#rates"});q.render()})}(jQuery,htmlSettingsTaxLocalizeScript,wp,ajaxurl); \ No newline at end of file diff --git a/assets/js/admin/settings.js b/assets/js/admin/settings.js index 46791e69801..49776facbc2 100644 --- a/assets/js/admin/settings.js +++ b/assets/js/admin/settings.js @@ -1,44 +1,58 @@ /* global woocommerce_settings_params */ -jQuery( window ).load( function() { +( function( $ ) { - // Countries - jQuery( 'select#woocommerce_allowed_countries, select#woocommerce_ship_to_countries' ).change( function() { - if ( jQuery( this ).val() === 'specific' ) { - jQuery( this ).parent().parent().next( 'tr' ).show(); + // Sell Countries + $( 'select#woocommerce_allowed_countries' ).change( function() { + if ( 'specific' === $( this ).val() ) { + $( this ).closest('tr').next( 'tr' ).hide(); + $( this ).closest('tr').next().next( 'tr' ).show(); + } else if ( 'all_except' === $( this ).val() ) { + $( this ).closest('tr').next( 'tr' ).show(); + $( this ).closest('tr').next().next( 'tr' ).hide(); } else { - jQuery( this ).parent().parent().next( 'tr' ).hide(); + $( this ).closest('tr').next( 'tr' ).hide(); + $( this ).closest('tr').next().next( 'tr' ).hide(); + } + }).change(); + + // Ship Countries + $( 'select#woocommerce_ship_to_countries' ).change( function() { + if ( 'specific' === $( this ).val() ) { + $( this ).closest('tr').next( 'tr' ).show(); + } else { + $( this ).closest('tr').next( 'tr' ).hide(); } }).change(); // Color picker - jQuery( '.colorpick' ).iris({ + $( '.colorpick' ).iris({ change: function( event, ui ) { - jQuery( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() }); + $( this ).parent().find( '.colorpickpreview' ).css({ backgroundColor: ui.color.toString() }); }, hide: true, border: true }).click( function() { - jQuery( '.iris-picker' ).hide(); - jQuery( this ).closest( 'td' ).find( '.iris-picker' ).show(); + $( '.iris-picker' ).hide(); + $( this ).closest( 'td' ).find( '.iris-picker' ).show(); }); - jQuery( 'body' ).click( function() { - jQuery( '.iris-picker' ).hide(); + $( 'body' ).click( function() { + $( '.iris-picker' ).hide(); }); - jQuery( '.colorpick' ).click( function( event ) { + $( '.colorpick' ).click( function( event ) { event.stopPropagation(); }); // Edit prompt - jQuery( function() { + $( function() { var changed = false; - jQuery( 'input, textarea, select, checkbox' ).change( function() { + $( 'input, textarea, select, checkbox' ).change( function() { changed = true; }); - jQuery( '.woo-nav-tab-wrapper a' ).click( function() { + $( '.woo-nav-tab-wrapper a' ).click( function() { if ( changed ) { window.onbeforeunload = function() { return woocommerce_settings_params.i18n_nav_warning; @@ -48,13 +62,13 @@ jQuery( window ).load( function() { } }); - jQuery( '.submit input' ).click( function() { + $( '.submit input' ).click( function() { window.onbeforeunload = ''; }); }); // Sorting - jQuery( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({ + $( 'table.wc_gateways tbody, table.wc_shipping tbody' ).sortable({ items: 'tr', cursor: 'move', axis: 'y', @@ -62,7 +76,7 @@ jQuery( window ).load( function() { scrollSensitivity: 40, helper: function( event, ui ) { ui.children().each( function() { - jQuery( this ).width( jQuery( this ).width() ); + $( this ).width( $( this ).width() ); }); ui.css( 'left', '0' ); return ui; @@ -76,15 +90,15 @@ jQuery( window ).load( function() { }); // Select all/none - jQuery( '.woocommerce' ).on( 'click', '.select_all', function() { - jQuery( this ).closest( 'td' ).find( 'select option' ).attr( 'selected', 'selected' ); - jQuery( this ).closest( 'td' ).find( 'select' ).trigger( 'change' ); + $( '.woocommerce' ).on( 'click', '.select_all', function() { + $( this ).closest( 'td' ).find( 'select option' ).attr( 'selected', 'selected' ); + $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' ); return false; }); - jQuery( '.woocommerce' ).on( 'click', '.select_none', function() { - jQuery( this ).closest( 'td' ).find( 'select option' ).removeAttr( 'selected' ); - jQuery( this ).closest( 'td' ).find( 'select' ).trigger( 'change' ); + $( '.woocommerce' ).on( 'click', '.select_none', function() { + $( this ).closest( 'td' ).find( 'select option' ).removeAttr( 'selected' ); + $( this ).closest( 'td' ).find( 'select' ).trigger( 'change' ); return false; }); -}); +})( jQuery ); diff --git a/assets/js/admin/settings.min.js b/assets/js/admin/settings.min.js index 1c85132b5d5..493e0ba7bfc 100644 --- a/assets/js/admin/settings.min.js +++ b/assets/js/admin/settings.min.js @@ -1 +1 @@ -jQuery(window).load(function(){jQuery("select#woocommerce_allowed_countries, select#woocommerce_ship_to_countries").change(function(){"specific"===jQuery(this).val()?jQuery(this).parent().parent().next("tr").show():jQuery(this).parent().parent().next("tr").hide()}).change(),jQuery(".colorpick").iris({change:function(a,b){jQuery(this).parent().find(".colorpickpreview").css({backgroundColor:b.color.toString()})},hide:!0,border:!0}).click(function(){jQuery(".iris-picker").hide(),jQuery(this).closest("td").find(".iris-picker").show()}),jQuery("body").click(function(){jQuery(".iris-picker").hide()}),jQuery(".colorpick").click(function(a){a.stopPropagation()}),jQuery(function(){var a=!1;jQuery("input, textarea, select, checkbox").change(function(){a=!0}),jQuery(".woo-nav-tab-wrapper a").click(function(){a?window.onbeforeunload=function(){return woocommerce_settings_params.i18n_nav_warning}:window.onbeforeunload=""}),jQuery(".submit input").click(function(){window.onbeforeunload=""})}),jQuery("table.wc_gateways tbody, table.wc_shipping tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,helper:function(a,b){return b.children().each(function(){jQuery(this).width(jQuery(this).width())}),b.css("left","0"),b},start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")}}),jQuery(".woocommerce").on("click",".select_all",function(){return jQuery(this).closest("td").find("select option").attr("selected","selected"),jQuery(this).closest("td").find("select").trigger("change"),!1}),jQuery(".woocommerce").on("click",".select_none",function(){return jQuery(this).closest("td").find("select option").removeAttr("selected"),jQuery(this).closest("td").find("select").trigger("change"),!1})}); \ No newline at end of file +!function(a){a("select#woocommerce_allowed_countries").change(function(){"specific"===a(this).val()?(a(this).closest("tr").next("tr").hide(),a(this).closest("tr").next().next("tr").show()):"all_except"===a(this).val()?(a(this).closest("tr").next("tr").show(),a(this).closest("tr").next().next("tr").hide()):(a(this).closest("tr").next("tr").hide(),a(this).closest("tr").next().next("tr").hide())}).change(),a("select#woocommerce_ship_to_countries").change(function(){"specific"===a(this).val()?a(this).closest("tr").next("tr").show():a(this).closest("tr").next("tr").hide()}).change(),a(".colorpick").iris({change:function(b,c){a(this).parent().find(".colorpickpreview").css({backgroundColor:c.color.toString()})},hide:!0,border:!0}).click(function(){a(".iris-picker").hide(),a(this).closest("td").find(".iris-picker").show()}),a("body").click(function(){a(".iris-picker").hide()}),a(".colorpick").click(function(a){a.stopPropagation()}),a(function(){var b=!1;a("input, textarea, select, checkbox").change(function(){b=!0}),a(".woo-nav-tab-wrapper a").click(function(){b?window.onbeforeunload=function(){return woocommerce_settings_params.i18n_nav_warning}:window.onbeforeunload=""}),a(".submit input").click(function(){window.onbeforeunload=""})}),a("table.wc_gateways tbody, table.wc_shipping tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,helper:function(b,c){return c.children().each(function(){a(this).width(a(this).width())}),c.css("left","0"),c},start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")}}),a(".woocommerce").on("click",".select_all",function(){return a(this).closest("td").find("select option").attr("selected","selected"),a(this).closest("td").find("select").trigger("change"),!1}),a(".woocommerce").on("click",".select_none",function(){return a(this).closest("td").find("select option").removeAttr("selected"),a(this).closest("td").find("select").trigger("change"),!1})}(jQuery); \ No newline at end of file diff --git a/assets/js/admin/wc-enhanced-select.js b/assets/js/admin/wc-enhanced-select.js index 59dd5e0fd6a..2cae8dd951d 100644 --- a/assets/js/admin/wc-enhanced-select.js +++ b/assets/js/admin/wc-enhanced-select.js @@ -87,30 +87,32 @@ jQuery( function( $ ) { return m; }, ajax: { - url: wc_enhanced_select_params.ajax_url, - dataType: 'json', - quietMillis: 250, - data: function( term ) { - return { + url: wc_enhanced_select_params.ajax_url, + dataType: 'json', + quietMillis: 250, + data: function( term ) { + return { term: term, action: $( this ).data( 'action' ) || 'woocommerce_json_search_products_and_variations', security: wc_enhanced_select_params.search_products_nonce, - exclude: $( this ).data( 'exclude' ) - }; - }, - results: function( data ) { - var terms = []; - if ( data ) { + exclude: $( this ).data( 'exclude' ), + include: $( this ).data( 'include' ), + limit: $( this ).data( 'limit' ) + }; + }, + results: function( data ) { + var terms = []; + if ( data ) { $.each( data, function( id, text ) { terms.push( { id: id, text: text } ); }); } - return { - results: terms - }; - }, - cache: true - } + return { + results: terms + }; + }, + cache: true + } }; if ( $( this ).data( 'multiple' ) === true ) { @@ -156,19 +158,20 @@ jQuery( function( $ ) { return m; }, ajax: { - url: wc_enhanced_select_params.ajax_url, - dataType: 'json', - quietMillis: 250, - data: function( term ) { - return { + url: wc_enhanced_select_params.ajax_url, + dataType: 'json', + quietMillis: 250, + data: function( term ) { + return { term: term, action: 'woocommerce_json_search_customers', - security: wc_enhanced_select_params.search_customers_nonce - }; - }, - results: function( data ) { - var terms = []; - if ( data ) { + security: wc_enhanced_select_params.search_customers_nonce, + exclude: $( this ).data( 'exclude' ) + }; + }, + results: function( data ) { + var terms = []; + if ( data ) { $.each( data, function( id, text ) { terms.push({ id: id, @@ -176,10 +179,10 @@ jQuery( function( $ ) { }); }); } - return { results: terms }; - }, - cache: true - } + return { results: terms }; + }, + cache: true + } }; if ( $( this ).data( 'multiple' ) === true ) { select2_args.multiple = true; diff --git a/assets/js/admin/wc-enhanced-select.min.js b/assets/js/admin/wc-enhanced-select.min.js index a37a1e60466..ec8ce8f0f87 100644 --- a/assets/js/admin/wc-enhanced-select.min.js +++ b/assets/js/admin/wc-enhanced-select.min.js @@ -1 +1 @@ -jQuery(function(a){function b(){var a={formatMatches:function(a){return 1===a?wc_enhanced_select_params.i18n_matches_1:wc_enhanced_select_params.i18n_matches_n.replace("%qty%",a)},formatNoMatches:function(){return wc_enhanced_select_params.i18n_no_matches},formatAjaxError:function(){return wc_enhanced_select_params.i18n_ajax_error},formatInputTooShort:function(a,b){var c=b-a.length;return 1===c?wc_enhanced_select_params.i18n_input_too_short_1:wc_enhanced_select_params.i18n_input_too_short_n.replace("%qty%",c)},formatInputTooLong:function(a,b){var c=a.length-b;return 1===c?wc_enhanced_select_params.i18n_input_too_long_1:wc_enhanced_select_params.i18n_input_too_long_n.replace("%qty%",c)},formatSelectionTooBig:function(a){return 1===a?wc_enhanced_select_params.i18n_selection_too_long_1:wc_enhanced_select_params.i18n_selection_too_long_n.replace("%qty%",a)},formatLoadMore:function(){return wc_enhanced_select_params.i18n_load_more},formatSearching:function(){return wc_enhanced_select_params.i18n_searching}};return a}a(document.body).on("wc-enhanced-select-init",function(){a(":input.wc-enhanced-select, :input.chosen_select").filter(":not(.enhanced)").each(function(){var c=a.extend({minimumResultsForSearch:10,allowClear:a(this).data("allow_clear")?!0:!1,placeholder:a(this).data("placeholder")},b());a(this).select2(c).addClass("enhanced")}),a(":input.wc-enhanced-select-nostd, :input.chosen_select_nostd").filter(":not(.enhanced)").each(function(){var c=a.extend({minimumResultsForSearch:10,allowClear:!0,placeholder:a(this).data("placeholder")},b());a(this).select2(c).addClass("enhanced")}),a(":input.wc-product-search").filter(":not(.enhanced)").each(function(){var c={allowClear:a(this).data("allow_clear")?!0:!1,placeholder:a(this).data("placeholder"),minimumInputLength:a(this).data("minimum_input_length")?a(this).data("minimum_input_length"):"3",escapeMarkup:function(a){return a},ajax:{url:wc_enhanced_select_params.ajax_url,dataType:"json",quietMillis:250,data:function(b){return{term:b,action:a(this).data("action")||"woocommerce_json_search_products_and_variations",security:wc_enhanced_select_params.search_products_nonce,exclude:a(this).data("exclude")}},results:function(b){var c=[];return b&&a.each(b,function(a,b){c.push({id:a,text:b})}),{results:c}},cache:!0}};a(this).data("multiple")===!0?(c.multiple=!0,c.initSelection=function(b,c){var d=a.parseJSON(b.attr("data-selected")),e=[];return a(b.val().split(",")).each(function(a,b){e.push({id:b,text:d[b]})}),c(e)},c.formatSelection=function(a){return'
    '+a.text+"
    "}):(c.multiple=!1,c.initSelection=function(a,b){var c={id:a.val(),text:a.attr("data-selected")};return b(c)}),c=a.extend(c,b()),a(this).select2(c).addClass("enhanced")}),a(":input.wc-customer-search").filter(":not(.enhanced)").each(function(){var c={allowClear:a(this).data("allow_clear")?!0:!1,placeholder:a(this).data("placeholder"),minimumInputLength:a(this).data("minimum_input_length")?a(this).data("minimum_input_length"):"3",escapeMarkup:function(a){return a},ajax:{url:wc_enhanced_select_params.ajax_url,dataType:"json",quietMillis:250,data:function(a){return{term:a,action:"woocommerce_json_search_customers",security:wc_enhanced_select_params.search_customers_nonce}},results:function(b){var c=[];return b&&a.each(b,function(a,b){c.push({id:a,text:b})}),{results:c}},cache:!0}};a(this).data("multiple")===!0?(c.multiple=!0,c.initSelection=function(b,c){var d=a.parseJSON(b.attr("data-selected")),e=[];return a(b.val().split(",")).each(function(a,b){e.push({id:b,text:d[b]})}),c(e)},c.formatSelection=function(a){return'
    '+a.text+"
    "}):(c.multiple=!1,c.initSelection=function(a,b){var c={id:a.val(),text:a.attr("data-selected")};return b(c)}),c=a.extend(c,b()),a(this).select2(c).addClass("enhanced")})}).on("wc_backbone_modal_before_remove",function(){a(":input.wc-enhanced-select, :input.wc-product-search, :input.wc-customer-search").select2("close")}).trigger("wc-enhanced-select-init")}); \ No newline at end of file +jQuery(function(a){function b(){var a={formatMatches:function(a){return 1===a?wc_enhanced_select_params.i18n_matches_1:wc_enhanced_select_params.i18n_matches_n.replace("%qty%",a)},formatNoMatches:function(){return wc_enhanced_select_params.i18n_no_matches},formatAjaxError:function(){return wc_enhanced_select_params.i18n_ajax_error},formatInputTooShort:function(a,b){var c=b-a.length;return 1===c?wc_enhanced_select_params.i18n_input_too_short_1:wc_enhanced_select_params.i18n_input_too_short_n.replace("%qty%",c)},formatInputTooLong:function(a,b){var c=a.length-b;return 1===c?wc_enhanced_select_params.i18n_input_too_long_1:wc_enhanced_select_params.i18n_input_too_long_n.replace("%qty%",c)},formatSelectionTooBig:function(a){return 1===a?wc_enhanced_select_params.i18n_selection_too_long_1:wc_enhanced_select_params.i18n_selection_too_long_n.replace("%qty%",a)},formatLoadMore:function(){return wc_enhanced_select_params.i18n_load_more},formatSearching:function(){return wc_enhanced_select_params.i18n_searching}};return a}a(document.body).on("wc-enhanced-select-init",function(){a(":input.wc-enhanced-select, :input.chosen_select").filter(":not(.enhanced)").each(function(){var c=a.extend({minimumResultsForSearch:10,allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder")},b());a(this).select2(c).addClass("enhanced")}),a(":input.wc-enhanced-select-nostd, :input.chosen_select_nostd").filter(":not(.enhanced)").each(function(){var c=a.extend({minimumResultsForSearch:10,allowClear:!0,placeholder:a(this).data("placeholder")},b());a(this).select2(c).addClass("enhanced")}),a(":input.wc-product-search").filter(":not(.enhanced)").each(function(){var c={allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder"),minimumInputLength:a(this).data("minimum_input_length")?a(this).data("minimum_input_length"):"3",escapeMarkup:function(a){return a},ajax:{url:wc_enhanced_select_params.ajax_url,dataType:"json",quietMillis:250,data:function(b){return{term:b,action:a(this).data("action")||"woocommerce_json_search_products_and_variations",security:wc_enhanced_select_params.search_products_nonce,exclude:a(this).data("exclude"),include:a(this).data("include"),limit:a(this).data("limit")}},results:function(b){var c=[];return b&&a.each(b,function(a,b){c.push({id:a,text:b})}),{results:c}},cache:!0}};a(this).data("multiple")===!0?(c.multiple=!0,c.initSelection=function(b,c){var d=a.parseJSON(b.attr("data-selected")),e=[];return a(b.val().split(",")).each(function(a,b){e.push({id:b,text:d[b]})}),c(e)},c.formatSelection=function(a){return'
    '+a.text+"
    "}):(c.multiple=!1,c.initSelection=function(a,b){var c={id:a.val(),text:a.attr("data-selected")};return b(c)}),c=a.extend(c,b()),a(this).select2(c).addClass("enhanced")}),a(":input.wc-customer-search").filter(":not(.enhanced)").each(function(){var c={allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder"),minimumInputLength:a(this).data("minimum_input_length")?a(this).data("minimum_input_length"):"3",escapeMarkup:function(a){return a},ajax:{url:wc_enhanced_select_params.ajax_url,dataType:"json",quietMillis:250,data:function(b){return{term:b,action:"woocommerce_json_search_customers",security:wc_enhanced_select_params.search_customers_nonce,exclude:a(this).data("exclude")}},results:function(b){var c=[];return b&&a.each(b,function(a,b){c.push({id:a,text:b})}),{results:c}},cache:!0}};a(this).data("multiple")===!0?(c.multiple=!0,c.initSelection=function(b,c){var d=a.parseJSON(b.attr("data-selected")),e=[];return a(b.val().split(",")).each(function(a,b){e.push({id:b,text:d[b]})}),c(e)},c.formatSelection=function(a){return'
    '+a.text+"
    "}):(c.multiple=!1,c.initSelection=function(a,b){var c={id:a.val(),text:a.attr("data-selected")};return b(c)}),c=a.extend(c,b()),a(this).select2(c).addClass("enhanced")})}).on("wc_backbone_modal_before_remove",function(){a(":input.wc-enhanced-select, :input.wc-product-search, :input.wc-customer-search").select2("close")}).trigger("wc-enhanced-select-init")}); \ No newline at end of file diff --git a/assets/js/admin/wc-setup.js b/assets/js/admin/wc-setup.js index 6a88f418d41..96145eaac7f 100644 --- a/assets/js/admin/wc-setup.js +++ b/assets/js/admin/wc-setup.js @@ -1,9 +1,9 @@ /*global wc_setup_params */ -jQuery(function( $ ) { +jQuery( function( $ ) { var locale_info = $.parseJSON( wc_setup_params.locale_info ); - $('select[name="store_location"]').change(function(){ + $( 'select[name="store_location"]' ).change( function() { var country_option = $(this).val(); var country = country_option.split( ':' )[0]; var country_locale_info = locale_info[ country ]; @@ -23,19 +23,9 @@ jQuery(function( $ ) { $(':input[name="decimal_sep"]').closest('tr').show(); $(':input[name="num_decimals"]').closest('tr').show(); } - }).change(); + } ).change(); - $('input[name="woocommerce_calc_shipping"]').change(function(){ - if ( $(this).is( ':checked' ) ) { - $(':input[name="shipping_cost_domestic"]').closest('tr').show(); - $(':input[name="shipping_cost_international"]').closest('tr').show(); - } else { - $(':input[name="shipping_cost_domestic"]').closest('tr').hide(); - $(':input[name="shipping_cost_international"]').closest('tr').hide(); - } - }).change(); - - $('input[name="woocommerce_calc_taxes"]').change(function(){ + $( 'input[name="woocommerce_calc_taxes"]' ).change( function() { if ( $(this).is( ':checked' ) ) { $(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest('tr').show(); $('tr.tax-rates').show(); @@ -43,17 +33,9 @@ jQuery(function( $ ) { $(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest('tr').hide(); $('tr.tax-rates').hide(); } - }).change(); + } ).change(); - $('input[name="woocommerce_import_tax_rates"]').change(function(){ - if ( $(this).is( ':checked' ) ) { - $('.importing-tax-rates').show(); - } else { - $('.importing-tax-rates').hide(); - } - }).change(); - - $('.button-next').on( 'click', function() { + $( '.button-next' ).on( 'click', function() { $('.wc-setup-content').block({ message: null, overlayCSS: { @@ -62,6 +44,23 @@ jQuery(function( $ ) { } }); return true; - }); + } ); -}); + $( '.wc-wizard-payment-gateways' ).on( 'change', '.wc-wizard-gateway-enable input', function() { + if ( $( this ).is( ':checked' ) ) { + $( this ).closest( 'li' ).addClass( 'checked' ); + } else { + $( this ).closest( 'li' ).removeClass( 'checked' ); + } + } ); + + $( '.wc-wizard-payment-gateways' ).on( 'click', 'li.wc-wizard-gateway', function() { + var $enabled = $( this ).find( '.wc-wizard-gateway-enable input' ); + + $enabled.prop( 'checked', ! $enabled.prop( 'checked' ) ).change(); + } ); + + $( '.wc-wizard-payment-gateways' ).on( 'click', 'li.wc-wizard-gateway table, li.wc-wizard-gateway a', function( e ) { + e.stopPropagation(); + } ); +} ); diff --git a/assets/js/admin/wc-setup.min.js b/assets/js/admin/wc-setup.min.js index 72efc694a0f..5dcaf11b467 100644 --- a/assets/js/admin/wc-setup.min.js +++ b/assets/js/admin/wc-setup.min.js @@ -1 +1 @@ -jQuery(function(a){var b=a.parseJSON(wc_setup_params.locale_info);a('select[name="store_location"]').change(function(){var c=a(this).val(),d=c.split(":")[0],e=b[d],f=["thousand_sep","decimal_sep","num_decimals","currency_pos"];e?a.each(e,function(b,c){a(':input[name="'+b+'"]').val(c).change(),-1!==a.inArray(b,f)&&a(':input[name="'+b+'"]').closest("tr").hide()}):(a(':input[name="currency_pos"]').closest("tr").show(),a(':input[name="thousand_sep"]').closest("tr").show(),a(':input[name="decimal_sep"]').closest("tr").show(),a(':input[name="num_decimals"]').closest("tr").show())}).change(),a('input[name="woocommerce_calc_shipping"]').change(function(){a(this).is(":checked")?(a(':input[name="shipping_cost_domestic"]').closest("tr").show(),a(':input[name="shipping_cost_international"]').closest("tr").show()):(a(':input[name="shipping_cost_domestic"]').closest("tr").hide(),a(':input[name="shipping_cost_international"]').closest("tr").hide())}).change(),a('input[name="woocommerce_calc_taxes"]').change(function(){a(this).is(":checked")?(a(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest("tr").show(),a("tr.tax-rates").show()):(a(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest("tr").hide(),a("tr.tax-rates").hide())}).change(),a('input[name="woocommerce_import_tax_rates"]').change(function(){a(this).is(":checked")?a(".importing-tax-rates").show():a(".importing-tax-rates").hide()}).change(),a(".button-next").on("click",function(){return a(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),!0})}); \ No newline at end of file +jQuery(function(a){var b=a.parseJSON(wc_setup_params.locale_info);a('select[name="store_location"]').change(function(){var c=a(this).val(),d=c.split(":")[0],e=b[d],f=["thousand_sep","decimal_sep","num_decimals","currency_pos"];e?a.each(e,function(b,c){a(':input[name="'+b+'"]').val(c).change(),-1!==a.inArray(b,f)&&a(':input[name="'+b+'"]').closest("tr").hide()}):(a(':input[name="currency_pos"]').closest("tr").show(),a(':input[name="thousand_sep"]').closest("tr").show(),a(':input[name="decimal_sep"]').closest("tr").show(),a(':input[name="num_decimals"]').closest("tr").show())}).change(),a('input[name="woocommerce_calc_taxes"]').change(function(){a(this).is(":checked")?(a(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest("tr").show(),a("tr.tax-rates").show()):(a(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest("tr").hide(),a("tr.tax-rates").hide())}).change(),a(".button-next").on("click",function(){return a(".wc-setup-content").block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),!0}),a(".wc-wizard-payment-gateways").on("change",".wc-wizard-gateway-enable input",function(){a(this).is(":checked")?a(this).closest("li").addClass("checked"):a(this).closest("li").removeClass("checked")}),a(".wc-wizard-payment-gateways").on("click","li.wc-wizard-gateway",function(){var b=a(this).find(".wc-wizard-gateway-enable input");b.prop("checked",!b.prop("checked")).change()}),a(".wc-wizard-payment-gateways").on("click","li.wc-wizard-gateway table, li.wc-wizard-gateway a",function(a){a.stopPropagation()})}); \ No newline at end of file diff --git a/assets/js/admin/wc-shipping-classes.js b/assets/js/admin/wc-shipping-classes.js new file mode 100644 index 00000000000..e08704044b2 --- /dev/null +++ b/assets/js/admin/wc-shipping-classes.js @@ -0,0 +1,210 @@ +/* global shippingClassesLocalizeScript, ajaxurl */ +( function( $, data, wp, ajaxurl ) { + $( function() { + var $table = $( '.wc-shipping-classes' ), + $tbody = $( '.wc-shipping-class-rows' ), + $save_button = $( '.wc-shipping-class-save' ), + $row_template = wp.template( 'wc-shipping-class-row' ), + $blank_template = wp.template( 'wc-shipping-class-row-blank' ), + + // Backbone model + ShippingClass = Backbone.Model.extend({ + changes: {}, + logChanges: function( changedRows ) { + var changes = this.changes || {}; + + _.each( changedRows, function( row, id ) { + changes[ id ] = _.extend( changes[ id ] || { term_id : id }, row ); + } ); + + this.changes = changes; + this.trigger( 'change:classes' ); + }, + save: function() { + if ( _.size( this.changes ) ) { + $.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_classes_save_changes', { + wc_shipping_classes_nonce : data.wc_shipping_classes_nonce, + changes : this.changes + }, this.onSaveResponse, 'json' ); + } else { + shippingClass.trigger( 'saved:classes' ); + } + }, + onSaveResponse: function( response, textStatus ) { + if ( 'success' === textStatus ) { + if ( response.success ) { + shippingClass.set( 'classes', response.data.shipping_classes ); + shippingClass.trigger( 'change:classes' ); + shippingClass.changes = {}; + shippingClass.trigger( 'saved:classes' ); + } else if ( response.data ) { + window.alert( response.data ); + } else { + window.alert( data.strings.save_failed ); + } + } + shippingClassView.unblock(); + } + } ), + + // Backbone view + ShippingClassView = Backbone.View.extend({ + rowTemplate: $row_template, + initialize: function() { + this.listenTo( this.model, 'change:classes', this.setUnloadConfirmation ); + this.listenTo( this.model, 'saved:classes', this.clearUnloadConfirmation ); + this.listenTo( this.model, 'saved:classes', this.render ); + $tbody.on( 'change', { view: this }, this.updateModelOnChange ); + $( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation ); + $save_button.on( 'click', { view: this }, this.onSubmit ); + $( document.body ).on( 'click', '.wc-shipping-class-add', { view: this }, this.onAddNewRow ); + $( document.body ).on( 'click', '.wc-shipping-class-save-changes', { view: this }, this.onSubmit ); + }, + block: function() { + $( this.el ).block({ + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + }); + }, + unblock: function() { + $( this.el ).unblock(); + }, + render: function() { + var classes = _.indexBy( this.model.get( 'classes' ), 'term_id' ), + view = this; + + this.$el.empty(); + this.unblock(); + + if ( _.size( classes ) ) { + // Sort classes + classes = _.sortBy( classes, function( shipping_class ) { + return shipping_class.name; + } ); + + // Populate $tbody with the current classes + $.each( classes, function( id, rowData ) { + view.$el.append( view.rowTemplate( rowData ) ); + + var $tr = view.$el.find( 'tr[data-id="' + rowData.term_id + '"]'); + + // Editing? + if ( rowData.editing ) { + $tr.addClass( 'editing' ); + } + } ); + + // Make the rows function + this.$el.find('.view').show(); + this.$el.find('.edit').hide(); + this.$el.find( '.wc-shipping-class-edit' ).on( 'click', { view: this }, this.onEditRow ); + this.$el.find( '.wc-shipping-class-delete' ).on( 'click', { view: this }, this.onDeleteRow ); + this.$el.find( '.wc-shipping-class-postcodes-toggle' ).on( 'click', { view: this }, this.onTogglePostcodes ); + this.$el.find('.editing .wc-shipping-class-edit').trigger('click'); + + // Stripe + if ( 0 === _.size( classes ) % 2) { + $table.find( 'tbody.wc-shipping-class-rows' ).next( 'tbody' ).find( 'tr' ).addClass( 'odd' ); + } else { + $table.find( 'tbody.wc-shipping-class-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' ); + } + } else { + view.$el.append( $blank_template ); + } + }, + onSubmit: function( event ) { + event.data.view.block(); + event.data.view.model.save(); + event.preventDefault(); + }, + onAddNewRow: function( event ) { + event.preventDefault(); + + var view = event.data.view, + model = view.model, + classes = _.indexBy( model.get( 'classes' ), 'term_id' ), + changes = {}, + size = _.size( classes ), + newRow = _.extend( {}, data.default_class, { + term_id: 'new-' + size + '-' + Date.now(), + editing: true, + newRow : true + } ); + + classes[ newRow.term_id ] = newRow; + changes[ newRow.term_id ] = newRow; + + model.set( 'classes', classes ); + model.logChanges( changes ); + + view.render(); + }, + onEditRow: function( event ) { + event.preventDefault(); + $( this ).closest('tr').addClass('editing'); + $( this ).closest('tr').find('.view').hide(); + $( this ).closest('tr').find('.edit').show(); + event.data.view.model.trigger( 'change:classes' ); + }, + onDeleteRow: function( event ) { + var view = event.data.view, + model = view.model, + classes = _.indexBy( model.get( 'classes' ), 'term_id' ), + changes = {}, + term_id = $( this ).closest('tr').data('id'); + + event.preventDefault(); + + delete classes[ term_id ]; + changes[ term_id ] = _.extend( changes[ term_id ] || {}, { deleted : 'deleted' } ); + model.set( 'classes', classes ); + model.logChanges( changes ); + view.render(); + }, + setUnloadConfirmation: function() { + this.needsUnloadConfirm = true; + $save_button.removeAttr( 'disabled' ); + }, + clearUnloadConfirmation: function() { + this.needsUnloadConfirm = false; + $save_button.attr( 'disabled', 'disabled' ); + }, + unloadConfirmation: function( event ) { + if ( event.data.view.needsUnloadConfirm ) { + event.returnValue = data.strings.unload_confirmation_msg; + window.event.returnValue = data.strings.unload_confirmation_msg; + return data.strings.unload_confirmation_msg; + } + }, + updateModelOnChange: function( event ) { + var model = event.data.view.model, + $target = $( event.target ), + term_id = $target.closest( 'tr' ).data( 'id' ), + attribute = $target.data( 'attribute' ), + value = $target.val(), + classes = _.indexBy( model.get( 'classes' ), 'term_id' ), + changes = {}; + + if ( classes[ term_id ][ attribute ] !== value ) { + changes[ term_id ] = {}; + changes[ term_id ][ attribute ] = value; + classes[ term_id ][ attribute ] = value; + } + + model.logChanges( changes ); + } + } ), + shippingClass = new ShippingClass({ + classes: data.classes + } ), + shippingClassView = new ShippingClassView({ + model: shippingClass, + el: $tbody + } ); + + shippingClassView.render(); + }); +})( jQuery, shippingClassesLocalizeScript, wp, ajaxurl ); diff --git a/assets/js/admin/wc-shipping-classes.min.js b/assets/js/admin/wc-shipping-classes.min.js new file mode 100644 index 00000000000..3e1b039eb92 --- /dev/null +++ b/assets/js/admin/wc-shipping-classes.min.js @@ -0,0 +1 @@ +!function(a,b,c,d){a(function(){var e=a(".wc-shipping-classes"),f=a(".wc-shipping-class-rows"),g=a(".wc-shipping-class-save"),h=c.template("wc-shipping-class-row"),i=c.template("wc-shipping-class-row-blank"),j=Backbone.Model.extend({changes:{},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{term_id:c},a)}),this.changes=b,this.trigger("change:classes")},save:function(){_.size(this.changes)?a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_classes_save_changes",{wc_shipping_classes_nonce:b.wc_shipping_classes_nonce,changes:this.changes},this.onSaveResponse,"json"):l.trigger("saved:classes")},onSaveResponse:function(a,c){"success"===c&&(a.success?(l.set("classes",a.data.shipping_classes),l.trigger("change:classes"),l.changes={},l.trigger("saved:classes")):a.data?window.alert(a.data):window.alert(b.strings.save_failed)),m.unblock()}}),k=Backbone.View.extend({rowTemplate:h,initialize:function(){this.listenTo(this.model,"change:classes",this.setUnloadConfirmation),this.listenTo(this.model,"saved:classes",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:classes",this.render),f.on("change",{view:this},this.updateModelOnChange),a(window).on("beforeunload",{view:this},this.unloadConfirmation),g.on("click",{view:this},this.onSubmit),a(document.body).on("click",".wc-shipping-class-add",{view:this},this.onAddNewRow),a(document.body).on("click",".wc-shipping-class-save-changes",{view:this},this.onSubmit)},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},render:function(){var b=_.indexBy(this.model.get("classes"),"term_id"),c=this;this.$el.empty(),this.unblock(),_.size(b)?(b=_.sortBy(b,function(a){return a.name}),a.each(b,function(a,b){c.$el.append(c.rowTemplate(b));var d=c.$el.find('tr[data-id="'+b.term_id+'"]');b.editing&&d.addClass("editing")}),this.$el.find(".view").show(),this.$el.find(".edit").hide(),this.$el.find(".wc-shipping-class-edit").on("click",{view:this},this.onEditRow),this.$el.find(".wc-shipping-class-delete").on("click",{view:this},this.onDeleteRow),this.$el.find(".wc-shipping-class-postcodes-toggle").on("click",{view:this},this.onTogglePostcodes),this.$el.find(".editing .wc-shipping-class-edit").trigger("click"),0===_.size(b)%2?e.find("tbody.wc-shipping-class-rows").next("tbody").find("tr").addClass("odd"):e.find("tbody.wc-shipping-class-rows").next("tbody").find("tr").removeClass("odd")):c.$el.append(i)},onSubmit:function(a){a.data.view.block(),a.data.view.model.save(),a.preventDefault()},onAddNewRow:function(a){a.preventDefault();var c=a.data.view,d=c.model,e=_.indexBy(d.get("classes"),"term_id"),f={},g=_.size(e),h=_.extend({},b.default_class,{term_id:"new-"+g+"-"+Date.now(),editing:!0,newRow:!0});e[h.term_id]=h,f[h.term_id]=h,d.set("classes",e),d.logChanges(f),c.render()},onEditRow:function(b){b.preventDefault(),a(this).closest("tr").addClass("editing"),a(this).closest("tr").find(".view").hide(),a(this).closest("tr").find(".edit").show(),b.data.view.model.trigger("change:classes")},onDeleteRow:function(b){var c=b.data.view,d=c.model,e=_.indexBy(d.get("classes"),"term_id"),f={},g=a(this).closest("tr").data("id");b.preventDefault(),delete e[g],f[g]=_.extend(f[g]||{},{deleted:"deleted"}),d.set("classes",e),d.logChanges(f),c.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,g.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,g.attr("disabled","disabled")},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("classes"),"term_id"),i={};h[e][f]!==g&&(i[e]={},i[e][f]=g,h[e][f]=g),c.logChanges(i)}}),l=new j({classes:b.classes}),m=new k({model:l,el:f});m.render()})}(jQuery,shippingClassesLocalizeScript,wp,ajaxurl); \ No newline at end of file diff --git a/assets/js/admin/wc-shipping-zone-methods.js b/assets/js/admin/wc-shipping-zone-methods.js new file mode 100644 index 00000000000..10f465b1b0a --- /dev/null +++ b/assets/js/admin/wc-shipping-zone-methods.js @@ -0,0 +1,324 @@ +/* global shippingZoneMethodsLocalizeScript, ajaxurl */ +( function( $, data, wp, ajaxurl ) { + $( function() { + var $table = $( '.wc-shipping-zone-methods' ), + $tbody = $( '.wc-shipping-zone-method-rows' ), + $save_button = $( '.wc-shipping-zone-method-save' ), + $row_template = wp.template( 'wc-shipping-zone-method-row' ), + $blank_template = wp.template( 'wc-shipping-zone-method-row-blank' ), + + // Backbone model + ShippingMethod = Backbone.Model.extend({ + changes: {}, + logChanges: function( changedRows ) { + var changes = this.changes || {}; + + _.each( changedRows, function( row, id ) { + changes[ id ] = _.extend( changes[ id ] || { instance_id : id }, row ); + } ); + + this.changes = changes; + this.trigger( 'change:methods' ); + }, + save: function() { + if ( _.size( this.changes ) ) { + $.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_methods_save_changes', { + wc_shipping_zones_nonce : data.wc_shipping_zones_nonce, + changes : this.changes, + zone_id : data.zone_id + }, this.onSaveResponse, 'json' ); + } else { + shippingMethod.trigger( 'saved:methods' ); + } + }, + addMethod: function() { + if ( _.size( this.changes ) && window.confirm( data.strings.save_changes_prompt ) ) { + this.save(); + } + $.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_add_method', { + wc_shipping_zones_nonce : data.wc_shipping_zones_nonce, + method_id : $('select[name="add_method_id"]').val(), + zone_id : data.zone_id + }, this.onAddResponse, 'json' ); + }, + onSaveResponse: function( response, textStatus ) { + if ( 'success' === textStatus ) { + if ( response.success ) { + shippingMethod.set( 'methods', response.data.methods ); + shippingMethod.trigger( 'change:methods' ); + shippingMethod.changes = {}; + shippingMethod.trigger( 'saved:methods' ); + } else { + window.alert( data.strings.save_failed ); + } + } + }, + onAddResponse: function( response, textStatus ) { + if ( 'success' === textStatus ) { + if ( response.success && response.data.instance_id ) { + shippingMethod.set( 'methods', response.data.methods ); + shippingMethod.trigger( 'change:methods' ); + shippingMethod.changes = {}; + shippingMethod.trigger( 'saved:methods' ); + } else { + window.alert( data.strings.add_method_failed ); + } + } + } + } ), + + // Backbone view + ShippingMethodView = Backbone.View.extend({ + rowTemplate: $row_template, + initialize: function() { + this.listenTo( this.model, 'change:methods', this.setUnloadConfirmation ); + this.listenTo( this.model, 'saved:methods', this.clearUnloadConfirmation ); + this.listenTo( this.model, 'saved:methods', this.render ); + $tbody.on( 'change', { view: this }, this.updateModelOnChange ); + $tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort ); + $( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation ); + $save_button.on( 'click', { view: this }, this.onSubmit ); + $('.wc-shipping-zone-add-method').on( 'click', { view: this }, this.onAdd ); + + // Settings modal + $( document.body ).on( 'click', '.wc-shipping-zone-method-settings', { view: this }, this.onConfigureShippingMethod ); + $( document.body ).on( 'wc_backbone_modal_response', this.onConfigureShippingMethodSubmitted ); + }, + block: function() { + $( this.el ).block({ + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + }); + }, + unblock: function() { + $( this.el ).unblock(); + }, + render: function() { + var methods = _.indexBy( this.model.get( 'methods' ), 'instance_id' ), + view = this; + + // Blank out the contents. + this.$el.empty(); + this.unblock(); + + if ( _.size( methods ) ) { + // Sort methods + methods = _.sortBy( methods, function( method ) { + return parseInt( method.method_order, 10 ); + } ); + + // Populate $tbody with the current methods + $.each( methods, function( id, rowData ) { + if ( 'yes' === rowData.enabled ) { + rowData.enabled_icon = '' + data.strings.yes + ''; + } else { + rowData.enabled_icon = '' + data.strings.no + ''; + } + + view.$el.append( view.rowTemplate( rowData ) ); + + var $tr = view.$el.find( 'tr[data-id="' + rowData.instance_id + '"]'); + + if ( ! rowData.has_settings ) { + $tr.find( '.wc-shipping-zone-method-title a').replaceWith( $tr.find( '.wc-shipping-zone-method-title' ).text() ); + $tr.find( '.wc-shipping-zone-method-settings' ).remove(); + } + } ); + + // Make the rows function + this.$el.find( '.wc-shipping-zone-method-delete' ).on( 'click', { view: this }, this.onDeleteRow ); + this.$el.find( '.wc-shipping-zone-method-enabled a').on( 'click', { view: this }, this.onToggleEnabled ); + } else { + view.$el.append( $blank_template ); + } + + this.initTooltips(); + }, + initTooltips: function() { + $( '#tiptip_holder' ).removeAttr( 'style' ); + $( '#tiptip_arrow' ).removeAttr( 'style' ); + $( '.tips' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 50 }); + }, + onSubmit: function( event ) { + event.data.view.block(); + event.data.view.model.save(); + event.preventDefault(); + }, + onAdd: function( event ) { + event.data.view.block(); + event.data.view.model.addMethod(); + event.preventDefault(); + }, + onDeleteRow: function( event ) { + var view = event.data.view, + model = view.model, + methods = _.indexBy( model.get( 'methods' ), 'instance_id' ), + changes = {}, + instance_id = $( this ).closest('tr').data('id'); + + event.preventDefault(); + + delete methods[ instance_id ]; + changes[ instance_id ] = _.extend( changes[ instance_id ] || {}, { deleted : 'deleted' } ); + model.set( 'methods', methods ); + model.logChanges( changes ); + view.render(); + }, + onToggleEnabled: function( event ) { + var view = event.data.view, + $target = $( event.target ), + model = view.model, + methods = _.indexBy( model.get( 'methods' ), 'instance_id' ), + instance_id = $target.closest( 'tr' ).data( 'id' ), + enabled = $target.closest( 'tr' ).data( 'enabled' ) === 'yes' ? 'no' : 'yes', + changes = {}; + + event.preventDefault(); + methods[ instance_id ].enabled = enabled; + changes[ instance_id ] = _.extend( changes[ instance_id ] || {}, { enabled : enabled } ); + model.set( 'methods', methods ); + model.logChanges( changes ); + view.render(); + }, + setUnloadConfirmation: function() { + this.needsUnloadConfirm = true; + $save_button.removeAttr( 'disabled' ); + }, + clearUnloadConfirmation: function() { + this.needsUnloadConfirm = false; + $save_button.attr( 'disabled', 'disabled' ); + }, + unloadConfirmation: function( event ) { + if ( event.data.view.needsUnloadConfirm ) { + event.returnValue = data.strings.unload_confirmation_msg; + window.event.returnValue = data.strings.unload_confirmation_msg; + return data.strings.unload_confirmation_msg; + } + }, + updateModelOnChange: function( event ) { + var model = event.data.view.model, + $target = $( event.target ), + instance_id = $target.closest( 'tr' ).data( 'id' ), + attribute = $target.data( 'attribute' ), + value = $target.val(), + methods = _.indexBy( model.get( 'methods' ), 'instance_id' ), + changes = {}; + + if ( methods[ instance_id ][ attribute ] !== value ) { + changes[ instance_id ] = {}; + changes[ instance_id ][ attribute ] = value; + methods[ instance_id ][ attribute ] = value; + } + + model.logChanges( changes ); + }, + updateModelOnSort: function( event ) { + var view = event.data.view, + model = view.model, + methods = _.indexBy( model.get( 'methods' ), 'instance_id' ), + changes = {}; + + _.each( methods, function( method ) { + var old_position = parseInt( method.method_order, 10 ); + var new_position = parseInt( $table.find( 'tr[data-id="' + method.instance_id + '"]').index() + 1, 10 ); + + if ( old_position !== new_position ) { + changes[ method.instance_id ] = _.extend( changes[ method.instance_id ] || {}, { method_order : new_position } ); + } + } ); + + if ( _.size( changes ) ) { + model.logChanges( changes ); + } + }, + onConfigureShippingMethod: function( event ) { + var instance_id = $( this ).closest( 'tr' ).data( 'id' ), + model = event.data.view.model, + methods = _.indexBy( model.get( 'methods' ), 'instance_id' ), + method = methods[ instance_id ]; + + // Only load modal if supported + if ( ! method.settings_html ) { + return true; + } + + event.preventDefault(); + + $( this ).WCBackboneModal({ + template : 'wc-modal-shipping-method-settings', + variable : { + instance_id : instance_id, + method : method + }, + data : { + instance_id : instance_id, + method : method + } + }); + + $( document.body ).trigger( 'init_tooltips' ); + }, + onConfigureShippingMethodSubmitted: function( event, target, posted_data ) { + if ( 'wc-modal-shipping-method-settings' === target ) { + shippingMethodView.block(); + + // Save method settings via ajax call + $.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_methods_save_settings', { + wc_shipping_zones_nonce : data.wc_shipping_zones_nonce, + instance_id : posted_data.instance_id, + data : posted_data + }, function( response, textStatus ) { + if ( 'success' === textStatus && response.success ) { + $( 'table.wc-shipping-zone-methods' ).parent().find( '#woocommerce_errors' ).remove(); + + // If there were errors, prepend the form. + if ( response.data.errors.length > 0 ) { + this.showErrors( response.data.errors ); + } + + // Method was saved. Re-render. + if ( _.size( shippingMethodView.model.changes ) ) { + shippingMethodView.model.save(); + } else { + shippingMethodView.model.onSaveResponse( response, textStatus ); + } + } else { + window.alert( data.strings.save_failed ); + shippingMethodView.unblock(); + } + }, 'json' ); + } + }, + showErrors: function( errors ) { + var error_html = '
    '; + + $( errors ).each( function( index, value ) { + error_html = error_html + '

    ' + value + '

    '; + } ); + error_html = error_html + '
    '; + + $( 'table.wc-shipping-zone-methods' ).before( error_html ); + } + } ), + shippingMethod = new ShippingMethod({ + methods: data.methods + } ), + shippingMethodView = new ShippingMethodView({ + model: shippingMethod, + el: $tbody + } ); + + shippingMethodView.render(); + + $tbody.sortable({ + items: 'tr', + cursor: 'move', + axis: 'y', + handle: 'td.wc-shipping-zone-method-sort', + scrollSensitivity: 40 + }); + }); +})( jQuery, shippingZoneMethodsLocalizeScript, wp, ajaxurl ); diff --git a/assets/js/admin/wc-shipping-zone-methods.min.js b/assets/js/admin/wc-shipping-zone-methods.min.js new file mode 100644 index 00000000000..e8a63eb4a03 --- /dev/null +++ b/assets/js/admin/wc-shipping-zone-methods.min.js @@ -0,0 +1 @@ +!function(a,b,c,d){a(function(){var e=a(".wc-shipping-zone-methods"),f=a(".wc-shipping-zone-method-rows"),g=a(".wc-shipping-zone-method-save"),h=c.template("wc-shipping-zone-method-row"),i=c.template("wc-shipping-zone-method-row-blank"),j=Backbone.Model.extend({changes:{},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{instance_id:c},a)}),this.changes=b,this.trigger("change:methods")},save:function(){_.size(this.changes)?a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_methods_save_changes",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,changes:this.changes,zone_id:b.zone_id},this.onSaveResponse,"json"):l.trigger("saved:methods")},addMethod:function(){_.size(this.changes)&&window.confirm(b.strings.save_changes_prompt)&&this.save(),a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_add_method",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,method_id:a('select[name="add_method_id"]').val(),zone_id:b.zone_id},this.onAddResponse,"json")},onSaveResponse:function(a,c){"success"===c&&(a.success?(l.set("methods",a.data.methods),l.trigger("change:methods"),l.changes={},l.trigger("saved:methods")):window.alert(b.strings.save_failed))},onAddResponse:function(a,c){"success"===c&&(a.success&&a.data.instance_id?(l.set("methods",a.data.methods),l.trigger("change:methods"),l.changes={},l.trigger("saved:methods")):window.alert(b.strings.add_method_failed))}}),k=Backbone.View.extend({rowTemplate:h,initialize:function(){this.listenTo(this.model,"change:methods",this.setUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:methods",this.render),f.on("change",{view:this},this.updateModelOnChange),f.on("sortupdate",{view:this},this.updateModelOnSort),a(window).on("beforeunload",{view:this},this.unloadConfirmation),g.on("click",{view:this},this.onSubmit),a(".wc-shipping-zone-add-method").on("click",{view:this},this.onAdd),a(document.body).on("click",".wc-shipping-zone-method-settings",{view:this},this.onConfigureShippingMethod),a(document.body).on("wc_backbone_modal_response",this.onConfigureShippingMethodSubmitted)},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},render:function(){var c=_.indexBy(this.model.get("methods"),"instance_id"),d=this;this.$el.empty(),this.unblock(),_.size(c)?(c=_.sortBy(c,function(a){return parseInt(a.method_order,10)}),a.each(c,function(a,c){"yes"===c.enabled?c.enabled_icon=''+b.strings.yes+"":c.enabled_icon=''+b.strings.no+"",d.$el.append(d.rowTemplate(c));var e=d.$el.find('tr[data-id="'+c.instance_id+'"]');c.has_settings||(e.find(".wc-shipping-zone-method-title a").replaceWith(e.find(".wc-shipping-zone-method-title").text()),e.find(".wc-shipping-zone-method-settings").remove())}),this.$el.find(".wc-shipping-zone-method-delete").on("click",{view:this},this.onDeleteRow),this.$el.find(".wc-shipping-zone-method-enabled a").on("click",{view:this},this.onToggleEnabled)):d.$el.append(i),this.initTooltips()},initTooltips:function(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},onSubmit:function(a){a.data.view.block(),a.data.view.model.save(),a.preventDefault()},onAdd:function(a){a.data.view.block(),a.data.view.model.addMethod(),a.preventDefault()},onDeleteRow:function(b){var c=b.data.view,d=c.model,e=_.indexBy(d.get("methods"),"instance_id"),f={},g=a(this).closest("tr").data("id");b.preventDefault(),delete e[g],f[g]=_.extend(f[g]||{},{deleted:"deleted"}),d.set("methods",e),d.logChanges(f),c.render()},onToggleEnabled:function(b){var c=b.data.view,d=a(b.target),e=c.model,f=_.indexBy(e.get("methods"),"instance_id"),g=d.closest("tr").data("id"),h="yes"===d.closest("tr").data("enabled")?"no":"yes",i={};b.preventDefault(),f[g].enabled=h,i[g]=_.extend(i[g]||{},{enabled:h}),e.set("methods",f),e.logChanges(i),c.render()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,g.removeAttr("disabled")},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,g.attr("disabled","disabled")},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("methods"),"instance_id"),i={};h[e][f]!==g&&(i[e]={},i[e][f]=g,h[e][f]=g),c.logChanges(i)},updateModelOnSort:function(a){var b=a.data.view,c=b.model,d=_.indexBy(c.get("methods"),"instance_id"),f={};_.each(d,function(a){var b=parseInt(a.method_order,10),c=parseInt(e.find('tr[data-id="'+a.instance_id+'"]').index()+1,10);b!==c&&(f[a.instance_id]=_.extend(f[a.instance_id]||{},{method_order:c}))}),_.size(f)&&c.logChanges(f)},onConfigureShippingMethod:function(b){var c=a(this).closest("tr").data("id"),d=b.data.view.model,e=_.indexBy(d.get("methods"),"instance_id"),f=e[c];return f.settings_html?(b.preventDefault(),a(this).WCBackboneModal({template:"wc-modal-shipping-method-settings",variable:{instance_id:c,method:f},data:{instance_id:c,method:f}}),void a(document.body).trigger("init_tooltips")):!0},onConfigureShippingMethodSubmitted:function(c,e,f){"wc-modal-shipping-method-settings"===e&&(m.block(),a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_methods_save_settings",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,instance_id:f.instance_id,data:f},function(c,d){"success"===d&&c.success?(a("table.wc-shipping-zone-methods").parent().find("#woocommerce_errors").remove(),c.data.errors.length>0&&this.showErrors(c.data.errors),_.size(m.model.changes)?m.model.save():m.model.onSaveResponse(c,d)):(window.alert(b.strings.save_failed),m.unblock())},"json"))},showErrors:function(b){var c='
    ';a(b).each(function(a,b){c=c+"

    "+b+"

    "}),c+="
    ",a("table.wc-shipping-zone-methods").before(c)}}),l=new j({methods:b.methods}),m=new k({model:l,el:f});m.render(),f.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-method-sort",scrollSensitivity:40})})}(jQuery,shippingZoneMethodsLocalizeScript,wp,ajaxurl); \ No newline at end of file diff --git a/assets/js/admin/wc-shipping-zones.js b/assets/js/admin/wc-shipping-zones.js new file mode 100644 index 00000000000..a5cb90fcfe8 --- /dev/null +++ b/assets/js/admin/wc-shipping-zones.js @@ -0,0 +1,482 @@ +/* global wc_enhanced_select_params, shippingZonesLocalizeScript, ajaxurl */ +( function( $, data, wp, ajaxurl ) { + $( function() { + var $table = $( '.wc-shipping-zones' ), + $tbody = $( '.wc-shipping-zone-rows' ), + $save_button = $( '.wc-shipping-zone-save' ), + $row_template = wp.template( 'wc-shipping-zone-row' ), + $blank_template = wp.template( 'wc-shipping-zone-row-blank' ), + select2_args = $.extend({ + minimumResultsForSearch: 10, + allowClear: $( this ).data( 'allow_clear' ) ? true : false, + placeholder: $( this ).data( 'placeholder' ), + matcher: function( term, text, opt ) { + return text.toUpperCase().indexOf( term.toUpperCase() ) >= 0 || opt.attr( 'alt' ).toUpperCase().indexOf( term.toUpperCase() ) >= 0; + } + }, getEnhancedSelectFormatString() ), + + // Backbone model + ShippingZone = Backbone.Model.extend({ + changes: {}, + logChanges: function( changedRows ) { + var changes = this.changes || {}; + + _.each( changedRows, function( row, id ) { + changes[ id ] = _.extend( changes[ id ] || { zone_id : id }, row ); + } ); + + this.changes = changes; + this.trigger( 'change:zones' ); + }, + discardChanges: function( id ) { + var changes = this.changes || {}, + set_position = null, + zones = _.indexBy( this.get( 'zones' ), 'zone_id' ); + + // Find current set position if it has moved since last save + if ( changes[ id ] && changes[ id ].zone_order !== undefined ) { + set_position = changes[ id ].zone_order; + } + + // Delete all changes + delete changes[ id ]; + + // If the position was set, and this zone does exist in DB, set the position again so the changes are not lost. + if ( set_position !== null && zones[ id ] && zones[ id ].zone_order !== set_position ) { + changes[ id ] = _.extend( changes[ id ] || {}, { zone_id : id, zone_order : set_position } ); + } + + this.changes = changes; + + // No changes? Disable save button. + if ( 0 === _.size( this.changes ) ) { + shippingZoneView.clearUnloadConfirmation(); + } + }, + save: function() { + if ( _.size( this.changes ) ) { + $.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zones_save_changes', { + wc_shipping_zones_nonce : data.wc_shipping_zones_nonce, + changes : this.changes + }, this.onSaveResponse, 'json' ); + } else { + shippingZone.trigger( 'saved:zones' ); + } + }, + onSaveResponse: function( response, textStatus ) { + if ( 'success' === textStatus ) { + if ( response.success ) { + shippingZone.set( 'zones', response.data.zones ); + shippingZone.trigger( 'change:zones' ); + shippingZone.changes = {}; + shippingZone.trigger( 'saved:zones' ); + } else { + window.alert( data.strings.save_failed ); + } + } + } + } ), + + // Backbone view + ShippingZoneView = Backbone.View.extend({ + rowTemplate: $row_template, + initialize: function() { + this.listenTo( this.model, 'change:zones', this.setUnloadConfirmation ); + this.listenTo( this.model, 'saved:zones', this.clearUnloadConfirmation ); + this.listenTo( this.model, 'saved:zones', this.render ); + $tbody.on( 'change', { view: this }, this.updateModelOnChange ); + $tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort ); + $( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation ); + $save_button.on( 'click', { view: this }, this.onSubmit ); + $( document.body ).on( 'click', '.add_shipping_method:not(.disabled)', { view: this }, this.onAddShippingMethod ); + $( document.body ).on( 'click', '.wc-shipping-zone-add', { view: this }, this.onAddNewRow ); + $( document.body ).on( 'click', '.wc-shipping-zone-save-changes', { view: this }, this.onSubmit ); + $( document.body ).on( 'wc_backbone_modal_response', this.onAddShippingMethodSubmitted ); + $( document.body ).on( 'change', '.wc-shipping-zone-method-selector select', this.onChangeShippingMethodSelector ); + }, + block: function() { + $( this.el ).block({ + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + }); + }, + unblock: function() { + $( this.el ).unblock(); + }, + render: function() { + var zones = _.indexBy( this.model.get( 'zones' ), 'zone_id' ), + view = this; + + view.$el.empty(); + view.unblock(); + + if ( _.size( zones ) ) { + // Sort zones + zones = _.sortBy( zones, function( zone ) { + return parseInt( zone.zone_order, 10 ); + } ); + + // Populate $tbody with the current zones + $.each( zones, function( id, rowData ) { + view.renderRow( rowData ); + } ); + + } else { + view.$el.append( $blank_template ); + } + + view.initRows(); + }, + renderRow: function( rowData ) { + var view = this; + view.$el.append( view.rowTemplate( rowData ) ); + view.initRow( rowData ); + }, + initRow: function( rowData ) { + var view = this; + var $tr = view.$el.find( 'tr[data-id="' + rowData.zone_id + '"]'); + + // Select values in region select + _.each( rowData.zone_locations, function( location ) { + if ( 'string' === jQuery.type( location ) ) { + $tr.find( 'option[value="' + location + '"]' ).prop( 'selected', true ); + } else { + if ( 'postcode' === location.type ) { + var postcode_field = $tr.find( '.wc-shipping-zone-postcodes :input' ); + + if ( postcode_field.val() ) { + postcode_field.val( postcode_field.val() + '\n' + location.code ); + } else { + postcode_field.val( location.code ); + } + $tr.find( '.wc-shipping-zone-postcodes' ).show(); + $tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide(); + } else { + $tr.find( 'option[value="' + location.type + ':' + location.code + '"]' ).prop( 'selected', true ); + } + } + } ); + + if ( rowData.zone_postcodes ) { + _.each( rowData.zone_postcodes, function( location ) { + var postcode_field = $tr.find( '.wc-shipping-zone-postcodes :input' ); + + if ( postcode_field.val() ) { + postcode_field.val( postcode_field.val() + '\n' + location.code ); + } else { + postcode_field.val( location.code ); + } + $tr.find( '.wc-shipping-zone-postcodes' ).show(); + $tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide(); + } ); + } + + // List shipping methods + view.renderShippingMethods( rowData.zone_id, rowData.shipping_methods ); + + // Make the row function + $tr.find( '.view' ).show(); + $tr.find( '.edit' ).hide(); + $tr.find( '.wc-shipping-zone-edit' ).on( 'click', { view: this }, this.onEditRow ); + $tr.find( '.wc-shipping-zone-cancel-edit' ).on( 'click', { view: this }, this.onCancelEditRow ); + $tr.find( '.wc-shipping-zone-delete' ).on( 'click', { view: this }, this.onDeleteRow ); + $tr.find( '.wc-shipping-zone-postcodes-toggle' ).on( 'click', { view: this }, this.onTogglePostcodes ); + + // Editing? + if ( true === rowData.editing ) { + $tr.addClass( 'editing' ); + $tr.find( '.wc-shipping-zone-edit' ).trigger( 'click' ); + } + }, + initRows: function() { + // Stripe + if ( 0 === ( $( 'tbody.wc-shipping-zone-rows tr' ).length % 2 ) ) { + $table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).addClass( 'odd' ); + } else { + $table.find( 'tbody.wc-shipping-zone-rows' ).next( 'tbody' ).find( 'tr' ).removeClass( 'odd' ); + } + + // Tooltips + $( '#tiptip_holder' ).removeAttr( 'style' ); + $( '#tiptip_arrow' ).removeAttr( 'style' ); + $( '.tips' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 50 }); + }, + renderShippingMethods: function( zone_id, shipping_methods ) { + var $tr = $( '.wc-shipping-zones tr[data-id="' + zone_id + '"]'); + var $method_list = $tr.find('.wc-shipping-zone-methods ul'); + + $method_list.find( '.wc-shipping-zone-method' ).remove(); + + if ( _.size( shipping_methods ) ) { + _.each( shipping_methods, function( shipping_method, instance_id ) { + var class_name = 'method_disabled'; + + if ( 'yes' === shipping_method.enabled ) { + class_name = 'method_enabled'; + } + + $method_list.prepend( '
  • ' + shipping_method.title + '
  • ' ); + } ); + } else { + $method_list.prepend( '
  • ' ); + } + }, + onSubmit: function( event ) { + event.data.view.block(); + event.data.view.model.save(); + event.preventDefault(); + }, + onAddNewRow: function( event ) { + event.preventDefault(); + + var view = event.data.view, + model = view.model, + zones = _.indexBy( model.get( 'zones' ), 'zone_id' ), + changes = {}, + size = _.size( zones ), + newRow = _.extend( {}, data.default_zone, { + zone_id : 'new-' + size + '-' + Date.now(), + zone_name: data.strings.default_zone_name, + editing : true + } ); + + newRow.zone_order = 1 + _.max( + _.pluck( zones, 'zone_order' ), + function ( val ) { + // Cast them all to integers, because strings compare funky. Sighhh. + return parseInt( val, 10 ); + } + ); + + changes[ newRow.zone_id ] = newRow; + + model.logChanges( changes ); + view.renderRow( newRow ); + view.initRows(); + }, + onTogglePostcodes: function( event ) { + event.preventDefault(); + var $tr = $( this ).closest( 'tr'); + $tr.find( '.wc-shipping-zone-postcodes' ).show(); + $tr.find( '.wc-shipping-zone-postcodes-toggle' ).hide(); + }, + onEditRow: function( event ) { + event.preventDefault(); + event.data.view.model.trigger( 'change:zones' ); + $( this ).closest('tr').addClass( 'editing' ); + $( this ).closest('tr').find('.view').hide(); + $( this ).closest('tr').find('.edit').show(); + $( '.wc-shipping-zone-region-select:not(.enhanced)' ).select2( select2_args ); + $( '.wc-shipping-zone-region-select:not(.enhanced)' ).addClass('enhanced'); + + var addShippingMethod = $( this ).closest('tr').find('.add_shipping_method'); + addShippingMethod.addClass( 'disabled' ); + addShippingMethod.tipTip({ 'attribute': 'data-disabled-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 50 }); + }, + onCancelEditRow: function( event ) { + var view = event.data.view, + model = view.model, + row = $( this ).closest('tr'), + zone_id = row.data('id'), + zones = _.indexBy( model.get( 'zones' ), 'zone_id' ); + + event.preventDefault(); + model.discardChanges( zone_id ); + + if ( zones[ zone_id ] ) { + zones[ zone_id ].editing = false; + row.after( view.rowTemplate( zones[ zone_id ] ) ); + view.initRow( zones[ zone_id ] ); + } + + row.remove(); + view.initRows(); + }, + onDeleteRow: function( event ) { + var view = event.data.view, + model = view.model, + zones = _.indexBy( model.get( 'zones' ), 'zone_id' ), + changes = {}, + row = $( this ).closest('tr'), + zone_id = $( this ).closest('tr').data('id'); + + event.preventDefault(); + + if ( zones[ zone_id ] ) { + delete zones[ zone_id ]; + changes[ zone_id ] = _.extend( changes[ zone_id ] || {}, { deleted : 'deleted' } ); + model.set( 'zones', zones ); + model.logChanges( changes ); + } + + row.remove(); + view.initRows(); + }, + setUnloadConfirmation: function() { + this.needsUnloadConfirm = true; + $save_button.prop( 'disabled', false ); + }, + clearUnloadConfirmation: function() { + this.needsUnloadConfirm = false; + $save_button.prop( 'disabled', true ); + }, + unloadConfirmation: function( event ) { + if ( event.data.view.needsUnloadConfirm ) { + event.returnValue = data.strings.unload_confirmation_msg; + window.event.returnValue = data.strings.unload_confirmation_msg; + return data.strings.unload_confirmation_msg; + } + }, + updateModelOnChange: function( event ) { + var model = event.data.view.model, + $target = $( event.target ), + zone_id = $target.closest( 'tr' ).data( 'id' ), + attribute = $target.data( 'attribute' ), + value = $target.val(), + zones = _.indexBy( model.get( 'zones' ), 'zone_id' ), + changes = {}; + + if ( ! zones[ zone_id ] || zones[ zone_id ][ attribute ] !== value ) { + changes[ zone_id ] = {}; + changes[ zone_id ][ attribute ] = value; + } + + model.logChanges( changes ); + }, + updateModelOnSort: function( event ) { + var view = event.data.view, + model = view.model, + zones = _.indexBy( model.get( 'zones' ), 'zone_id' ), + rows = $( 'tbody.wc-shipping-zone-rows tr' ), + changes = {}; + + // Update sorted row position + _.each( rows, function( row ) { + var zone_id = $( row ).data( 'id' ), + old_position = null, + new_position = parseInt( $( row ).index(), 10 ); + + if ( zones[ zone_id ] ) { + old_position = parseInt( zones[ zone_id ].zone_order, 10 ); + } + + if ( old_position !== new_position ) { + changes[ zone_id ] = _.extend( changes[ zone_id ] || {}, { zone_order : new_position } ); + } + } ); + + if ( _.size( changes ) ) { + model.logChanges( changes ); + } + }, + onAddShippingMethod: function( event ) { + var zone_id = $( this ).closest('tr').data('id'); + + event.preventDefault(); + + $( this ).WCBackboneModal({ + template : 'wc-modal-add-shipping-method', + variable : { + zone_id : zone_id + } + }); + + $( '.wc-shipping-zone-method-selector select' ).change(); + }, + onAddShippingMethodSubmitted: function( event, target, posted_data ) { + if ( 'wc-modal-add-shipping-method' === target ) { + shippingZoneView.block(); + + // Add method to zone via ajax call + $.post( ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?' ) + 'action=woocommerce_shipping_zone_add_method', { + wc_shipping_zones_nonce : data.wc_shipping_zones_nonce, + method_id : posted_data.add_method_id, + zone_id : posted_data.zone_id + }, function( response, textStatus ) { + if ( 'success' === textStatus && response.success ) { + // Method was added. Render methods. + shippingZoneView.renderShippingMethods( posted_data.zone_id, response.data.methods ); + } + shippingZoneView.unblock(); + }, 'json' ); + } + }, + onChangeShippingMethodSelector: function() { + var description = $( this ).find( 'option:selected' ).data( 'description' ); + $( this ).parent().find( '.wc-shipping-zone-method-description' ).remove(); + $( this ).after( '

    ' + description + '

    ' ); + $( this ).closest( 'article' ).height( $( this ).parent().height() ); + } + } ), + shippingZone = new ShippingZone({ + zones: data.zones + } ), + shippingZoneView = new ShippingZoneView({ + model: shippingZone, + el: $tbody + } ); + + shippingZoneView.render(); + + $tbody.sortable({ + items: 'tr', + cursor: 'move', + axis: 'y', + handle: 'td.wc-shipping-zone-sort', + scrollSensitivity: 40 + }); + + function getEnhancedSelectFormatString() { + var formatString = { + formatMatches: function( matches ) { + if ( 1 === matches ) { + return wc_enhanced_select_params.i18n_matches_1; + } + return wc_enhanced_select_params.i18n_matches_n.replace( '%qty%', matches ); + }, + formatNoMatches: function() { + return wc_enhanced_select_params.i18n_no_matches; + }, + formatAjaxError: function() { + return wc_enhanced_select_params.i18n_ajax_error; + }, + formatInputTooShort: function( input, min ) { + var number = min - input.length; + + if ( 1 === number ) { + return wc_enhanced_select_params.i18n_input_too_short_1; + } + + return wc_enhanced_select_params.i18n_input_too_short_n.replace( '%qty%', number ); + }, + formatInputTooLong: function( input, max ) { + var number = input.length - max; + + if ( 1 === number ) { + return wc_enhanced_select_params.i18n_input_too_long_1; + } + + return wc_enhanced_select_params.i18n_input_too_long_n.replace( '%qty%', number ); + }, + formatSelectionTooBig: function( limit ) { + if ( 1 === limit ) { + return wc_enhanced_select_params.i18n_selection_too_long_1; + } + + return wc_enhanced_select_params.i18n_selection_too_long_n.replace( '%qty%', limit ); + }, + formatLoadMore: function() { + return wc_enhanced_select_params.i18n_load_more; + }, + formatSearching: function() { + return wc_enhanced_select_params.i18n_searching; + } + }; + + return formatString; + } + }); +})( jQuery, shippingZonesLocalizeScript, wp, ajaxurl ); diff --git a/assets/js/admin/wc-shipping-zones.min.js b/assets/js/admin/wc-shipping-zones.min.js new file mode 100644 index 00000000000..e89f2c3b156 --- /dev/null +++ b/assets/js/admin/wc-shipping-zones.min.js @@ -0,0 +1 @@ +!function(a,b,c,d){a(function(){function e(){var a={formatMatches:function(a){return 1===a?wc_enhanced_select_params.i18n_matches_1:wc_enhanced_select_params.i18n_matches_n.replace("%qty%",a)},formatNoMatches:function(){return wc_enhanced_select_params.i18n_no_matches},formatAjaxError:function(){return wc_enhanced_select_params.i18n_ajax_error},formatInputTooShort:function(a,b){var c=b-a.length;return 1===c?wc_enhanced_select_params.i18n_input_too_short_1:wc_enhanced_select_params.i18n_input_too_short_n.replace("%qty%",c)},formatInputTooLong:function(a,b){var c=a.length-b;return 1===c?wc_enhanced_select_params.i18n_input_too_long_1:wc_enhanced_select_params.i18n_input_too_long_n.replace("%qty%",c)},formatSelectionTooBig:function(a){return 1===a?wc_enhanced_select_params.i18n_selection_too_long_1:wc_enhanced_select_params.i18n_selection_too_long_n.replace("%qty%",a)},formatLoadMore:function(){return wc_enhanced_select_params.i18n_load_more},formatSearching:function(){return wc_enhanced_select_params.i18n_searching}};return a}var f=a(".wc-shipping-zones"),g=a(".wc-shipping-zone-rows"),h=a(".wc-shipping-zone-save"),i=c.template("wc-shipping-zone-row"),j=c.template("wc-shipping-zone-row-blank"),k=a.extend({minimumResultsForSearch:10,allowClear:!!a(this).data("allow_clear"),placeholder:a(this).data("placeholder"),matcher:function(a,b,c){return b.toUpperCase().indexOf(a.toUpperCase())>=0||c.attr("alt").toUpperCase().indexOf(a.toUpperCase())>=0}},e()),l=Backbone.Model.extend({changes:{},logChanges:function(a){var b=this.changes||{};_.each(a,function(a,c){b[c]=_.extend(b[c]||{zone_id:c},a)}),this.changes=b,this.trigger("change:zones")},discardChanges:function(a){var b=this.changes||{},c=null,d=_.indexBy(this.get("zones"),"zone_id");b[a]&&void 0!==b[a].zone_order&&(c=b[a].zone_order),delete b[a],null!==c&&d[a]&&d[a].zone_order!==c&&(b[a]=_.extend(b[a]||{},{zone_id:a,zone_order:c})),this.changes=b,0===_.size(this.changes)&&o.clearUnloadConfirmation()},save:function(){_.size(this.changes)?a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zones_save_changes",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,changes:this.changes},this.onSaveResponse,"json"):n.trigger("saved:zones")},onSaveResponse:function(a,c){"success"===c&&(a.success?(n.set("zones",a.data.zones),n.trigger("change:zones"),n.changes={},n.trigger("saved:zones")):window.alert(b.strings.save_failed))}}),m=Backbone.View.extend({rowTemplate:i,initialize:function(){this.listenTo(this.model,"change:zones",this.setUnloadConfirmation),this.listenTo(this.model,"saved:zones",this.clearUnloadConfirmation),this.listenTo(this.model,"saved:zones",this.render),g.on("change",{view:this},this.updateModelOnChange),g.on("sortupdate",{view:this},this.updateModelOnSort),a(window).on("beforeunload",{view:this},this.unloadConfirmation),h.on("click",{view:this},this.onSubmit),a(document.body).on("click",".add_shipping_method:not(.disabled)",{view:this},this.onAddShippingMethod),a(document.body).on("click",".wc-shipping-zone-add",{view:this},this.onAddNewRow),a(document.body).on("click",".wc-shipping-zone-save-changes",{view:this},this.onSubmit),a(document.body).on("wc_backbone_modal_response",this.onAddShippingMethodSubmitted),a(document.body).on("change",".wc-shipping-zone-method-selector select",this.onChangeShippingMethodSelector)},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},render:function(){var b=_.indexBy(this.model.get("zones"),"zone_id"),c=this;c.$el.empty(),c.unblock(),_.size(b)?(b=_.sortBy(b,function(a){return parseInt(a.zone_order,10)}),a.each(b,function(a,b){c.renderRow(b)})):c.$el.append(j),c.initRows()},renderRow:function(a){var b=this;b.$el.append(b.rowTemplate(a)),b.initRow(a)},initRow:function(a){var b=this,c=b.$el.find('tr[data-id="'+a.zone_id+'"]');_.each(a.zone_locations,function(a){if("string"===jQuery.type(a))c.find('option[value="'+a+'"]').prop("selected",!0);else if("postcode"===a.type){var b=c.find(".wc-shipping-zone-postcodes :input");b.val()?b.val(b.val()+"\n"+a.code):b.val(a.code),c.find(".wc-shipping-zone-postcodes").show(),c.find(".wc-shipping-zone-postcodes-toggle").hide()}else c.find('option[value="'+a.type+":"+a.code+'"]').prop("selected",!0)}),a.zone_postcodes&&_.each(a.zone_postcodes,function(a){var b=c.find(".wc-shipping-zone-postcodes :input");b.val()?b.val(b.val()+"\n"+a.code):b.val(a.code),c.find(".wc-shipping-zone-postcodes").show(),c.find(".wc-shipping-zone-postcodes-toggle").hide()}),b.renderShippingMethods(a.zone_id,a.shipping_methods),c.find(".view").show(),c.find(".edit").hide(),c.find(".wc-shipping-zone-edit").on("click",{view:this},this.onEditRow),c.find(".wc-shipping-zone-cancel-edit").on("click",{view:this},this.onCancelEditRow),c.find(".wc-shipping-zone-delete").on("click",{view:this},this.onDeleteRow),c.find(".wc-shipping-zone-postcodes-toggle").on("click",{view:this},this.onTogglePostcodes),!0===a.editing&&(c.addClass("editing"),c.find(".wc-shipping-zone-edit").trigger("click"))},initRows:function(){0===a("tbody.wc-shipping-zone-rows tr").length%2?f.find("tbody.wc-shipping-zone-rows").next("tbody").find("tr").addClass("odd"):f.find("tbody.wc-shipping-zone-rows").next("tbody").find("tr").removeClass("odd"),a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:50})},renderShippingMethods:function(b,c){var d=a('.wc-shipping-zones tr[data-id="'+b+'"]'),e=d.find(".wc-shipping-zone-methods ul");e.find(".wc-shipping-zone-method").remove(),_.size(c)?_.each(c,function(a,b){var c="method_disabled";"yes"===a.enabled&&(c="method_enabled"),e.prepend('
  • '+a.title+"
  • ")}):e.prepend('
  • ')},onSubmit:function(a){a.data.view.block(),a.data.view.model.save(),a.preventDefault()},onAddNewRow:function(a){a.preventDefault();var c=a.data.view,d=c.model,e=_.indexBy(d.get("zones"),"zone_id"),f={},g=_.size(e),h=_.extend({},b.default_zone,{zone_id:"new-"+g+"-"+Date.now(),zone_name:b.strings.default_zone_name,editing:!0});h.zone_order=1+_.max(_.pluck(e,"zone_order"),function(a){return parseInt(a,10)}),f[h.zone_id]=h,d.logChanges(f),c.renderRow(h),c.initRows()},onTogglePostcodes:function(b){b.preventDefault();var c=a(this).closest("tr");c.find(".wc-shipping-zone-postcodes").show(),c.find(".wc-shipping-zone-postcodes-toggle").hide()},onEditRow:function(b){b.preventDefault(),b.data.view.model.trigger("change:zones"),a(this).closest("tr").addClass("editing"),a(this).closest("tr").find(".view").hide(),a(this).closest("tr").find(".edit").show(),a(".wc-shipping-zone-region-select:not(.enhanced)").select2(k),a(".wc-shipping-zone-region-select:not(.enhanced)").addClass("enhanced");var c=a(this).closest("tr").find(".add_shipping_method");c.addClass("disabled"),c.tipTip({attribute:"data-disabled-tip",fadeIn:50,fadeOut:50,delay:50})},onCancelEditRow:function(b){var c=b.data.view,d=c.model,e=a(this).closest("tr"),f=e.data("id"),g=_.indexBy(d.get("zones"),"zone_id");b.preventDefault(),d.discardChanges(f),g[f]&&(g[f].editing=!1,e.after(c.rowTemplate(g[f])),c.initRow(g[f])),e.remove(),c.initRows()},onDeleteRow:function(b){var c=b.data.view,d=c.model,e=_.indexBy(d.get("zones"),"zone_id"),f={},g=a(this).closest("tr"),h=a(this).closest("tr").data("id");b.preventDefault(),e[h]&&(delete e[h],f[h]=_.extend(f[h]||{},{deleted:"deleted"}),d.set("zones",e),d.logChanges(f)),g.remove(),c.initRows()},setUnloadConfirmation:function(){this.needsUnloadConfirm=!0,h.prop("disabled",!1)},clearUnloadConfirmation:function(){this.needsUnloadConfirm=!1,h.prop("disabled",!0)},unloadConfirmation:function(a){return a.data.view.needsUnloadConfirm?(a.returnValue=b.strings.unload_confirmation_msg,window.event.returnValue=b.strings.unload_confirmation_msg,b.strings.unload_confirmation_msg):void 0},updateModelOnChange:function(b){var c=b.data.view.model,d=a(b.target),e=d.closest("tr").data("id"),f=d.data("attribute"),g=d.val(),h=_.indexBy(c.get("zones"),"zone_id"),i={};h[e]&&h[e][f]===g||(i[e]={},i[e][f]=g),c.logChanges(i)},updateModelOnSort:function(b){var c=b.data.view,d=c.model,e=_.indexBy(d.get("zones"),"zone_id"),f=a("tbody.wc-shipping-zone-rows tr"),g={};_.each(f,function(b){var c=a(b).data("id"),d=null,f=parseInt(a(b).index(),10);e[c]&&(d=parseInt(e[c].zone_order,10)),d!==f&&(g[c]=_.extend(g[c]||{},{zone_order:f}))}),_.size(g)&&d.logChanges(g)},onAddShippingMethod:function(b){var c=a(this).closest("tr").data("id");b.preventDefault(),a(this).WCBackboneModal({template:"wc-modal-add-shipping-method",variable:{zone_id:c}}),a(".wc-shipping-zone-method-selector select").change()},onAddShippingMethodSubmitted:function(c,e,f){"wc-modal-add-shipping-method"===e&&(o.block(),a.post(d+(d.indexOf("?")>0?"&":"?")+"action=woocommerce_shipping_zone_add_method",{wc_shipping_zones_nonce:b.wc_shipping_zones_nonce,method_id:f.add_method_id,zone_id:f.zone_id},function(a,b){"success"===b&&a.success&&o.renderShippingMethods(f.zone_id,a.data.methods),o.unblock()},"json"))},onChangeShippingMethodSelector:function(){var b=a(this).find("option:selected").data("description");a(this).parent().find(".wc-shipping-zone-method-description").remove(),a(this).after('

    '+b+"

    "),a(this).closest("article").height(a(this).parent().height())}}),n=new l({zones:b.zones}),o=new m({model:n,el:g});o.render(),g.sortable({items:"tr",cursor:"move",axis:"y",handle:"td.wc-shipping-zone-sort",scrollSensitivity:40})})}(jQuery,shippingZonesLocalizeScript,wp,ajaxurl); \ No newline at end of file diff --git a/assets/js/admin/woocommerce_admin.js b/assets/js/admin/woocommerce_admin.js index be14474be02..9059a6219ce 100644 --- a/assets/js/admin/woocommerce_admin.js +++ b/assets/js/admin/woocommerce_admin.js @@ -7,10 +7,11 @@ jQuery( function ( $ ) { // Field validation error tips $( document.body ) + .on( 'wc_add_error_tip', function( e, element, error_type ) { var offset = element.position(); - if ( element.parent().find( '.wc_error_tip' ).size() === 0 ) { + if ( element.parent().find( '.wc_error_tip' ).length === 0 ) { element.after( '
    ' + woocommerce_admin[error_type] + '
    ' ); element.parent().find( '.wc_error_tip' ) .css( 'left', offset.left + element.width() - ( element.width() / 2 ) - ( $( '.wc_error_tip' ).width() / 2 ) ) @@ -18,51 +19,61 @@ jQuery( function ( $ ) { .fadeIn( '100' ); } }) + .on( 'wc_remove_error_tip', function( e, element, error_type ) { - element.parent().find( '.wc_error_tip.' + error_type ).remove(); + element.parent().find( '.wc_error_tip.' + error_type ).fadeOut( '100', function() { $( this ).remove(); } ); }) + .on( 'click', function() { $( '.wc_error_tip' ).fadeOut( '100', function() { $( this ).remove(); } ); }) + .on( 'blur', '.wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]', function() { $( '.wc_error_tip' ).fadeOut( '100', function() { $( this ).remove(); } ); }) - .on( 'keyup change', '.wc_input_price[type=text]', function() { + + .on( 'change', '.wc_input_price[type=text], .wc_input_decimal[type=text]', function() { + var regex; + + if ( $( this ).is( '.wc_input_price' ) ) { + regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' ); + } else { + regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' ); + } + var value = $( this ).val(); - var regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' ); var newvalue = value.replace( regex, '' ); if ( value !== newvalue ) { $( this ).val( newvalue ); - $( document.body ).triggerHandler( 'wc_add_error_tip', [ $( this ), 'i18n_mon_decimal_error' ] ); - } else { - $( document.body ).triggerHandler( 'wc_remove_error_tip', [ $( this ), 'i18n_mon_decimal_error' ] ); } }) - .on( 'keyup change', '.wc_input_decimal[type=text]', function() { + + .on( 'keyup', '.wc_input_price[type=text], .wc_input_decimal[type=text], .wc_input_country_iso[type=text]', function() { + var regex, error; + + if ( $( this ).is( '.wc_input_price' ) ) { + regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.mon_decimal_point + ']+', 'gi' ); + error = 'i18n_mon_decimal_error'; + } else if ( $( this ).is( '.wc_input_country_iso' ) ) { + regex = new RegExp( '([^A-Z])+|(.){3,}', 'im' ); + error = 'i18n_country_iso_error'; + } else { + regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' ); + error = 'i18n_decimal_error'; + } + var value = $( this ).val(); - var regex = new RegExp( '[^\-0-9\%\\' + woocommerce_admin.decimal_point + ']+', 'gi' ); var newvalue = value.replace( regex, '' ); if ( value !== newvalue ) { - $( this ).val( newvalue ); - $( document.body ).triggerHandler( 'wc_add_error_tip', [ $( this ), 'i18n_decimal_error' ] ); + $( document.body ).triggerHandler( 'wc_add_error_tip', [ $( this ), error ] ); } else { - $( document.body ).triggerHandler( 'wc_remove_error_tip', [ $( this ), 'i18n_decimal_error' ] ); + $( document.body ).triggerHandler( 'wc_remove_error_tip', [ $( this ), error ] ); } }) - .on( 'keyup change', '.wc_input_country_iso[type=text]', function() { - var value = $( this ).val(); - var regex = new RegExp( '^([A-Z])?([A-Z])$' ); - if ( ! regex.test( value ) ) { - $( this ).val( '' ); - $( document.body ).triggerHandler( 'wc_add_error_tip', [ $( this ), 'i18n_country_iso_error' ] ); - } else { - $( document.body ).triggerHandler( 'wc_remove_error_tip', [ $( this ), 'i18n_country_iso_error' ] ); - } - }) - .on( 'keyup change', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function() { + .on( 'keyup', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function() { var sale_price_field = $( this ), regular_price_field; if( sale_price_field.attr( 'name' ).indexOf( 'variable' ) !== -1 ) { @@ -79,21 +90,43 @@ jQuery( function ( $ ) { } else { $( document.body ).triggerHandler( 'wc_remove_error_tip', [ $(this), 'i18_sale_less_than_regular_error' ] ); } + }) + + .on( 'change', '#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]', function() { + var sale_price_field = $( this ), regular_price_field; + + if( sale_price_field.attr( 'name' ).indexOf( 'variable' ) !== -1 ) { + regular_price_field = sale_price_field.parents( '.variable_pricing' ).find( '.wc_input_price[name^=variable_regular_price]' ); + } else { + regular_price_field = $( '#_regular_price' ); + } + + var sale_price = parseFloat( window.accounting.unformat( sale_price_field.val(), woocommerce_admin.mon_decimal_point ) ); + var regular_price = parseFloat( window.accounting.unformat( regular_price_field.val(), woocommerce_admin.mon_decimal_point ) ); + + if ( sale_price >= regular_price ) { + $( this ).val( '' ); + } + }) + + .on( 'init_tooltips', function() { + var tiptip_args = { + 'attribute': 'data-tip', + 'fadeIn': 50, + 'fadeOut': 50, + 'delay': 200 + }; + + $( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip( tiptip_args ); + + // Add tiptip to parent element for widefat tables + $( '.parent-tips' ).each( function() { + $( this ).closest( 'a, th' ).attr( 'data-tip', $( this ).data( 'tip' ) ).tipTip( tiptip_args ).css( 'cursor', 'help' ); + }); }); // Tooltips - var tiptip_args = { - 'attribute': 'data-tip', - 'fadeIn': 50, - 'fadeOut': 50, - 'delay': 200 - }; - $( '.tips, .help_tip, .woocommerce-help-tip' ).tipTip( tiptip_args ); - - // Add tiptip to parent element for widefat tables - $( '.parent-tips' ).each( function() { - $( this ).closest( 'a, th' ).attr( 'data-tip', $( this ).data( 'tip' ) ).tipTip( tiptip_args ).css( 'cursor', 'help' ); - }); + $( document.body ).trigger( 'init_tooltips' ); // wc_input_table tables $( '.wc_input_table.sortable tbody' ).sortable({ @@ -115,7 +148,7 @@ jQuery( function ( $ ) { $( '.wc_input_table .remove_rows' ).click( function() { var $tbody = $( this ).closest( '.wc_input_table' ).find( 'tbody' ); - if ( $tbody.find( 'tr.current' ).size() > 0 ) { + if ( $tbody.find( 'tr.current' ).length > 0 ) { var $current = $tbody.find( 'tr.current' ); $current.each( function() { $( this ).remove(); @@ -125,15 +158,16 @@ jQuery( function ( $ ) { }); var controlled = false; - var shifted = false; - var hasFocus = false; + var shifted = false; + var hasFocus = false; $( document.body ).bind( 'keyup keydown', function( e ) { - shifted = e.shiftKey; controlled = e.ctrlKey || e.metaKey; + shifted = e.shiftKey; + controlled = e.ctrlKey || e.metaKey; }); $( '.wc_input_table' ).on( 'focus click', 'input', function( e ) { - var $this_table = $( this ).closest( 'table' ); + var $this_table = $( this ).closest( 'table, tbody' ); var $this_row = $( this ).closest( 'tr' ); if ( ( e.type === 'focus' && hasFocus !== $this_row.index() ) || ( e.type === 'click' && $( this ).is( ':focus' ) ) ) { @@ -146,7 +180,7 @@ jQuery( function ( $ ) { $( 'tr', $this_table ).removeClass( 'current' ); $this_row.addClass( 'selected_now' ).addClass( 'current' ); - if ( $( 'tr.last_selected', $this_table ).size() > 0 ) { + if ( $( 'tr.last_selected', $this_table ).length > 0 ) { if ( $this_row.index() > $( 'tr.last_selected', $this_table ).index() ) { $( 'tr', $this_table ).slice( $( 'tr.last_selected', $this_table ).index(), $this_row.index() ).addClass( 'current' ); } else { @@ -221,4 +255,11 @@ jQuery( function ( $ ) { // Attribute term table $( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' ); + + // Load videos when help button is clicked. + $( '#contextual-help-link' ).on( 'click', function() { + var frame = $( '#tab-panel-woocommerce_101_tab iframe' ); + + frame.attr( 'src', frame.data( 'src' ) ); + }); }); diff --git a/assets/js/admin/woocommerce_admin.min.js b/assets/js/admin/woocommerce_admin.min.js index 73564cbb26c..8da80726906 100644 --- a/assets/js/admin/woocommerce_admin.min.js +++ b/assets/js/admin/woocommerce_admin.min.js @@ -1 +1 @@ -jQuery(function(a){a(document.body).on("wc_add_error_tip",function(b,c,d){var e=c.position();0===c.parent().find(".wc_error_tip").size()&&(c.after('
    '+woocommerce_admin[d]+"
    "),c.parent().find(".wc_error_tip").css("left",e.left+c.width()-c.width()/2-a(".wc_error_tip").width()/2).css("top",e.top+c.height()).fadeIn("100"))}).on("wc_remove_error_tip",function(a,b,c){b.parent().find(".wc_error_tip."+c).remove()}).on("click",function(){a(".wc_error_tip").fadeOut("100",function(){a(this).remove()})}).on("blur",".wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]",function(){a(".wc_error_tip").fadeOut("100",function(){a(this).remove()})}).on("keyup change",".wc_input_price[type=text]",function(){var b=a(this).val(),c=new RegExp("[^-0-9%\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),d=b.replace(c,"");b!==d?(a(this).val(d),a(document.body).triggerHandler("wc_add_error_tip",[a(this),"i18n_mon_decimal_error"])):a(document.body).triggerHandler("wc_remove_error_tip",[a(this),"i18n_mon_decimal_error"])}).on("keyup change",".wc_input_decimal[type=text]",function(){var b=a(this).val(),c=new RegExp("[^-0-9%\\"+woocommerce_admin.decimal_point+"]+","gi"),d=b.replace(c,"");b!==d?(a(this).val(d),a(document.body).triggerHandler("wc_add_error_tip",[a(this),"i18n_decimal_error"])):a(document.body).triggerHandler("wc_remove_error_tip",[a(this),"i18n_decimal_error"])}).on("keyup change",".wc_input_country_iso[type=text]",function(){var b=a(this).val(),c=new RegExp("^([A-Z])?([A-Z])$");c.test(b)?a(document.body).triggerHandler("wc_remove_error_tip",[a(this),"i18n_country_iso_error"]):(a(this).val(""),a(document.body).triggerHandler("wc_add_error_tip",[a(this),"i18n_country_iso_error"]))}).on("keyup change","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var b,c=a(this);b=-1!==c.attr("name").indexOf("variable")?c.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]"):a("#_regular_price");var d=parseFloat(window.accounting.unformat(c.val(),woocommerce_admin.mon_decimal_point)),e=parseFloat(window.accounting.unformat(b.val(),woocommerce_admin.mon_decimal_point));d>=e?a(document.body).triggerHandler("wc_add_error_tip",[a(this),"i18_sale_less_than_regular_error"]):a(document.body).triggerHandler("wc_remove_error_tip",[a(this),"i18_sale_less_than_regular_error"])});var b={attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200};a(".tips, .help_tip, .woocommerce-help-tip").tipTip(b),a(".parent-tips").each(function(){a(this).closest("a, th").attr("data-tip",a(this).data("tip")).tipTip(b).css("cursor","help")}),a(".wc_input_table.sortable tbody").sortable({items:"tr",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")}}),a(".wc_input_table .remove_rows").click(function(){var b=a(this).closest(".wc_input_table").find("tbody");if(b.find("tr.current").size()>0){var c=b.find("tr.current");c.each(function(){a(this).remove()})}return!1});var c=!1,d=!1,e=!1;a(document.body).bind("keyup keydown",function(a){d=a.shiftKey,c=a.ctrlKey||a.metaKey}),a(".wc_input_table").on("focus click","input",function(b){var f=a(this).closest("table"),g=a(this).closest("tr");("focus"===b.type&&e!==g.index()||"click"===b.type&&a(this).is(":focus"))&&(e=g.index(),d||c?d?(a("tr",f).removeClass("current"),g.addClass("selected_now").addClass("current"),a("tr.last_selected",f).size()>0&&(g.index()>a("tr.last_selected",f).index()?a("tr",f).slice(a("tr.last_selected",f).index(),g.index()).addClass("current"):a("tr",f).slice(g.index(),a("tr.last_selected",f).index()+1).addClass("current")),a("tr",f).removeClass("last_selected"),g.addClass("last_selected")):(a("tr",f).removeClass("last_selected"),c&&a(this).closest("tr").is(".current")?g.removeClass("current"):g.addClass("current").addClass("last_selected")):(a("tr",f).removeClass("current").removeClass("last_selected"),g.addClass("current").addClass("last_selected")),a("tr",f).removeClass("selected_now"))}).on("blur","input",function(){e=!1}),a(".woocommerce_page_wc-settings .shippingrows tbody tr:even, table.attributes-table tbody tr:nth-child(odd)").addClass("alternate"),a(document.body).on("click",".show_order_items",function(){return a(this).closest("td").find("table").toggle(),!1}),a("select.availability").change(function(){"all"===a(this).val()?a(this).closest("tr").next("tr").hide():a(this).closest("tr").next("tr").show()}).change(),a(".hide_options_if_checked").each(function(){a(this).find("input:eq(0)").change(function(){a(this).is(":checked")?a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide():a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show()}).change()}),a(".show_options_if_checked").each(function(){a(this).find("input:eq(0)").change(function(){a(this).is(":checked")?a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show():a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide()}).change()}),a("input#woocommerce_demo_store").change(function(){a(this).is(":checked")?a("#woocommerce_demo_store_notice").closest("tr").show():a("#woocommerce_demo_store_notice").closest("tr").hide()}).change(),a("table.attributes-table tbody tr:nth-child(odd)").addClass("alternate")}); \ No newline at end of file +jQuery(function(a){a(document.body).on("wc_add_error_tip",function(b,c,d){var e=c.position();0===c.parent().find(".wc_error_tip").length&&(c.after('
    '+woocommerce_admin[d]+"
    "),c.parent().find(".wc_error_tip").css("left",e.left+c.width()-c.width()/2-a(".wc_error_tip").width()/2).css("top",e.top+c.height()).fadeIn("100"))}).on("wc_remove_error_tip",function(b,c,d){c.parent().find(".wc_error_tip."+d).fadeOut("100",function(){a(this).remove()})}).on("click",function(){a(".wc_error_tip").fadeOut("100",function(){a(this).remove()})}).on("blur",".wc_input_decimal[type=text], .wc_input_price[type=text], .wc_input_country_iso[type=text]",function(){a(".wc_error_tip").fadeOut("100",function(){a(this).remove()})}).on("change",".wc_input_price[type=text], .wc_input_decimal[type=text]",function(){var b;b=a(this).is(".wc_input_price")?new RegExp("[^-0-9%\\"+woocommerce_admin.mon_decimal_point+"]+","gi"):new RegExp("[^-0-9%\\"+woocommerce_admin.decimal_point+"]+","gi");var c=a(this).val(),d=c.replace(b,"");c!==d&&a(this).val(d)}).on("keyup",".wc_input_price[type=text], .wc_input_decimal[type=text], .wc_input_country_iso[type=text]",function(){var b,c;a(this).is(".wc_input_price")?(b=new RegExp("[^-0-9%\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),c="i18n_mon_decimal_error"):a(this).is(".wc_input_country_iso")?(b=new RegExp("([^A-Z])+|(.){3,}","im"),c="i18n_country_iso_error"):(b=new RegExp("[^-0-9%\\"+woocommerce_admin.decimal_point+"]+","gi"),c="i18n_decimal_error");var d=a(this).val(),e=d.replace(b,"");d!==e?a(document.body).triggerHandler("wc_add_error_tip",[a(this),c]):a(document.body).triggerHandler("wc_remove_error_tip",[a(this),c])}).on("keyup","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var b,c=a(this);b=-1!==c.attr("name").indexOf("variable")?c.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]"):a("#_regular_price");var d=parseFloat(window.accounting.unformat(c.val(),woocommerce_admin.mon_decimal_point)),e=parseFloat(window.accounting.unformat(b.val(),woocommerce_admin.mon_decimal_point));d>=e?a(document.body).triggerHandler("wc_add_error_tip",[a(this),"i18_sale_less_than_regular_error"]):a(document.body).triggerHandler("wc_remove_error_tip",[a(this),"i18_sale_less_than_regular_error"])}).on("change","#_sale_price.wc_input_price[type=text], .wc_input_price[name^=variable_sale_price]",function(){var b,c=a(this);b=-1!==c.attr("name").indexOf("variable")?c.parents(".variable_pricing").find(".wc_input_price[name^=variable_regular_price]"):a("#_regular_price");var d=parseFloat(window.accounting.unformat(c.val(),woocommerce_admin.mon_decimal_point)),e=parseFloat(window.accounting.unformat(b.val(),woocommerce_admin.mon_decimal_point));d>=e&&a(this).val("")}).on("init_tooltips",function(){var b={attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200};a(".tips, .help_tip, .woocommerce-help-tip").tipTip(b),a(".parent-tips").each(function(){a(this).closest("a, th").attr("data-tip",a(this).data("tip")).tipTip(b).css("cursor","help")})}),a(document.body).trigger("init_tooltips"),a(".wc_input_table.sortable tbody").sortable({items:"tr",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(a,b){b.item.css("background-color","#f6f6f6")},stop:function(a,b){b.item.removeAttr("style")}}),a(".wc_input_table .remove_rows").click(function(){var b=a(this).closest(".wc_input_table").find("tbody");if(b.find("tr.current").length>0){var c=b.find("tr.current");c.each(function(){a(this).remove()})}return!1});var b=!1,c=!1,d=!1;a(document.body).bind("keyup keydown",function(a){c=a.shiftKey,b=a.ctrlKey||a.metaKey}),a(".wc_input_table").on("focus click","input",function(e){var f=a(this).closest("table, tbody"),g=a(this).closest("tr");("focus"===e.type&&d!==g.index()||"click"===e.type&&a(this).is(":focus"))&&(d=g.index(),c||b?c?(a("tr",f).removeClass("current"),g.addClass("selected_now").addClass("current"),a("tr.last_selected",f).length>0&&(g.index()>a("tr.last_selected",f).index()?a("tr",f).slice(a("tr.last_selected",f).index(),g.index()).addClass("current"):a("tr",f).slice(g.index(),a("tr.last_selected",f).index()+1).addClass("current")),a("tr",f).removeClass("last_selected"),g.addClass("last_selected")):(a("tr",f).removeClass("last_selected"),b&&a(this).closest("tr").is(".current")?g.removeClass("current"):g.addClass("current").addClass("last_selected")):(a("tr",f).removeClass("current").removeClass("last_selected"),g.addClass("current").addClass("last_selected")),a("tr",f).removeClass("selected_now"))}).on("blur","input",function(){d=!1}),a(".woocommerce_page_wc-settings .shippingrows tbody tr:even, table.attributes-table tbody tr:nth-child(odd)").addClass("alternate"),a(document.body).on("click",".show_order_items",function(){return a(this).closest("td").find("table").toggle(),!1}),a("select.availability").change(function(){"all"===a(this).val()?a(this).closest("tr").next("tr").hide():a(this).closest("tr").next("tr").show()}).change(),a(".hide_options_if_checked").each(function(){a(this).find("input:eq(0)").change(function(){a(this).is(":checked")?a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide():a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show()}).change()}),a(".show_options_if_checked").each(function(){a(this).find("input:eq(0)").change(function(){a(this).is(":checked")?a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show():a(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide()}).change()}),a("input#woocommerce_demo_store").change(function(){a(this).is(":checked")?a("#woocommerce_demo_store_notice").closest("tr").show():a("#woocommerce_demo_store_notice").closest("tr").hide()}).change(),a("table.attributes-table tbody tr:nth-child(odd)").addClass("alternate"),a("#contextual-help-link").on("click",function(){var b=a("#tab-panel-woocommerce_101_tab iframe");b.attr("src",b.data("src"))})}); \ No newline at end of file diff --git a/assets/js/chosen/ajax-chosen.jquery.js b/assets/js/chosen/ajax-chosen.jquery.js deleted file mode 100644 index f823a9b103d..00000000000 --- a/assets/js/chosen/ajax-chosen.jquery.js +++ /dev/null @@ -1,81 +0,0 @@ -// Generated by CoffeeScript 1.3.1 - -(function($) { - return $.fn.ajaxChosen = function(settings, callback) { - var chosenXhr, defaultOptions, options, select; - if (settings == null) { - settings = {}; - } - if (callback == null) { - callback = function() {}; - } - defaultOptions = { - minTermLength: 3, - afterTypeDelay: 500, - jsonTermKey: "term" - }; - select = this; - chosenXhr = null; - options = $.extend({}, defaultOptions, settings); - this.chosen(); - return this.each(function() { - return $(this).next('.chosen-container').find(".search-field > input, .chosen-search > input").bind('keyup', function() { - var field, msg, success, val; - val = $.trim($(this).attr('value')); - msg = val.length < options.minTermLength ? "Keep typing..." : "Looking for '" + val + "'"; - select.next('.chosen-container').find('.no-results').text(msg); - if (val === $(this).data('prevVal')) { - return false; - } - $(this).data('prevVal', val); - if (this.timer) { - clearTimeout(this.timer); - } - if (val.length < options.minTermLength) { - return false; - } - field = $(this); - if (!(options.data != null)) { - options.data = {}; - } - options.data[options.jsonTermKey] = val; - if (options.dataCallback != null) { - options.data = options.dataCallback(options.data); - } - success = options.success; - options.success = function(data) { - var items, selected_values; - if (!(data != null)) { - return; - } - selected_values = []; - select.find('option').each(function() { - if (!$(this).is(":selected")) { - return $(this).remove(); - } else { - return selected_values.push($(this).val() + "-" + $(this).text()); - } - }); - items = callback(data); - $.each(items, function(value, text) { - if ($.inArray(value + "-" + text, selected_values) === -1) { - return $("