api-keys.js
5 years ago
api-keys.min.js
5 years ago
backbone-modal.js
5 years ago
backbone-modal.min.js
5 years ago
marketplace-suggestions.js
4 years ago
marketplace-suggestions.min.js
3 years ago
meta-boxes-coupon.js
5 years ago
meta-boxes-coupon.min.js
3 years ago
meta-boxes-order.js
3 years ago
meta-boxes-order.min.js
3 years ago
meta-boxes-product-variation.js
3 years ago
meta-boxes-product-variation.min.js
3 years ago
meta-boxes-product.js
3 years ago
meta-boxes-product.min.js
3 years ago
meta-boxes.js
3 years ago
meta-boxes.min.js
3 years ago
network-orders.js
8 years ago
network-orders.min.js
3 years ago
product-editor.js
3 years ago
product-editor.min.js
3 years ago
product-ordering.js
3 years ago
product-ordering.min.js
3 years ago
quick-edit.js
4 years ago
quick-edit.min.js
3 years ago
reports.js
5 years ago
reports.min.js
3 years ago
settings-views-html-settings-tax.js
5 years ago
settings-views-html-settings-tax.min.js
3 years ago
settings.js
4 years ago
settings.min.js
3 years ago
system-status.js
3 years ago
system-status.min.js
3 years ago
term-ordering.js
3 years ago
term-ordering.min.js
3 years ago
users.js
5 years ago
users.min.js
3 years ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-enhanced-select.js
3 years ago
wc-enhanced-select.min.js
3 years ago
wc-orders.js
3 years ago
wc-orders.min.js
3 years ago
wc-product-export.js
5 years ago
wc-product-export.min.js
5 years ago
wc-product-import.js
3 years ago
wc-product-import.min.js
3 years ago
wc-setup.js
5 years ago
wc-setup.min.js
3 years ago
wc-shipping-classes.js
5 years ago
wc-shipping-classes.min.js
3 years ago
wc-shipping-zone-methods.js
4 years ago
wc-shipping-zone-methods.min.js
3 years ago
wc-shipping-zones.js
4 years ago
wc-shipping-zones.min.js
3 years ago
wc-status-widget.js
4 years ago
wc-status-widget.min.js
4 years ago
woocommerce_admin.js
3 years ago
woocommerce_admin.min.js
3 years ago
wc-setup.js
323 lines
| 1 | /*global wc_setup_params */ |
| 2 | /*global wc_setup_currencies */ |
| 3 | /*global wc_base_state */ |
| 4 | /* @deprecated 4.6.0 */ |
| 5 | jQuery( function( $ ) { |
| 6 | function blockWizardUI() { |
| 7 | $('.wc-setup-content').block({ |
| 8 | message: null, |
| 9 | overlayCSS: { |
| 10 | background: '#fff', |
| 11 | opacity: 0.6 |
| 12 | } |
| 13 | }); |
| 14 | } |
| 15 | |
| 16 | $( '.button-next' ).on( 'click', function() { |
| 17 | var form = $( this ).parents( 'form' ).get( 0 ); |
| 18 | |
| 19 | if ( ( 'function' !== typeof form.checkValidity ) || form.checkValidity() ) { |
| 20 | blockWizardUI(); |
| 21 | } |
| 22 | |
| 23 | return true; |
| 24 | } ); |
| 25 | |
| 26 | $( 'form.address-step' ).on( 'submit', function( e ) { |
| 27 | var form = $( this ); |
| 28 | if ( ( 'function' !== typeof form.checkValidity ) || form.checkValidity() ) { |
| 29 | blockWizardUI(); |
| 30 | } |
| 31 | |
| 32 | e.preventDefault(); |
| 33 | $('.wc-setup-content').unblock(); |
| 34 | |
| 35 | $( this ).WCBackboneModal( { |
| 36 | template: 'wc-modal-tracking-setup' |
| 37 | } ); |
| 38 | |
| 39 | $( document.body ).on( 'wc_backbone_modal_response', function() { |
| 40 | form.off( 'submit' ).trigger( 'submit' ); |
| 41 | } ); |
| 42 | |
| 43 | $( '#wc_tracker_checkbox_dialog' ).on( 'change', function( e ) { |
| 44 | var eventTarget = $( e.target ); |
| 45 | $( '#wc_tracker_checkbox' ).prop( 'checked', eventTarget.prop( 'checked' ) ); |
| 46 | } ); |
| 47 | |
| 48 | $( '#wc_tracker_submit' ).on( 'click', function () { |
| 49 | form.off( 'submit' ).trigger( 'submit' ); |
| 50 | } ); |
| 51 | |
| 52 | return true; |
| 53 | } ); |
| 54 | |
| 55 | $( '#store_country' ).on( 'change', function() { |
| 56 | // Prevent if we don't have the metabox data |
| 57 | if ( wc_setup_params.states === null ){ |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | var $this = $( this ), |
| 62 | country = $this.val(), |
| 63 | $state_select = $( '#store_state' ); |
| 64 | |
| 65 | if ( ! $.isEmptyObject( wc_setup_params.states[ country ] ) ) { |
| 66 | var states = wc_setup_params.states[ country ]; |
| 67 | |
| 68 | $state_select.empty(); |
| 69 | |
| 70 | $.each( states, function( index ) { |
| 71 | $state_select.append( $( '<option value="' + index + '">' + states[ index ] + '</option>' ) ); |
| 72 | } ); |
| 73 | |
| 74 | $( '.store-state-container' ).show(); |
| 75 | $state_select.selectWoo().val( wc_base_state ).trigger( 'change' ).prop( 'required', true ); |
| 76 | } else { |
| 77 | $( '.store-state-container' ).hide(); |
| 78 | $state_select.empty().val( '' ).trigger( 'change' ).prop( 'required', false ); |
| 79 | } |
| 80 | |
| 81 | $( '#currency_code' ).val( wc_setup_currencies[ country ] ).trigger( 'change' ); |
| 82 | } ); |
| 83 | |
| 84 | /* Setup postcode field and validations */ |
| 85 | $( '#store_country' ).on( 'change', function() { |
| 86 | if ( ! wc_setup_params.postcodes ) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | var $this = $( this ), |
| 91 | country = $this.val(), |
| 92 | $store_postcode_input = $( '#store_postcode' ), |
| 93 | country_postcode_obj = wc_setup_params.postcodes[ country ]; |
| 94 | |
| 95 | // Default to required, if its unknown whether postcode is required or not. |
| 96 | if ( $.isEmptyObject( country_postcode_obj ) || country_postcode_obj.required ) { |
| 97 | $store_postcode_input.attr( 'required', 'true' ); |
| 98 | } else { |
| 99 | $store_postcode_input.prop( 'required', false ); |
| 100 | } |
| 101 | } ); |
| 102 | |
| 103 | $( '#store_country' ).trigger( 'change' ); |
| 104 | |
| 105 | $( '.wc-wizard-services' ).on( 'change', '.wc-wizard-service-enable input', function() { |
| 106 | if ( $( this ).is( ':checked' ) ) { |
| 107 | $( this ).closest( '.wc-wizard-service-toggle' ).removeClass( 'disabled' ); |
| 108 | $( this ).closest( '.wc-wizard-service-item' ).addClass( 'checked' ); |
| 109 | $( this ).closest( '.wc-wizard-service-item' ) |
| 110 | .find( '.wc-wizard-service-settings' ).removeClass( 'hide' ); |
| 111 | } else { |
| 112 | $( this ).closest( '.wc-wizard-service-toggle' ).addClass( 'disabled' ); |
| 113 | $( this ).closest( '.wc-wizard-service-item' ).removeClass( 'checked' ); |
| 114 | $( this ).closest( '.wc-wizard-service-item' ) |
| 115 | .find( '.wc-wizard-service-settings' ).addClass( 'hide' ); |
| 116 | } |
| 117 | } ); |
| 118 | |
| 119 | $( '.wc-wizard-services' ).on( 'keyup', function( e ) { |
| 120 | var code = e.keyCode || e.which, |
| 121 | $focused = $( document.activeElement ); |
| 122 | |
| 123 | if ( $focused.is( '.wc-wizard-service-toggle, .wc-wizard-service-enable' ) && ( 13 === code || 32 === code ) ) { |
| 124 | $focused.find( ':input' ).trigger( 'click' ); |
| 125 | } |
| 126 | } ); |
| 127 | |
| 128 | $( '.wc-wizard-services' ).on( 'click', '.wc-wizard-service-enable', function( e ) { |
| 129 | var eventTarget = $( e.target ); |
| 130 | |
| 131 | if ( eventTarget.is( 'input' ) ) { |
| 132 | e.stopPropagation(); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | var $checkbox = $( this ).find( 'input[type="checkbox"]' ); |
| 137 | |
| 138 | $checkbox.prop( 'checked', ! $checkbox.prop( 'checked' ) ).trigger( 'change' ); |
| 139 | } ); |
| 140 | |
| 141 | $( '.wc-wizard-services-list-toggle' ).on( 'click', function() { |
| 142 | var listToggle = $( this ).closest( '.wc-wizard-services-list-toggle' ); |
| 143 | |
| 144 | if ( listToggle.hasClass( 'closed' ) ) { |
| 145 | listToggle.removeClass( 'closed' ); |
| 146 | } else { |
| 147 | listToggle.addClass( 'closed' ); |
| 148 | } |
| 149 | |
| 150 | $( this ).closest( '.wc-wizard-services' ).find( '.wc-wizard-service-item' ) |
| 151 | .slideToggle() |
| 152 | .css( 'display', 'flex' ); |
| 153 | } ); |
| 154 | |
| 155 | $( '.wc-wizard-services' ).on( 'change', '.wc-wizard-shipping-method-select .method', function( e ) { |
| 156 | var zone = $( this ).closest( '.wc-wizard-service-description' ); |
| 157 | var selectedMethod = e.target.value; |
| 158 | |
| 159 | var description = zone.find( '.shipping-method-descriptions' ); |
| 160 | description.find( '.shipping-method-description' ).addClass( 'hide' ); |
| 161 | description.find( '.' + selectedMethod ).removeClass( 'hide' ); |
| 162 | |
| 163 | var $checkbox = zone.parent().find( 'input[type="checkbox"]' ); |
| 164 | var settings = zone.find( '.shipping-method-settings' ); |
| 165 | settings |
| 166 | .find( '.shipping-method-setting' ) |
| 167 | .addClass( 'hide' ) |
| 168 | .find( '.shipping-method-required-field' ) |
| 169 | .prop( 'required', false ); |
| 170 | settings |
| 171 | .find( '.' + selectedMethod ) |
| 172 | .removeClass( 'hide' ) |
| 173 | .find( '.shipping-method-required-field' ) |
| 174 | .prop( 'required', $checkbox.prop( 'checked' ) ); |
| 175 | } ).find( '.wc-wizard-shipping-method-select .method' ).trigger( 'change' ); |
| 176 | |
| 177 | $( '.wc-wizard-services' ).on( 'change', '.wc-wizard-shipping-method-enable', function() { |
| 178 | var checked = $( this ).is( ':checked' ); |
| 179 | var selectedMethod = $( this ) |
| 180 | .closest( '.wc-wizard-service-item' ) |
| 181 | .find( '.wc-wizard-shipping-method-select .method' ) |
| 182 | .val(); |
| 183 | |
| 184 | $( this ) |
| 185 | .closest( '.wc-wizard-service-item' ) |
| 186 | .find( '.' + selectedMethod ) |
| 187 | .find( '.shipping-method-required-field' ) |
| 188 | .prop( 'required', checked ); |
| 189 | } ); |
| 190 | |
| 191 | function submitActivateForm() { |
| 192 | $( 'form.activate-jetpack' ).trigger( 'submit' ); |
| 193 | } |
| 194 | |
| 195 | function waitForJetpackInstall() { |
| 196 | wp.ajax.post( 'setup_wizard_check_jetpack' ) |
| 197 | .then( function( result ) { |
| 198 | // If we receive success, or an unexpected result |
| 199 | // let the form submit. |
| 200 | if ( |
| 201 | ! result || |
| 202 | ! result.is_active || |
| 203 | 'yes' === result.is_active |
| 204 | ) { |
| 205 | return submitActivateForm(); |
| 206 | } |
| 207 | |
| 208 | // Wait until checking the status again |
| 209 | setTimeout( waitForJetpackInstall, 3000 ); |
| 210 | } ) |
| 211 | .fail( function() { |
| 212 | // Submit the form as normal if the request fails |
| 213 | submitActivateForm(); |
| 214 | } ); |
| 215 | } |
| 216 | |
| 217 | // Wait for a pending Jetpack install to finish before triggering a "save" |
| 218 | // on the activate step, which launches the Jetpack connection flow. |
| 219 | $( '.activate-jetpack' ).on( 'click', '.button-primary', function( e ) { |
| 220 | blockWizardUI(); |
| 221 | |
| 222 | if ( 'no' === wc_setup_params.pending_jetpack_install ) { |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | e.preventDefault(); |
| 227 | waitForJetpackInstall(); |
| 228 | } ); |
| 229 | |
| 230 | $( '.activate-new-onboarding' ).on( 'click', '.button-primary', function() { |
| 231 | // Show pending spinner while activate happens. |
| 232 | blockWizardUI(); |
| 233 | } ); |
| 234 | |
| 235 | $( '.wc-wizard-services' ).on( 'change', 'input#stripe_create_account, input#ppec_paypal_reroute_requests', function() { |
| 236 | if ( $( this ).is( ':checked' ) ) { |
| 237 | $( this ).closest( '.wc-wizard-service-settings' ) |
| 238 | .find( 'input.payment-email-input' ) |
| 239 | .attr( 'type', 'email' ) |
| 240 | .prop( 'disabled', false ) |
| 241 | .prop( 'required', true ); |
| 242 | } else { |
| 243 | $( this ).closest( '.wc-wizard-service-settings' ) |
| 244 | .find( 'input.payment-email-input' ) |
| 245 | .attr( 'type', null ) |
| 246 | .prop( 'disabled', true ) |
| 247 | .prop( 'required', false ); |
| 248 | } |
| 249 | } ).find( 'input#stripe_create_account, input#ppec_paypal_reroute_requests' ).trigger( 'change' ); |
| 250 | |
| 251 | function addPlugins( bySlug, $el, hover ) { |
| 252 | var plugins = $el.data( 'plugins' ); |
| 253 | for ( var i in Array.isArray( plugins ) ? plugins : [] ) { |
| 254 | var slug = plugins[ i ].slug; |
| 255 | bySlug[ slug ] = bySlug[ slug ] || |
| 256 | $( '<span class="plugin-install-info-list-item">' ) |
| 257 | .append( '<a href="https://wordpress.org/plugins/' + slug + '/" target="_blank">' + plugins[ i ].name + '</a>' ); |
| 258 | |
| 259 | bySlug[ slug ].find( 'a' ) |
| 260 | .on( 'mouseenter mouseleave', ( function( $hover, event ) { |
| 261 | $hover.toggleClass( 'plugin-install-source', 'mouseenter' === event.type ); |
| 262 | } ).bind( null, hover ? $el.closest( hover ) : $el ) ); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | function updatePluginInfo() { |
| 267 | var pluginLinkBySlug = {}; |
| 268 | var extraPlugins = []; |
| 269 | |
| 270 | $( '.wc-wizard-service-enable input:checked' ).each( function() { |
| 271 | addPlugins( pluginLinkBySlug, $( this ), '.wc-wizard-service-item' ); |
| 272 | |
| 273 | var $container = $( this ).closest( '.wc-wizard-service-item' ); |
| 274 | $container.find( 'input.payment-checkbox-input:checked' ).each( function() { |
| 275 | extraPlugins.push( $( this ).attr( 'id' ) ); |
| 276 | addPlugins( pluginLinkBySlug, $( this ), '.wc-wizard-service-settings' ); |
| 277 | } ); |
| 278 | $container.find( '.wc-wizard-shipping-method-select .method' ).each( function() { |
| 279 | var $this = $( this ); |
| 280 | if ( 'live_rates' === $this.val() ) { |
| 281 | addPlugins( pluginLinkBySlug, $this, '.wc-wizard-service-item' ); |
| 282 | } |
| 283 | } ); |
| 284 | } ); |
| 285 | |
| 286 | $( '.recommended-item input:checked' ).each( function() { |
| 287 | addPlugins( pluginLinkBySlug, $( this ), '.recommended-item' ); |
| 288 | } ); |
| 289 | |
| 290 | var $list = $( 'span.plugin-install-info-list' ).empty(); |
| 291 | |
| 292 | for ( var slug in pluginLinkBySlug ) { |
| 293 | $list.append( pluginLinkBySlug[ slug ] ); |
| 294 | } |
| 295 | |
| 296 | if ( |
| 297 | extraPlugins && |
| 298 | wc_setup_params.current_step && |
| 299 | wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ] && |
| 300 | wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ][ extraPlugins.join( ',' ) ] |
| 301 | ) { |
| 302 | $list.append( |
| 303 | wc_setup_params.i18n.extra_plugins[ wc_setup_params.current_step ][ extraPlugins.join( ',' ) ] |
| 304 | ); |
| 305 | } |
| 306 | |
| 307 | $( 'span.plugin-install-info' ).toggle( $list.children().length > 0 ); |
| 308 | } |
| 309 | |
| 310 | updatePluginInfo(); |
| 311 | $( '.wc-setup-content' ).on( 'change', '[data-plugins]', updatePluginInfo ); |
| 312 | |
| 313 | $( document.body ).on( 'init_tooltips', function() { |
| 314 | $( '.help_tip' ).tipTip( { |
| 315 | 'attribute': 'data-tip', |
| 316 | 'fadeIn': 50, |
| 317 | 'fadeOut': 50, |
| 318 | 'delay': 200, |
| 319 | 'defaultPosition': 'top' |
| 320 | } ); |
| 321 | } ).trigger( 'init_tooltips' ); |
| 322 | } ); |
| 323 |