diff --git a/plugins/woocommerce/changelog/update-shipping-modal-contents b/plugins/woocommerce/changelog/update-shipping-modal-contents new file mode 100644 index 00000000000..1ecd592cb67 --- /dev/null +++ b/plugins/woocommerce/changelog/update-shipping-modal-contents @@ -0,0 +1,4 @@ +Significance: patch +Type: update + +Update Shipping Class modals to new style \ No newline at end of file diff --git a/plugins/woocommerce/client/legacy/css/admin.scss b/plugins/woocommerce/client/legacy/css/admin.scss index 232ced2d578..38e230d78c3 100644 --- a/plugins/woocommerce/client/legacy/css/admin.scss +++ b/plugins/woocommerce/client/legacy/css/admin.scss @@ -4023,6 +4023,203 @@ table.wc_shipping { display: table-row-group; } +/** +* New Shipping Settings Refresh Modal Styles +**/ + +.wc-backbone-modal-add-shipping-method, +.wc-backbone-modal-shipping-method-settings, +.wc-shipping-class-modal { + font-family: $font-sf-pro-text; + font-size: 13px; + font-weight: 400; + line-height: 16px; + color: #1e1e1e; + + .button-primary, + .button-primary:hover, + .button-primary:focus { + background-color: #3858E9; + border-radius: 2px; + color: #FFFFFF; + border-color: #3858e9 + } + .button-primary:focus { + box-shadow: 0 0 0 1px #fff, 0 0 0 3px #3858E9; + } + .button-primary.disabled { + background-color: #3858E9 !important; + border-color: #3858E9 !important; + color: #8494EC !important; + } + + &.wc-backbone-modal .wc-backbone-modal-content { + border-radius: 8px; + border-top: 8px solid transparent; + border-bottom: 8px solid transparent; + max-width: 600px; + + @media screen and (max-width: 782px) { + border-radius: none; + border-top: none; + border-bottom: none; + } + } + + .wc-backbone-modal-main article { + padding: 0 32px 32px 32px; + + } + + .wc-backbone-modal-main header{ + padding: 20px 32px; + } + + .wc-backbone-modal-main footer { + padding: 20px 32px 12px 32px; + + } + + .wc-backbone-modal-main .wc-backbone-modal-header h1 { + font-weight: 400; + } + + .wc-backbone-modal-main .wc-backbone-modal-header { + background-color: #fff; + border-bottom: none; + font-size: 20px; + line-height: 28px; + + .modal-close-link { + border-left: none; + + &:hover { + background-color: #fff; + } + } + } + .wc-backbone-modal-main footer { + box-shadow: none; + border-top: 1px solid #E0E0E0; + background-color: #fff; + + .inner { + display: flex; + justify-content: space-between; + flex-direction: row-reverse; + } + + .wc-shipping-zone-method-modal-info { + display: flex; + align-items: center; + font-size: 11px; + font-weight: 500; + line-height: 16px; + color: #787C82; + + &.wc-shipping-zone-method-modal-info-inactive { + display: none; + } + } + + } + + .wc-shipping-zone-method-input { + input { + clip: rect(0 0 0 0); + clip-path: inset(100%); + height: 1px; + overflow: hidden; + position: absolute; + white-space: nowrap; + width: 1px; + + &:checked + label { + outline: 2px solid #3858E9; + + .dashicons-yes { + display: block; + } + } + } + + label { + display: block; + width: 100%; + padding: 20px 16px; + outline: 1px solid #DDDDDD; + margin: 12px 0; + border-radius: 4px; + } + } + + .dashicons-yes { + display: none; + color: #949494; + float: right; + } + + .woocommerce-help-tip { + color: #949494; + + &:after { + top: -6px; + font-size: 24px; + } + } + + .wc-shipping-zone-method-fields { + + & > label { + text-transform: uppercase; + font-size: 11px; + font-weight: 500; + line-height: 16px; + + & > .woocommerce-help-tip { + display: none; + } + } + + fieldset { + margin-bottom: 24px; + + input, + select { + margin: 6px 0; + padding: 12px; + font-size: 13px; + line-height: 16px; + + &:not([type="checkbox"]) { + width: 100%; + max-width: 100%; + } + &[type="checkbox"] { + border-radius: 2px; + margin: 4px 8px 6px 0; + + & + .woocommerce-help-tip { + margin: 6px 0 4px 8px; + } + } + } + } + } + + .wc-backbone-modal-action-inactive { + display: none; + } + + .wc-shipping-zone-method-fields-help-text, + .wc-shipping-class-modal-help-text { + font-size: 12px; + font-weight: 400; + line-height: 16px; + color: #757575; + } +} + table { tr, tr:hover { @@ -4039,11 +4236,6 @@ table { } .wc-shipping-class-modal { - font-family: $font-sf-pro-text; - font-size: 13px; - font-weight: 400; - line-height: 18px; - .edit { margin: 5px 0; } @@ -4052,28 +4244,27 @@ table { .edit > select { width: 100%; max-width: 100%; + padding: 12px; } .view { - font-weight: 600; - } - - .wc-shipping-class-modal-action-inactive { - display: none; + font-size: 11px; + font-weight: 500; + line-height: 16px; } .wc-shipping-class-modal-input { - padding: 10px 0; + padding: 0 0 24px 0; + + input { + font-size: 13px; + line-height: 16px; + } } .wc-shipping-class-count { display: none; } - - .wc-shipping-class-modal-help-text { - font-size: 12px; - line-height: 17px; - } } .wc-shipping-class-hide-sibling-view + .view { @@ -4477,8 +4668,6 @@ table.wc-shipping-classes { } .wc-modal-shipping-method-settings { - background: #f8f8f8; - padding: 1em !important; form .form-table { width: 100%; @@ -4531,24 +4720,6 @@ table.wc-shipping-classes { } } -.wc-backbone-modal .wc-shipping-zone-method-selector { - p { - margin-top: 0; - } - - .wc-shipping-zone-method-description { - margin: 0.75em 1px 0; - line-height: 1.5em; - color: #999; - font-style: italic; - } - - select { - width: 100%; - cursor: pointer; - } -} - img.help_tip { margin: 0 0 0 9px; vertical-align: middle; diff --git a/plugins/woocommerce/client/legacy/js/admin/wc-shipping-zone-methods.js b/plugins/woocommerce/client/legacy/js/admin/wc-shipping-zone-methods.js index 1430e8aa052..3b656737c04 100644 --- a/plugins/woocommerce/client/legacy/js/admin/wc-shipping-zone-methods.js +++ b/plugins/woocommerce/client/legacy/js/admin/wc-shipping-zone-methods.js @@ -105,6 +105,8 @@ $( document.body ).on( 'wc_backbone_modal_before_remove', this.onCloseConfigureShippingMethod ); $( document.body ).on( 'change', '.wc-shipping-zone-method-selector select', this.onChangeShippingMethodSelector ); $( document.body ).on( 'click', '.wc-shipping-zone-postcodes-toggle', this.onTogglePostcodes ); + $( document.body ).on( 'wc_backbone_modal_validation', { view: this }, this.validateFormArguments ); + $( document.body ).on( 'wc_backbone_modal_loaded', { view: this }, this.onModalLoaded ); }, onUpdateZoneRegionPicker: function( event ) { var value = event.detail, @@ -326,6 +328,8 @@ event.preventDefault(); + method.settings_html = shippingMethodView.reformatSettingsHTML( method.settings_html ); + $( this ).WCBackboneModal({ template : 'wc-modal-shipping-method-settings', variable : { @@ -400,6 +404,77 @@ $( '.wc-shipping-zone-method-selector select' ).trigger( 'change' ); }, + /** + * The settings HTML is controlled and built by the settings api, so in order to refactor the + * markup, it needs to be manipulated here. + */ + reformatSettingsHTML: function( html ) { + const htmlWithoutTables = this.replaceHTMLTables( html ); + const htmlWithMovedHelpTips = this.moveHTMLHelpTips( htmlWithoutTables ); + + return htmlWithMovedHelpTips; + }, + moveHTMLHelpTips: function( html ) { + // These help tips aren't moved. + const helpTipsToIgnore = [ 'woocommerce_flat_rate_cost' ]; + + const htmlContent = $( html ); + const labels = htmlContent.find( 'label' ); + labels.each( ( i ) => { + const label = $( labels[ i ] ); + const helpTip = label.find( '.woocommerce-help-tip' ); + + if ( helpTip.length === 0 ) { + return; + } + + const id = label.attr( 'for' ); + + if ( helpTipsToIgnore.includes( id ) ) { + return; + } + + // woocommerce_free_shipping_ignore_discounts gets a helpTip appended to its label. Otherwise, add the text as the last element in the fieldset. + if ( id === 'woocommerce_free_shipping_ignore_discounts' ) { + const input = htmlContent.find( `#${ id }` ); + const fieldset = input.closest( 'fieldset' ); + const inputLabel = fieldset.find( 'label' ); + inputLabel.append( helpTip ); + } else { + const text = helpTip.data( 'tip' ); + const input = htmlContent.find( `#${ id }` ); + const fieldset = input.closest( 'fieldset' ); + + if ( fieldset.length && fieldset.find( '.wc-shipping-zone-method-fields-help-text' ).length === 0 ) { + fieldset.append( `
${ text }
` ); + } + } + + // Coupon discounts doesn't get a title on Free Shipping. + if ( label.text().trim() === 'Coupons discounts' ) { + label.text( '' ); + } + + } ); + + return htmlContent.prop( 'outerHTML' ); + }, + replaceHTMLTables: function ( html ) { + // `` elements added by the Settings API need to be removed. + // Modern browsers won't interpret other table elements like `td` not in a `table`, so + // Removing the `table` is sufficient. + const htmlContent = $( html ); + const tables = htmlContent.find( 'table.form-table' ); + + tables.each( ( i ) => { + const table = $( tables[ i ] ); + const div = $( '
' ); + div.html( table.html() ); + table.replaceWith( div ); + } ); + + return htmlContent.prop('outerHTML'); + }, onAddShippingMethodSubmitted: function( event, target, posted_data, closeModal ) { if ( 'wc-modal-add-shipping-method' === target ) { shippingMethodView.block(); @@ -439,20 +514,24 @@ shippingMethodView.unblock(); - // Pop up next modal - $( this ).WCBackboneModal({ - template : 'wc-modal-shipping-method-settings', - variable : { - instance_id : instance_id, - method : method, - status : 'new' - }, - data : { - instance_id : instance_id, - method : method, - status : 'new' - } - }); + if ( method.settings_html ) { + method.settings_html = shippingMethodView.reformatSettingsHTML( method.settings_html ); + + // Pop up next modal + $( this ).WCBackboneModal({ + template : 'wc-modal-shipping-method-settings', + variable : { + instance_id : instance_id, + method : method, + status : 'new' + }, + data : { + instance_id : instance_id, + method : method, + status : 'new' + } + }); + } $( document.body ).trigger( 'init_tooltips' ); @@ -461,12 +540,62 @@ }, 'json' ); } }, + // Free Shipping has hidden field elements depending on data values. + possiblyHideFreeShippingRequirements: function( data ) { + if ( Object.keys( data ).includes( 'woocommerce_free_shipping_requires' ) ) { + const shouldHideRequirements = data.woocommerce_free_shipping_requires === null || + data.woocommerce_free_shipping_requires === '' || + data.woocommerce_free_shipping_requires === 'coupon'; + + const select = $( '#woocommerce_free_shipping_requires' ); + const fieldset = select.closest( 'fieldset' ); + const allOtherLabelElementsAfter = fieldset.nextAll( 'label' ); + const allOtherFieldsetElementsAfter = fieldset.nextAll( 'fieldset' ); + + allOtherLabelElementsAfter.each( ( i ) => { + $( allOtherLabelElementsAfter[ i ] ).css( 'display', shouldHideRequirements ? 'none' : 'block' ); + } ); + + allOtherFieldsetElementsAfter.each( ( i ) => { + $( allOtherFieldsetElementsAfter[ i ] ).css( 'display', shouldHideRequirements ? 'none' : 'block' ); + } ); + } + }, + onModalLoaded: function( event, target ) { + if ( target === 'wc-modal-shipping-method-settings' ) { + const select = $( '#woocommerce_free_shipping_requires' ); + if ( select.length > 0 ) { + event.data.view.possiblyHideFreeShippingRequirements( { woocommerce_free_shipping_requires: select.val() } ); + } + } + }, + validateFormArguments: function( event, target, data ) { + if ( target === 'wc-modal-add-shipping-method' ) { + if ( data.add_method_id ) { + const nextButton = document.getElementById( 'btn-next' ); + nextButton.disabled = false; + nextButton.classList.remove( 'disabled' ); + } + } else if ( target === 'wc-modal-shipping-method-settings' ) { + event.data.view.possiblyHideFreeShippingRequirements( data ); + const requiredFields = [ 'woocommerce_free_shipping_title', 'woocommerce_flat_rate_title', 'woocommerce_local_pickup_title' ]; + const requiredFieldPresent = requiredFields.find( ( field ) => { + return data.hasOwnProperty( field ) && field; + } ); + + if ( requiredFieldPresent ) { + const shouldDisable = data[ requiredFieldPresent ].length === 0; + const saveButton = document.getElementById( 'btn-ok' ); + saveButton.disabled = shouldDisable; + saveButton.classList.toggle( 'disabled', shouldDisable ); + } + } + }, onCloseConfigureShippingMethod: function( event, target, post_data, addButtonCalled ) { if ( target === 'wc-modal-shipping-method-settings' ) { var btnData = $( '#btn-ok' ).data(); if ( ! addButtonCalled && btnData && btnData.status === 'new' ) { - console.log( 'delete instance_id: ' + post_data.instance_id ); shippingMethodView.block(); var view = shippingMethodView, diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-shipping-method.php b/plugins/woocommerce/includes/abstracts/abstract-wc-shipping-method.php index 0ff2af299e4..e1c50efbd74 100644 --- a/plugins/woocommerce/includes/abstracts/abstract-wc-shipping-method.php +++ b/plugins/woocommerce/includes/abstracts/abstract-wc-shipping-method.php @@ -460,7 +460,7 @@ abstract class WC_Shipping_Method extends WC_Settings_API { $settings_html = $this->generate_settings_html( $this->get_form_fields(), false ); } - return '
' . $settings_html . '
'; + return '
' . $settings_html . '
'; } /** diff --git a/plugins/woocommerce/includes/admin/settings/views/html-admin-page-shipping-classes.php b/plugins/woocommerce/includes/admin/settings/views/html-admin-page-shipping-classes.php index 8c419f07397..cf279e02661 100644 --- a/plugins/woocommerce/includes/admin/settings/views/html-admin-page-shipping-classes.php +++ b/plugins/woocommerce/includes/admin/settings/views/html-admin-page-shipping-classes.php @@ -42,8 +42,8 @@ if ( ! defined( 'ABSPATH' ) ) {