| @@ -41,12 +41,31 @@ | ||
| 41 | 41 | * Whether the setup bar has already been printed in the current request. |
| 42 | 42 | * |
| 43 | 43 | * @var bool |
| 44 | 44 | */ |
| 45 | - private static $is_top_bar_rendered = false; | |
| 45 | + private static $is_top_bar_rendered = false; | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Check whether the legacy floating Setup Wizard bar is enabled. | |
| 49 | + * | |
| 50 | + * The bar is temporarily disabled while the initial Setup Wizard hands the | |
| 51 | + * user directly to Form Builder. The filter preserves a bounded rollback | |
| 52 | + * path without changing Setup Wizard progress or stored configuration. | |
| 53 | + * | |
| 54 | + * @return bool True when the floating Setup Wizard bar may be registered. | |
| 55 | + */ | |
| 56 | + private static function is_floating_setup_bar_enabled() { | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Filter whether the legacy floating Setup Wizard bar is enabled. | |
| 60 | + * | |
| 61 | + * @param bool $is_enabled Whether the floating Setup Wizard bar is enabled. | |
| 62 | + */ | |
| 63 | + return (bool) apply_filters( 'wpbc_setup_wizard_floating_bar_enabled', false ); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public function __construct() { | |
| 46 | 67 | |
| 47 | - public function __construct() { | |
| 48 | - | |
| 49 | 68 | if ( WPBC()->is_wp_inited() || did_action( 'init' ) ) { |
| 50 | 69 | $this->init_steps_data(); |
| 51 | 70 | } else { |
| 52 | 71 | add_action( 'init', array( $this, 'init_steps_data' ) ); |
| @@ -51,12 +70,12 @@ | ||
| 51 | 70 | } else { |
| 52 | 71 | add_action( 'init', array( $this, 'init_steps_data' ) ); |
| 53 | 72 | } |
| 54 | 73 | |
| 55 | - if ( ! self::$is_top_bar_hook_registered ) { | |
| 56 | - add_action( 'wpbc_after_wpbc_page_top__header_tabs', array( $this, 'show_top_right_wizard_button' ), 10, 3 ); | |
| 57 | - self::$is_top_bar_hook_registered = true; | |
| 58 | - } | |
| 74 | + if ( self::is_floating_setup_bar_enabled() && ! self::$is_top_bar_hook_registered ) { | |
| 75 | + add_action( 'wpbc_after_wpbc_page_top__header_tabs', array( $this, 'show_top_right_wizard_button' ), 10, 3 ); | |
| 76 | + self::$is_top_bar_hook_registered = true; | |
| 77 | + } | |
| 59 | 78 | |
| 60 | 79 | } |
| 61 | 80 | |
| 62 | 81 | /** |
| @@ -116,9 +135,9 @@ | ||
| 116 | 135 | ); |
| 117 | 136 | } |
| 118 | 137 | } |
| 119 | 138 | |
| 120 | - foreach ( array( 'date_selection', 'changeover_days', 'working_time', 'time_slots_availability', 'date_availability', 'form_structure', 'color_theme', 'wizard_publish' ) as $continue_step_name ) { | |
| 139 | + foreach ( array( 'service_provider', 'date_selection', 'changeover_days', 'working_time', 'time_slots_availability', 'date_availability', 'form_structure', 'color_theme', 'wizard_publish' ) as $continue_step_name ) { | |
| 121 | 140 | if ( isset( $steps_arr[ $continue_step_name ] ) ) { |
| 122 | 141 | $steps_arr[ $continue_step_name ]['next_title'] = $is_i18n_ready ? __( 'Continue', 'booking' ) : 'Continue'; |
| 123 | 142 | } |
| 124 | 143 | } |
| @@ -812,16 +831,30 @@ | ||
| 812 | 831 | * |
| 813 | 832 | * Show Continue Setup Wizard Button |
| 814 | 833 | * @return void |
| 815 | 834 | */ |
| 816 | - public function show_top_right_wizard_button() { | |
| 835 | + public function show_top_right_wizard_button() { | |
| 836 | + | |
| 837 | + if ( ! self::is_floating_setup_bar_enabled() ) { | |
| 838 | + return false; | |
| 839 | + } | |
| 840 | + | |
| 841 | + if ( ! wpbc_is_setup_wizard_page() ) { | |
| 842 | + $explicit_step_context = false; | |
| 817 | 843 | |
| 818 | - if ( ! wpbc_is_setup_wizard_page() ){ | |
| 844 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only Setup Wizard routing context. | |
| 845 | + if ( isset( $_GET['wpbc_setup_step'] ) && is_scalar( $_GET['wpbc_setup_step'] ) ) { | |
| 846 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only Setup Wizard routing context. | |
| 847 | + $request_step = sanitize_key( wp_unslash( $_GET['wpbc_setup_step'] ) ); | |
| 848 | + $explicit_step_context = isset( $this->steps_arr[ $request_step ] ) | |
| 849 | + && function_exists( 'wpbc_setup_wizard_page__has_explicit_step_context' ) | |
| 850 | + && wpbc_setup_wizard_page__has_explicit_step_context( $request_step ); | |
| 851 | + } | |
| 819 | 852 | |
| 820 | 853 | if ( |
| 821 | 854 | ( ! wpbc_is_user_can_access_wizard_page() ) || |
| 822 | - ( $this->db__is_all_steps_completed() ) | |
| 823 | - ){ | |
| 855 | + ( $this->db__is_all_steps_completed() && ! $explicit_step_context ) | |
| 856 | + ) { | |
| 824 | 857 | return false; |
| 825 | 858 | } |
| 826 | 859 | |
| 827 | 860 | if ( self::$is_top_bar_rendered ) { |
| @@ -843,26 +876,29 @@ | ||
| 843 | 876 | $step_heading = $this->get_step_heading( $current_step ); |
| 844 | 877 | $step_save_page_title = ( 'form_structure' === $current_step ) ? __( 'Form Builder', 'booking' ) : $step_title; |
| 845 | 878 | $description = $this->get_step_description( $current_step ); |
| 846 | 879 | $save_behavior = $this->get_step_save_behavior( $current_step ); |
| 847 | - $target_selector = $this->get_step_meta_value( $current_step, 'target_selector' ); | |
| 848 | - $scroll_selector = $this->get_step_meta_value( $current_step, 'scroll_selector' ); | |
| 849 | - $highlight_selector = $this->get_step_meta_value( $current_step, 'highlight_selector' ); | |
| 850 | - $highlight_disabled = $this->get_step_meta_value( $current_step, 'highlight_disabled' ); | |
| 851 | - $form_selector = $this->get_step_meta_value( $current_step, 'form_selector' ); | |
| 852 | - $save_selector = $this->get_step_meta_value( $current_step, 'save_selector' ); | |
| 853 | - $save_ajax_action = $this->get_step_meta_value( $current_step, 'save_ajax_action' ); | |
| 854 | - $save_events = $this->get_step_meta_value( $current_step, 'save_events' ); | |
| 855 | - $open_action = $this->get_step_meta_value( $current_step, 'open_action' ); | |
| 856 | - $can_save_from_bar = ( 'manual_save_required' === $save_behavior && ! empty( $save_selector ) ); | |
| 857 | - $continue_title = ( 'complete' === $save_behavior ) ? __( 'Finish Setup', 'booking' ) : __( 'Continue', 'booking' ); | |
| 858 | - if ( $can_save_from_bar ) { | |
| 859 | - $continue_title = __( 'Save and Continue', 'booking' ); | |
| 860 | - } | |
| 861 | - $is_step_saved = $this->db__is_step_saved( $current_step ); | |
| 862 | - $is_step_unsaved = ( 'manual_save_required' === $save_behavior && ! $is_step_saved ); | |
| 863 | - $is_continue_disabled = ( $is_step_unsaved && ! $can_save_from_bar ); | |
| 864 | - $continue_href = $is_step_unsaved ? '#wpbc_setup_save_required' : $continue_url; | |
| 880 | + $target_selector = $this->get_step_meta_value( $current_step, 'target_selector' ); | |
| 881 | + $scroll_selector = $this->get_step_meta_value( $current_step, 'scroll_selector' ); | |
| 882 | + $highlight_selector = $this->get_step_meta_value( $current_step, 'highlight_selector' ); | |
| 883 | + $highlight_disabled = $this->get_step_meta_value( $current_step, 'highlight_disabled' ); | |
| 884 | + $highlight_all = $this->get_step_meta_value( $current_step, 'highlight_all' ); | |
| 885 | + $form_selector = $this->get_step_meta_value( $current_step, 'form_selector' ); | |
| 886 | + $save_selector = $this->get_step_meta_value( $current_step, 'save_selector' ); | |
| 887 | + $save_ajax_action = $this->get_step_meta_value( $current_step, 'save_ajax_action' ); | |
| 888 | + $save_events = $this->get_step_meta_value( $current_step, 'save_events' ); | |
| 889 | + $open_action = $this->get_step_meta_value( $current_step, 'open_action' ); | |
| 890 | + $secondary_action_url = $this->get_step_meta_value( $current_step, 'secondary_action_url' ); | |
| 891 | + $secondary_action_label = $this->get_step_meta_value( $current_step, 'secondary_action_label' ); | |
| 892 | + $can_save_from_bar = ( 'manual_save_required' === $save_behavior && ! empty( $save_selector ) ); | |
| 893 | + $continue_title = ( 'complete' === $save_behavior ) ? __( 'Finish Setup', 'booking' ) : __( 'Continue', 'booking' ); | |
| 894 | + if ( $can_save_from_bar ) { | |
| 895 | + $continue_title = __( 'Save and Continue', 'booking' ); | |
| 896 | + } | |
| 897 | + $is_step_saved = $this->db__is_step_saved( $current_step ); | |
| 898 | + $is_step_unsaved = ( 'manual_save_required' === $save_behavior && ! $is_step_saved ); | |
| 899 | + $is_continue_disabled = ( $is_step_unsaved && ! $can_save_from_bar ); | |
| 900 | + $continue_href = $is_step_unsaved ? '#wpbc_setup_save_required' : $continue_url; | |
| 865 | 901 | $mark_saved_nonce = wp_create_nonce( 'wpbc_setup_wizard_mark_step_saved' ); |
| 866 | 902 | $step_target_url = $this->get_step_target_url( $current_step ); |
| 867 | 903 | $skip_wizard_url = add_query_arg( 'wpbc_setup_wizard', 'completed', wpbc_get_bookings_url() ); |
| 868 | 904 | $reset_wizard_url = add_query_arg( 'wpbc_setup_wizard', 'reset', wpbc_get_setup_wizard_page_url() ); |
| @@ -870,8 +906,12 @@ | ||
| 870 | 906 | /* translators: %s: setup target page title. */ |
| 871 | 907 | __( 'Save changes on the %s page before continuing.', 'booking' ), |
| 872 | 908 | '<a href="' . esc_url( $step_target_url ) . '">' . esc_html( $step_save_page_title ) . '</a>' |
| 873 | 909 | ); |
| 910 | + $test_page_links = ( | |
| 911 | + 'wizard_publish' === $current_step | |
| 912 | + && function_exists( 'wpbc_booking_modes_get_setup_test_page_links' ) | |
| 913 | + ) ? wpbc_booking_modes_get_setup_test_page_links() : array(); | |
| 874 | 914 | |
| 875 | 915 | // FixIn: 10.12.1.1. |
| 876 | 916 | ?><style type="text/css"> |
| 877 | 917 | @media screen and (max-width: 782px) { |
| @@ -1011,8 +1051,42 @@ | ||
| 1011 | 1051 | } |
| 1012 | 1052 | .wpbc_page_top__wizard_button_actions .button.button-secondary { |
| 1013 | 1053 | background-color: #e4e4e4; |
| 1014 | 1054 | } |
| 1055 | + .wpbc_setup_wizard_test_page_actions { | |
| 1056 | + display: flex; | |
| 1057 | + flex-flow: row wrap; | |
| 1058 | + align-items: center; | |
| 1059 | + gap: 8px; | |
| 1060 | + font-size: 11px; | |
| 1061 | + font-weight: 400; | |
| 1062 | + line-height: 1.35; | |
| 1063 | + } | |
| 1064 | + .wpbc_page_top__wizard_button[data-wpbc-setup-step="wizard_publish"] .wpbc_page_top__wizard_button_actions { | |
| 1065 | + flex-flow: row wrap; | |
| 1066 | + } | |
| 1067 | + .wpbc_page_top__wizard_button_actions .button.wpbc_setup_wizard_test_page_button, | |
| 1068 | + .wpbc_page_top__wizard_button_actions .button.wpbc_setup_wizard_test_page_button:hover, | |
| 1069 | + .wpbc_page_top__wizard_button_actions .button.wpbc_setup_wizard_test_page_button:focus { | |
| 1070 | + margin: 20px 0; | |
| 1071 | + background: #71a501; | |
| 1072 | + border-color: #71a501; | |
| 1073 | + color: #f0ffce; | |
| 1074 | + } | |
| 1075 | + .wpbc_page_top__wizard_button_actions .button.wpbc_setup_wizard_test_page_button:first-child { | |
| 1076 | + margin-right: auto; | |
| 1077 | + margin-left: 0; | |
| 1078 | + } | |
| 1079 | + .wpbc_page_top__wizard_button[data-wpbc-setup-step="wizard_publish"] .wpbc_page_top__wizard_button_actions.wpbc_page_top__wizard_button_links { | |
| 1080 | + margin: 0; | |
| 1081 | + gap: 10px 15px; | |
| 1082 | + justify-content: flex-start; | |
| 1083 | + } | |
| 1084 | + .wpbc_page_top__wizard_button_actions.wpbc_page_top__wizard_button_links .button.wpbc_setup_wizard_test_page_button:first-child, | |
| 1085 | + .wpbc_page_top__wizard_button[data-wpbc-setup-step="wizard_publish"] .wpbc_page_top__wizard_button_actions.wpbc_page_top__wizard_button_links a { | |
| 1086 | + margin: 0; | |
| 1087 | + flex: 0 1 auto; | |
| 1088 | + } | |
| 1015 | 1089 | .wpbc_page_top__wizard_button_actions .button.disabled, |
| 1016 | 1090 | .wpbc_page_top__wizard_button_actions .button[aria-disabled="true"] { |
| 1017 | 1091 | cursor: not-allowed; |
| 1018 | 1092 | opacity: 0.55; |
| @@ -1109,17 +1183,18 @@ | ||
| 1109 | 1183 | data-wpbc-setup-save-behavior="<?php echo esc_attr( $save_behavior ); ?>" |
| 1110 | 1184 | data-wpbc-setup-is-saved="<?php echo esc_attr( $is_step_saved ? '1' : '0' ); ?>" |
| 1111 | 1185 | data-wpbc-setup-ajax-url="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" |
| 1112 | 1186 | data-wpbc-setup-mark-saved-nonce="<?php echo esc_attr( $mark_saved_nonce ); ?>" |
| 1113 | - data-wpbc-setup-target-selector="<?php echo esc_attr( $target_selector ); ?>" | |
| 1114 | - data-wpbc-setup-scroll-selector="<?php echo esc_attr( $scroll_selector ); ?>" | |
| 1115 | - data-wpbc-setup-highlight-selector="<?php echo esc_attr( $highlight_selector ); ?>" | |
| 1116 | - data-wpbc-setup-highlight-disabled="<?php echo esc_attr( $highlight_disabled ); ?>" | |
| 1117 | - data-wpbc-setup-form-selector="<?php echo esc_attr( $form_selector ); ?>" | |
| 1118 | - data-wpbc-setup-save-selector="<?php echo esc_attr( $save_selector ); ?>" | |
| 1119 | - data-wpbc-setup-save-ajax-action="<?php echo esc_attr( $save_ajax_action ); ?>" | |
| 1120 | - data-wpbc-setup-save-events="<?php echo esc_attr( $save_events ); ?>" | |
| 1121 | - data-wpbc-setup-open-action="<?php echo esc_attr( $open_action ); ?>"> | |
| 1187 | + data-wpbc-setup-target-selector="<?php echo esc_attr( $target_selector ); ?>" | |
| 1188 | + data-wpbc-setup-scroll-selector="<?php echo esc_attr( $scroll_selector ); ?>" | |
| 1189 | + data-wpbc-setup-highlight-selector="<?php echo esc_attr( $highlight_selector ); ?>" | |
| 1190 | + data-wpbc-setup-highlight-disabled="<?php echo esc_attr( $highlight_disabled ); ?>" | |
| 1191 | + data-wpbc-setup-highlight-all="<?php echo esc_attr( $highlight_all ); ?>" | |
| 1192 | + data-wpbc-setup-form-selector="<?php echo esc_attr( $form_selector ); ?>" | |
| 1193 | + data-wpbc-setup-save-selector="<?php echo esc_attr( $save_selector ); ?>" | |
| 1194 | + data-wpbc-setup-save-ajax-action="<?php echo esc_attr( $save_ajax_action ); ?>" | |
| 1195 | + data-wpbc-setup-save-events="<?php echo esc_attr( $save_events ); ?>" | |
| 1196 | + data-wpbc-setup-open-action="<?php echo esc_attr( $open_action ); ?>"> | |
| 1122 | 1197 | <div class="wpbc_ui_control wpbc_page_top__wizard_button_content"> |
| 1123 | 1198 | <div class="in-button-text" |
| 1124 | 1199 | style="width: 100%;margin: 0;display: flex;flex-flow: column nowrap;justify-content: flex-start;align-items: stretch;gap:8px;"> |
| 1125 | 1200 | <div class="setup_wizard_page_container" |
| @@ -1142,9 +1217,9 @@ | ||
| 1142 | 1217 | <button type="button" |
| 1143 | 1218 | class="wpbc_setup_wizard_bar_icon_button wpbc_setup_wizard_bar_reset_button" |
| 1144 | 1219 | title="<?php esc_attr_e( 'Reset setup bar position', 'booking' ); ?>" |
| 1145 | 1220 | aria-label="<?php esc_attr_e( 'Reset setup bar position', 'booking' ); ?>"> |
| 1146 | - <i class="menu_icon icon-1x wpbc_icn_refresh"></i> | |
| 1221 | + <i class="menu_icon icon-1x wpbc_icn_rotate_90 wpbc_icn_pin_invoke"></i> | |
| 1147 | 1222 | </button> |
| 1148 | 1223 | <button type="button" |
| 1149 | 1224 | class="wpbc_setup_wizard_bar_icon_button wpbc_setup_wizard_bar_toggle_button" |
| 1150 | 1225 | title="<?php esc_attr_e( 'Collapse setup bar', 'booking' ); ?>" |
| @@ -1149,9 +1224,9 @@ | ||
| 1149 | 1224 | class="wpbc_setup_wizard_bar_icon_button wpbc_setup_wizard_bar_toggle_button" |
| 1150 | 1225 | title="<?php esc_attr_e( 'Collapse setup bar', 'booking' ); ?>" |
| 1151 | 1226 | aria-label="<?php esc_attr_e( 'Collapse setup bar', 'booking' ); ?>" |
| 1152 | 1227 | aria-expanded="true"> |
| 1153 | - <i class="menu_icon icon-1x wpbc_icn_expand_less"></i> | |
| 1228 | + <i class="menu_icon icon-1x wpbc_icn_minimize"></i> | |
| 1154 | 1229 | </button> |
| 1155 | 1230 | </div> |
| 1156 | 1231 | </div> |
| 1157 | 1232 | <div class="name_item wpbc_setup_wizard_bar_expandable" style="flex:1 1 100%;font-size:13px;font-weight:600;line-height:1.35;margin:3px 0 0;color:#f1f1f1;"> |
| @@ -1185,9 +1260,32 @@ | ||
| 1185 | 1260 | } |
| 1186 | 1261 | ?> |
| 1187 | 1262 | </div> |
| 1188 | 1263 | <?php } ?> |
| 1264 | + <?php if ( 'wizard_publish' === $current_step && empty( $test_page_links ) ) { ?> | |
| 1265 | + <div class="wpbc_setup_wizard_test_page_actions wpbc_setup_wizard_bar_expandable"> | |
| 1266 | + <span><?php esc_html_e( 'No published booking page was found yet. Use QuickStart or the page publishing controls, then return to this step.', 'booking' ); ?></span> | |
| 1267 | + </div> | |
| 1268 | + <?php } ?> | |
| 1269 | + <?php if ( 'wizard_publish' === $current_step && ! empty( $test_page_links ) ) { ?> | |
| 1270 | + <div class="wpbc_page_top__wizard_button_actions wpbc_setup_wizard_bar_expandable wpbc_page_top__wizard_button_links"> | |
| 1271 | + <?php foreach ( $test_page_links as $test_page_link ) { | |
| 1272 | + if ( empty( $test_page_link['url'] ) || empty( $test_page_link['label'] ) ) { | |
| 1273 | + continue; | |
| 1274 | + } | |
| 1275 | + ?> | |
| 1276 | + <a class="button button-primary secondary wpbc_setup_wizard_test_page_button" | |
| 1277 | + href="<?php echo esc_url( $test_page_link['url'] ); ?>" | |
| 1278 | + target="_blank" | |
| 1279 | + rel="noopener noreferrer"><?php echo esc_html( $test_page_link['label'] ); ?></a> | |
| 1280 | + <?php } ?> | |
| 1281 | + </div> | |
| 1282 | + <?php } ?> | |
| 1189 | 1283 | <div class="wpbc_page_top__wizard_button_actions wpbc_setup_wizard_bar_expandable"> |
| 1284 | + <?php if ( ! empty( $secondary_action_url ) && ! empty( $secondary_action_label ) ) { ?> | |
| 1285 | + <a class="button button-secondary wpbc_setup_wizard_secondary_action" | |
| 1286 | + href="<?php echo esc_url( $secondary_action_url ); ?>"><?php echo esc_html( $secondary_action_label ); ?></a> | |
| 1287 | + <?php } ?> | |
| 1190 | 1288 | <?php if ( ! empty( $prior_url ) ) { ?> |
| 1191 | 1289 | <a href="<?php echo esc_url( $prior_url ); ?>" class="button button-secondary"><?php esc_html_e( 'Back', 'booking' ); ?></a> |
| 1192 | 1290 | <?php } ?> |
| 1193 | 1291 | <a href="<?php echo esc_url( $continue_href ); ?>" |
| @@ -1213,38 +1311,40 @@ | ||
| 1213 | 1311 | jQuery( document ).ready( function() { |
| 1214 | 1312 | var $bar = jQuery( '.wpbc_page_top__wizard_button[data-wpbc-setup-step]' ).first(); |
| 1215 | 1313 | var step = $bar.attr( 'data-wpbc-setup-step' ) || ''; |
| 1216 | 1314 | var saveBehavior = $bar.attr( 'data-wpbc-setup-save-behavior' ) || ''; |
| 1217 | - var selector = $bar.attr( 'data-wpbc-setup-target-selector' ) || ''; | |
| 1218 | - var scrollSelector = $bar.attr( 'data-wpbc-setup-scroll-selector' ) || selector; | |
| 1219 | - var highlightSelector = $bar.attr( 'data-wpbc-setup-highlight-selector' ) || selector; | |
| 1220 | - var highlightDisabled = ( '1' === ( $bar.attr( 'data-wpbc-setup-highlight-disabled' ) || '' ) ); | |
| 1221 | - var formSelector = $bar.attr( 'data-wpbc-setup-form-selector' ) || ''; | |
| 1222 | - var saveSelector = $bar.attr( 'data-wpbc-setup-save-selector' ) || ''; | |
| 1223 | - var saveAjaxAction = $bar.attr( 'data-wpbc-setup-save-ajax-action' ) || ''; | |
| 1224 | - var saveEvents = ( $bar.attr( 'data-wpbc-setup-save-events' ) || '' ).split( ',' ); | |
| 1315 | + var selector = $bar.attr( 'data-wpbc-setup-target-selector' ) || ''; | |
| 1316 | + var scrollSelector = $bar.attr( 'data-wpbc-setup-scroll-selector' ) || selector; | |
| 1317 | + var highlightSelector = $bar.attr( 'data-wpbc-setup-highlight-selector' ) || selector; | |
| 1318 | + var highlightDisabled = ( '1' === ( $bar.attr( 'data-wpbc-setup-highlight-disabled' ) || '' ) ); | |
| 1319 | + var highlightAll = ( '1' === ( $bar.attr( 'data-wpbc-setup-highlight-all' ) || '' ) ); | |
| 1320 | + var formSelector = $bar.attr( 'data-wpbc-setup-form-selector' ) || ''; | |
| 1321 | + var saveSelector = $bar.attr( 'data-wpbc-setup-save-selector' ) || ''; | |
| 1322 | + var saveAjaxAction = $bar.attr( 'data-wpbc-setup-save-ajax-action' ) || ''; | |
| 1323 | + var saveEvents = ( $bar.attr( 'data-wpbc-setup-save-events' ) || '' ).split( ',' ); | |
| 1225 | 1324 | var openAction = $bar.attr( 'data-wpbc-setup-open-action' ) || ''; |
| 1226 | 1325 | var ajaxUrl = $bar.attr( 'data-wpbc-setup-ajax-url' ) || ''; |
| 1227 | 1326 | var nonce = $bar.attr( 'data-wpbc-setup-mark-saved-nonce' ) || ''; |
| 1228 | - var $continueButton = $bar.find( '.wpbc_setup_wizard_continue_button' ).first(); | |
| 1229 | - var $note = $bar.find( '.wpbc_page_top__wizard_button_note' ).first(); | |
| 1230 | - var savedNote = '<?php echo esc_js( __( 'Changes saved. You can continue.', 'booking' ) ); ?>'; | |
| 1231 | - var saveRequiredNote = <?php echo wp_json_encode( wp_kses_post( $save_required_note ) ); ?>; | |
| 1232 | - var continueTitle = <?php echo wp_json_encode( ( 'complete' === $save_behavior ) ? __( 'Finish Setup', 'booking' ) : __( 'Continue', 'booking' ) ); ?>; | |
| 1233 | - var saveAndContinueTitle = <?php echo wp_json_encode( __( 'Save and Continue', 'booking' ) ); ?>; | |
| 1234 | - var savingTitle = <?php echo wp_json_encode( __( 'Saving', 'booking' ) . '...' ); ?>; | |
| 1235 | - var $toggleButton = $bar.find( '.wpbc_setup_wizard_bar_toggle_button' ).first(); | |
| 1236 | - var $toggleIcon = $toggleButton.find( 'i' ).first(); | |
| 1237 | - var $resetButton = $bar.find( '.wpbc_setup_wizard_bar_reset_button' ).first(); | |
| 1238 | - var $dragHandle = $bar.find( '.wpbc_setup_wizard_bar_drag_handle' ).first(); | |
| 1327 | + var $continueButton = $bar.find( '.wpbc_setup_wizard_continue_button' ).first(); | |
| 1328 | + var $note = $bar.find( '.wpbc_page_top__wizard_button_note' ).first(); | |
| 1329 | + var savedNote = '<?php echo esc_js( __( 'Changes saved. You can continue.', 'booking' ) ); ?>'; | |
| 1330 | + var saveRequiredNote = <?php echo wp_json_encode( wp_kses_post( $save_required_note ) ); ?>; | |
| 1331 | + var continueTitle = <?php echo wp_json_encode( ( 'complete' === $save_behavior ) ? __( 'Finish Setup', 'booking' ) : __( 'Continue', 'booking' ) ); ?>; | |
| 1332 | + var saveAndContinueTitle = <?php echo wp_json_encode( __( 'Save and Continue', 'booking' ) ); ?>; | |
| 1333 | + var savingTitle = <?php echo wp_json_encode( __( 'Saving', 'booking' ) . '...' ); ?>; | |
| 1334 | + var $toggleButton = $bar.find( '.wpbc_setup_wizard_bar_toggle_button' ).first(); | |
| 1335 | + var $toggleIcon = $toggleButton.find( 'i' ).first(); | |
| 1336 | + var $resetButton = $bar.find( '.wpbc_setup_wizard_bar_reset_button' ).first(); | |
| 1337 | + var $dragHandle = $bar.find( '.wpbc_setup_wizard_bar_drag_handle' ).first(); | |
| 1239 | 1338 | var positionStorageKey = 'wpbc_setup_wizard_bar_position'; |
| 1240 | 1339 | var collapsedStorageKey = 'wpbc_setup_wizard_bar_collapsed'; |
| 1241 | 1340 | var collapseLabel = <?php echo wp_json_encode( __( 'Collapse setup bar', 'booking' ) ); ?>; |
| 1242 | - var expandLabel = <?php echo wp_json_encode( __( 'Expand setup bar', 'booking' ) ); ?>; | |
| 1243 | - var $target; | |
| 1244 | - var saveClicked = false; | |
| 1245 | - var saveAndContinueRequested = false; | |
| 1246 | - var saveAndContinueRedirecting = false; | |
| 1341 | + var expandLabel = <?php echo wp_json_encode( __( 'Expand setup bar', 'booking' ) ); ?>; | |
| 1342 | + var $target; | |
| 1343 | + var $highlightTargets = jQuery(); | |
| 1344 | + var saveClicked = false; | |
| 1345 | + var saveAndContinueRequested = false; | |
| 1346 | + var saveAndContinueRedirecting = false; | |
| 1247 | 1347 | |
| 1248 | 1348 | function wpbcSetupWizardStorageGet( key ) { |
| 1249 | 1349 | try { |
| 1250 | 1350 | return window.localStorage.getItem( key ); |
| @@ -1322,9 +1422,10 @@ | ||
| 1322 | 1422 | return -1 !== jQuery.inArray( step, [ |
| 1323 | 1423 | 'date_selection', |
| 1324 | 1424 | 'changeover_days', |
| 1325 | 1425 | 'working_time', |
| 1326 | - 'time_slots_availability' | |
| 1426 | + 'time_slots_availability', | |
| 1427 | + 'date_availability' | |
| 1327 | 1428 | ] ); |
| 1328 | 1429 | } |
| 1329 | 1430 | |
| 1330 | 1431 | function wpbcSetupWizardGetRightSidebarOffset() { |
| @@ -1369,9 +1470,13 @@ | ||
| 1369 | 1470 | wpbcSetupWizardApplyPosition( null ); |
| 1370 | 1471 | return; |
| 1371 | 1472 | } |
| 1372 | 1473 | |
| 1474 | + // Clear any visible inspector while retaining the minimum offset used by the Days Availability page. | |
| 1373 | 1475 | rightOffset = wpbcSetupWizardGetRightSidebarOffset(); |
| 1476 | + if ( 'date_availability' === step ) { | |
| 1477 | + rightOffset = Math.max( rightOffset, 60 ); | |
| 1478 | + } | |
| 1374 | 1479 | maxRight = Math.max( 15, jQuery( window ).width() - barWidth - 10 ); |
| 1375 | 1480 | |
| 1376 | 1481 | if ( wpbcSetupWizardShouldUseTopDefault() ) { |
| 1377 | 1482 | $bar |
| @@ -1412,8 +1517,11 @@ | ||
| 1412 | 1517 | } |
| 1413 | 1518 | |
| 1414 | 1519 | function wpbcSetupWizardApplySavedPosition() { |
| 1415 | 1520 | var savedPosition = wpbcSetupWizardStorageGet( positionStorageKey ); |
| 1521 | + var rightSidebarOffset; | |
| 1522 | + var barRect; | |
| 1523 | + var sidebarLeft; | |
| 1416 | 1524 | |
| 1417 | 1525 | if ( ! savedPosition ) { |
| 1418 | 1526 | wpbcSetupWizardApplyDefaultPosition(); |
| 1419 | 1527 | return; |
| @@ -1423,9 +1531,20 @@ | ||
| 1423 | 1531 | wpbcSetupWizardApplyPosition( JSON.parse( savedPosition ) ); |
| 1424 | 1532 | } catch ( _e ) { |
| 1425 | 1533 | wpbcSetupWizardStorageRemove( positionStorageKey ); |
| 1426 | 1534 | wpbcSetupWizardApplyDefaultPosition(); |
| 1535 | + return; | |
| 1427 | 1536 | } |
| 1537 | + | |
| 1538 | + rightSidebarOffset = wpbcSetupWizardGetRightSidebarOffset(); | |
| 1539 | + if ( 'service_provider' === step && rightSidebarOffset > 15 ) { | |
| 1540 | + barRect = $bar[0].getBoundingClientRect(); | |
| 1541 | + sidebarLeft = jQuery( window ).width() - rightSidebarOffset + 15; | |
| 1542 | + | |
| 1543 | + if ( barRect.right > ( sidebarLeft - 10 ) ) { | |
| 1544 | + wpbcSetupWizardApplyDefaultPosition(); | |
| 1545 | + } | |
| 1546 | + } | |
| 1428 | 1547 | } |
| 1429 | 1548 | |
| 1430 | 1549 | function wpbcSetupWizardResetPosition() { |
| 1431 | 1550 | wpbcSetupWizardStorageRemove( positionStorageKey ); |
| @@ -1438,10 +1557,10 @@ | ||
| 1438 | 1557 | .attr( 'aria-expanded', isCollapsed ? 'false' : 'true' ) |
| 1439 | 1558 | .attr( 'title', isCollapsed ? expandLabel : collapseLabel ) |
| 1440 | 1559 | .attr( 'aria-label', isCollapsed ? expandLabel : collapseLabel ); |
| 1441 | 1560 | $toggleIcon |
| 1442 | - .toggleClass( 'wpbc_icn_expand_less', ! isCollapsed ) | |
| 1443 | - .toggleClass( 'wpbc_icn_expand_more', !! isCollapsed ); | |
| 1561 | + .toggleClass( 'wpbc_icn_minimize', ! isCollapsed ) | |
| 1562 | + .toggleClass( 'wpbc_icn_fullscreen', !! isCollapsed ); | |
| 1444 | 1563 | wpbcSetupWizardStorageSet( collapsedStorageKey, isCollapsed ? '1' : '0' ); |
| 1445 | 1564 | wpbcSetupWizardApplySavedPosition(); |
| 1446 | 1565 | } |
| 1447 | 1566 | |
| @@ -1496,11 +1615,16 @@ | ||
| 1496 | 1615 | wpbcSetupWizardApplySavedPosition(); |
| 1497 | 1616 | setTimeout( wpbcSetupWizardApplySavedPosition, 400 ); |
| 1498 | 1617 | setTimeout( wpbcSetupWizardApplySavedPosition, 1000 ); |
| 1499 | 1618 | jQuery( window ).on( 'resize.wpbc_setup_wizard_bar', wpbcSetupWizardApplySavedPosition ); |
| 1619 | + jQuery( document ).on( 'wpbc_setup_wizard_layout_changed.wpbc_setup_wizard_bar', wpbcSetupWizardApplySavedPosition ); | |
| 1500 | 1620 | |
| 1501 | 1621 | function wpbcSetupWizardOpenPublishArea() { |
| 1502 | - var isResourcesPage = -1 !== window.location.href.indexOf( 'page=wpbc-resources' ); | |
| 1622 | + var currentUrl = new window.URL( window.location.href ); | |
| 1623 | + var currentResourcesTab = currentUrl.searchParams.get( 'tab' ) || ''; | |
| 1624 | + var isResourcesPage = 'wpbc-resources' === currentUrl.searchParams.get( 'page' ) | |
| 1625 | + && ( '' === currentResourcesTab || 'resources' === currentResourcesTab ); | |
| 1626 | + var catalogMount = document.getElementById( 'wpbc_catalog_booking_resources' ); | |
| 1503 | 1627 | var publishTabSelectors = [ |
| 1504 | 1628 | '.wpdvlp-sub-tabs .nav-tab', |
| 1505 | 1629 | '.wpdvlp-top-tabs .nav-tab', |
| 1506 | 1630 | '.wpbc_settings_navigation_item a', |
| @@ -1518,23 +1642,90 @@ | ||
| 1518 | 1642 | 'button.button' |
| 1519 | 1643 | ].join( ',' ); |
| 1520 | 1644 | var publishTargetSelector = [ |
| 1521 | 1645 | '.wpbc_resources_table .ui_group__publish_btn:visible', |
| 1646 | + '#wpbc_booking_resource_table .ui_group__publish_btn:visible', | |
| 1522 | 1647 | '.wpbc_resource_field__switchable.wpbc_resource_field__publish:visible', |
| 1523 | 1648 | '.wpbc_resource_field__publish:visible', |
| 1524 | 1649 | '.wpbc_resource_publish:visible', |
| 1525 | 1650 | '.wpbc_publish_resources:visible', |
| 1526 | - '.wpbc_resource_shortcode:visible', | |
| 1527 | - '[data-wpbc-resource-publish]:visible', | |
| 1528 | - '#wpbc_booking_resource_table:visible' | |
| 1651 | + '[data-wpbc-resource-publish]:visible' | |
| 1529 | 1652 | ].join( ',' ); |
| 1530 | 1653 | var $publishTab; |
| 1531 | 1654 | var $publishToggle; |
| 1532 | 1655 | |
| 1533 | - if ( ( 'wizard_publish' !== step && 'publish_area' !== openAction ) || ! isResourcesPage ) { | |
| 1656 | + if ( 'wizard_publish' !== step || ! isResourcesPage ) { | |
| 1534 | 1657 | return; |
| 1535 | 1658 | } |
| 1536 | 1659 | |
| 1660 | + if ( 'catalog_publish' === openAction && catalogMount ) { | |
| 1661 | + var catalogPublishRequested = false; | |
| 1662 | + /** | |
| 1663 | + * Open the first authorized Resource at its publishing inspector section. | |
| 1664 | + * | |
| 1665 | + * @param {CustomEvent|null} renderEvent Shared catalog render event. | |
| 1666 | + * @return {void} | |
| 1667 | + */ | |
| 1668 | + var openCatalogPublishing = function( renderEvent ) { | |
| 1669 | + var catalogResponse = renderEvent && renderEvent.detail ? renderEvent.detail.response : null; | |
| 1670 | + var publishAction = catalogMount.querySelector( '[data-wpbc-booking-resource-action="publish_resource"][data-wpbc-booking-resource-id]' ); | |
| 1671 | + var resourceId = publishAction ? Number( publishAction.getAttribute( 'data-wpbc-booking-resource-id' ) || 0 ) : 0; | |
| 1672 | + | |
| 1673 | + if ( ! resourceId && catalogResponse && Array.isArray( catalogResponse.items ) ) { | |
| 1674 | + catalogResponse.items.some( function( resource ) { | |
| 1675 | + var isPublishAuthorized = Array.isArray( resource.action_items ) && resource.action_items.some( function( resourceAction ) { | |
| 1676 | + return resourceAction && 'publish_resource' === resourceAction.id; | |
| 1677 | + } ); | |
| 1678 | + | |
| 1679 | + if ( ! isPublishAuthorized ) { | |
| 1680 | + return false; | |
| 1681 | + } | |
| 1682 | + | |
| 1683 | + resourceId = Number( resource.id || 0 ); | |
| 1684 | + return 0 < resourceId; | |
| 1685 | + } ); | |
| 1686 | + } | |
| 1687 | + if ( catalogPublishRequested || ! resourceId ) { | |
| 1688 | + return; | |
| 1689 | + } | |
| 1690 | + | |
| 1691 | + catalogPublishRequested = true; | |
| 1692 | + catalogMount.removeEventListener( 'wpbc:ui-catalog-rendered', openCatalogPublishing ); | |
| 1693 | + | |
| 1694 | + // Defer until the domain catalog has completed its synchronous mount listeners. | |
| 1695 | + window.setTimeout( function() { | |
| 1696 | + var resourceActionEvent; | |
| 1697 | + | |
| 1698 | + if ( 'function' === typeof window.CustomEvent ) { | |
| 1699 | + resourceActionEvent = new window.CustomEvent( 'wpbc:booking-resource-action', { | |
| 1700 | + bubbles: false, | |
| 1701 | + detail: { | |
| 1702 | + action: 'publish_resource', | |
| 1703 | + resource_id: resourceId, | |
| 1704 | + source: 'setup_wizard' | |
| 1705 | + } | |
| 1706 | + } ); | |
| 1707 | + } else { | |
| 1708 | + resourceActionEvent = document.createEvent( 'CustomEvent' ); | |
| 1709 | + resourceActionEvent.initCustomEvent( 'wpbc:booking-resource-action', false, false, { | |
| 1710 | + action: 'publish_resource', | |
| 1711 | + resource_id: resourceId, | |
| 1712 | + source: 'setup_wizard' | |
| 1713 | + } ); | |
| 1714 | + } | |
| 1715 | + document.dispatchEvent( resourceActionEvent ); | |
| 1716 | + }, 0 ); | |
| 1717 | + }; | |
| 1718 | + | |
| 1719 | + catalogMount.addEventListener( 'wpbc:ui-catalog-rendered', openCatalogPublishing ); | |
| 1720 | + openCatalogPublishing( null ); | |
| 1721 | + return; | |
| 1722 | + } | |
| 1723 | + | |
| 1724 | + if ( 'publish_area' !== openAction ) { | |
| 1725 | + return; | |
| 1726 | + } | |
| 1727 | + | |
| 1537 | 1728 | $publishTab = jQuery( publishTabSelectors ).filter( ':visible' ).filter( function() { |
| 1538 | 1729 | var $element = jQuery( this ); |
| 1539 | 1730 | var text = $element.text() || ''; |
| 1540 | 1731 | var href = $element.attr( 'href' ) || ''; |
| @@ -1718,82 +1909,82 @@ | ||
| 1718 | 1909 | wpbcSetupWizardPulseElement( jQuery( '#ajax_working .wpbc_inner_message.notice-warning' ).last() ); |
| 1719 | 1910 | }, 50 ); |
| 1720 | 1911 | } |
| 1721 | 1912 | |
| 1722 | - function wpbcSetupWizardSetSaved() { | |
| 1723 | - $bar.attr( 'data-wpbc-setup-is-saved', '1' ); | |
| 1724 | - $continueButton | |
| 1725 | - .removeClass( 'disabled' ) | |
| 1726 | - .removeAttr( 'aria-disabled' ) | |
| 1727 | - .attr( 'href', $continueButton.attr( 'data-wpbc-setup-continue-url' ) || '#' ) | |
| 1728 | - .text( continueTitle ); | |
| 1729 | - if ( $note.length ) { | |
| 1730 | - $note | |
| 1731 | - .addClass( 'wpbc_setup_wizard_bar_note_saved' ) | |
| 1732 | - .text( savedNote ); | |
| 1733 | - } | |
| 1734 | - } | |
| 1735 | - | |
| 1736 | - function wpbcSetupWizardSetUnsaved() { | |
| 1737 | - $bar.attr( 'data-wpbc-setup-is-saved', '0' ); | |
| 1738 | - $continueButton.attr( 'href', '#wpbc_setup_save_required' ).text( saveSelector ? saveAndContinueTitle : continueTitle ); | |
| 1739 | - if ( saveSelector ) { | |
| 1740 | - $continueButton.removeClass( 'disabled' ).removeAttr( 'aria-disabled' ); | |
| 1741 | - } else { | |
| 1742 | - $continueButton.addClass( 'disabled' ).attr( 'aria-disabled', 'true' ); | |
| 1743 | - } | |
| 1744 | - if ( $note.length ) { | |
| 1745 | - $note | |
| 1746 | - .removeClass( 'wpbc_setup_wizard_bar_note_saved' ) | |
| 1747 | - .html( saveRequiredNote ); | |
| 1748 | - } | |
| 1749 | - } | |
| 1750 | - | |
| 1751 | - function wpbcSetupWizardSetSaveAndContinueBusy( isBusy ) { | |
| 1752 | - if ( ! saveSelector ) { | |
| 1753 | - return; | |
| 1754 | - } | |
| 1755 | - | |
| 1756 | - $continueButton.toggleClass( 'disabled', !! isBusy ).text( isBusy ? savingTitle : saveAndContinueTitle ); | |
| 1757 | - if ( isBusy ) { | |
| 1758 | - $continueButton.attr( 'aria-disabled', 'true' ); | |
| 1759 | - } else { | |
| 1760 | - $continueButton.removeAttr( 'aria-disabled' ); | |
| 1761 | - } | |
| 1762 | - } | |
| 1763 | - | |
| 1764 | - function wpbcSetupWizardGetContinueUrl() { | |
| 1765 | - return $continueButton.attr( 'data-wpbc-setup-continue-url' ) || $continueButton.attr( 'href' ) || ''; | |
| 1766 | - } | |
| 1767 | - | |
| 1768 | - function wpbcSetupWizardContinueAfterSave() { | |
| 1769 | - var continueUrl; | |
| 1770 | - | |
| 1771 | - if ( saveAndContinueRedirecting ) { | |
| 1772 | - return; | |
| 1773 | - } | |
| 1774 | - | |
| 1775 | - continueUrl = wpbcSetupWizardGetContinueUrl(); | |
| 1776 | - if ( ! continueUrl || '#wpbc_setup_save_required' === continueUrl ) { | |
| 1777 | - wpbcSetupWizardSetSaveAndContinueBusy( false ); | |
| 1778 | - return; | |
| 1779 | - } | |
| 1780 | - | |
| 1781 | - saveAndContinueRedirecting = true; | |
| 1782 | - window.location.href = continueUrl; | |
| 1783 | - } | |
| 1784 | - | |
| 1785 | - function wpbcSetupWizardMarkSaved( afterSavedCallback ) { | |
| 1786 | - if ( ! step || ! ajaxUrl || ! nonce ) { | |
| 1787 | - wpbcSetupWizardSetSaved(); | |
| 1788 | - if ( 'function' === typeof afterSavedCallback ) { | |
| 1789 | - afterSavedCallback(); | |
| 1790 | - } | |
| 1791 | - return; | |
| 1792 | - } | |
| 1793 | - | |
| 1794 | - jQuery.post( ajaxUrl, { | |
| 1795 | - action: 'WPBC_AJX_SETUP_WIZARD_MARK_STEP_SAVED', | |
| 1913 | + function wpbcSetupWizardSetSaved() { | |
| 1914 | + $bar.attr( 'data-wpbc-setup-is-saved', '1' ); | |
| 1915 | + $continueButton | |
| 1916 | + .removeClass( 'disabled' ) | |
| 1917 | + .removeAttr( 'aria-disabled' ) | |
| 1918 | + .attr( 'href', $continueButton.attr( 'data-wpbc-setup-continue-url' ) || '#' ) | |
| 1919 | + .text( continueTitle ); | |
| 1920 | + if ( $note.length ) { | |
| 1921 | + $note | |
| 1922 | + .addClass( 'wpbc_setup_wizard_bar_note_saved' ) | |
| 1923 | + .text( savedNote ); | |
| 1924 | + } | |
| 1925 | + } | |
| 1926 | + | |
| 1927 | + function wpbcSetupWizardSetUnsaved() { | |
| 1928 | + $bar.attr( 'data-wpbc-setup-is-saved', '0' ); | |
| 1929 | + $continueButton.attr( 'href', '#wpbc_setup_save_required' ).text( saveSelector ? saveAndContinueTitle : continueTitle ); | |
| 1930 | + if ( saveSelector ) { | |
| 1931 | + $continueButton.removeClass( 'disabled' ).removeAttr( 'aria-disabled' ); | |
| 1932 | + } else { | |
| 1933 | + $continueButton.addClass( 'disabled' ).attr( 'aria-disabled', 'true' ); | |
| 1934 | + } | |
| 1935 | + if ( $note.length ) { | |
| 1936 | + $note | |
| 1937 | + .removeClass( 'wpbc_setup_wizard_bar_note_saved' ) | |
| 1938 | + .html( saveRequiredNote ); | |
| 1939 | + } | |
| 1940 | + } | |
| 1941 | + | |
| 1942 | + function wpbcSetupWizardSetSaveAndContinueBusy( isBusy ) { | |
| 1943 | + if ( ! saveSelector ) { | |
| 1944 | + return; | |
| 1945 | + } | |
| 1946 | + | |
| 1947 | + $continueButton.toggleClass( 'disabled', !! isBusy ).text( isBusy ? savingTitle : saveAndContinueTitle ); | |
| 1948 | + if ( isBusy ) { | |
| 1949 | + $continueButton.attr( 'aria-disabled', 'true' ); | |
| 1950 | + } else { | |
| 1951 | + $continueButton.removeAttr( 'aria-disabled' ); | |
| 1952 | + } | |
| 1953 | + } | |
| 1954 | + | |
| 1955 | + function wpbcSetupWizardGetContinueUrl() { | |
| 1956 | + return $continueButton.attr( 'data-wpbc-setup-continue-url' ) || $continueButton.attr( 'href' ) || ''; | |
| 1957 | + } | |
| 1958 | + | |
| 1959 | + function wpbcSetupWizardContinueAfterSave() { | |
| 1960 | + var continueUrl; | |
| 1961 | + | |
| 1962 | + if ( saveAndContinueRedirecting ) { | |
| 1963 | + return; | |
| 1964 | + } | |
| 1965 | + | |
| 1966 | + continueUrl = wpbcSetupWizardGetContinueUrl(); | |
| 1967 | + if ( ! continueUrl || '#wpbc_setup_save_required' === continueUrl ) { | |
| 1968 | + wpbcSetupWizardSetSaveAndContinueBusy( false ); | |
| 1969 | + return; | |
| 1970 | + } | |
| 1971 | + | |
| 1972 | + saveAndContinueRedirecting = true; | |
| 1973 | + window.location.href = continueUrl; | |
| 1974 | + } | |
| 1975 | + | |
| 1976 | + function wpbcSetupWizardMarkSaved( afterSavedCallback ) { | |
| 1977 | + if ( ! step || ! ajaxUrl || ! nonce ) { | |
| 1978 | + wpbcSetupWizardSetSaved(); | |
| 1979 | + if ( 'function' === typeof afterSavedCallback ) { | |
| 1980 | + afterSavedCallback(); | |
| 1981 | + } | |
| 1982 | + return; | |
| 1983 | + } | |
| 1984 | + | |
| 1985 | + jQuery.post( ajaxUrl, { | |
| 1986 | + action: 'WPBC_AJX_SETUP_WIZARD_MARK_STEP_SAVED', | |
| 1796 | 1987 | nonce: nonce, |
| 1797 | 1988 | wpbc_setup_step: step |
| 1798 | 1989 | } ).done( function( response ) { |
| 1799 | 1990 | if ( 'string' === typeof response ) { |
| @@ -1799,140 +1990,140 @@ | ||
| 1799 | 1990 | if ( 'string' === typeof response ) { |
| 1800 | 1991 | try { |
| 1801 | 1992 | response = JSON.parse( response ); |
| 1802 | 1993 | } catch ( _e ) {} |
| 1803 | - } | |
| 1804 | - if ( response && response.success ) { | |
| 1805 | - wpbcSetupWizardSetSaved(); | |
| 1806 | - if ( 'function' === typeof afterSavedCallback ) { | |
| 1807 | - afterSavedCallback(); | |
| 1808 | - } | |
| 1809 | - } | |
| 1810 | - } ).fail( function() { | |
| 1811 | - if ( saveAndContinueRequested ) { | |
| 1812 | - wpbcSetupWizardSetSaveAndContinueBusy( false ); | |
| 1813 | - saveAndContinueRequested = false; | |
| 1814 | - } | |
| 1815 | - } ); | |
| 1816 | - } | |
| 1994 | + } | |
| 1995 | + if ( response && response.success ) { | |
| 1996 | + wpbcSetupWizardSetSaved(); | |
| 1997 | + if ( 'function' === typeof afterSavedCallback ) { | |
| 1998 | + afterSavedCallback(); | |
| 1999 | + } | |
| 2000 | + } | |
| 2001 | + } ).fail( function() { | |
| 2002 | + if ( saveAndContinueRequested ) { | |
| 2003 | + wpbcSetupWizardSetSaveAndContinueBusy( false ); | |
| 2004 | + saveAndContinueRequested = false; | |
| 2005 | + } | |
| 2006 | + } ); | |
| 2007 | + } | |
| 1817 | 2008 | |
| 1818 | 2009 | function wpbcSetupWizardSaveStarted() { |
| 1819 | 2010 | saveClicked = true; |
| 1820 | 2011 | } |
| 1821 | 2012 | |
| 1822 | - function wpbcSetupWizardLooksSuccessfulResponse( response ) { | |
| 1823 | - if ( ! response ) { | |
| 1824 | - return false; | |
| 1825 | - } | |
| 1826 | - | |
| 1827 | - return ( | |
| 1828 | - !! response.success | |
| 2013 | + function wpbcSetupWizardLooksSuccessfulResponse( response ) { | |
| 2014 | + if ( ! response ) { | |
| 2015 | + return false; | |
| 2016 | + } | |
| 2017 | + | |
| 2018 | + return ( | |
| 2019 | + !! response.success | |
| 1829 | 2020 | || 'success' === response.status |
| 1830 | 2021 | || '1' === String( response.ajx_after_action_result || '' ) |
| 1831 | 2022 | || ( response.ajx_data && '1' === String( response.ajx_data.ajx_after_action_result || '' ) ) |
| 1832 | - || ( response.data && response.data.setup_step_saved ) | |
| 1833 | - ); | |
| 1834 | - } | |
| 1835 | - | |
| 1836 | - function wpbcSetupWizardGetAjaxAction( ajaxSettings ) { | |
| 1837 | - var data = ajaxSettings && ajaxSettings.data ? ajaxSettings.data : ''; | |
| 1838 | - var matches; | |
| 1839 | - | |
| 1840 | - if ( ! data ) { | |
| 1841 | - return ''; | |
| 1842 | - } | |
| 1843 | - | |
| 1844 | - if ( 'string' === typeof data ) { | |
| 1845 | - matches = data.match( /(?:^|&)action=([^&]+)/ ); | |
| 1846 | - return matches && matches[1] ? decodeURIComponent( matches[1].replace( /\+/g, ' ' ) ) : ''; | |
| 1847 | - } | |
| 1848 | - | |
| 1849 | - if ( window.FormData && data instanceof window.FormData && 'function' === typeof data.get ) { | |
| 1850 | - return data.get( 'action' ) || ''; | |
| 1851 | - } | |
| 1852 | - | |
| 1853 | - if ( 'object' === typeof data && data.action ) { | |
| 1854 | - return data.action; | |
| 1855 | - } | |
| 1856 | - | |
| 1857 | - return ''; | |
| 1858 | - } | |
| 1859 | - | |
| 1860 | - function wpbcSetupWizardIsExpectedSaveAjax( ajaxSettings ) { | |
| 1861 | - var ajaxAction; | |
| 1862 | - | |
| 1863 | - if ( ! saveAjaxAction ) { | |
| 1864 | - return true; | |
| 1865 | - } | |
| 1866 | - | |
| 1867 | - ajaxAction = wpbcSetupWizardGetAjaxAction( ajaxSettings ); | |
| 1868 | - | |
| 1869 | - return saveAjaxAction === ajaxAction; | |
| 1870 | - } | |
| 2023 | + || ( response.data && response.data.setup_step_saved ) | |
| 2024 | + ); | |
| 2025 | + } | |
| 1871 | 2026 | |
| 1872 | - function wpbcSetupWizardHandleSavedEvent() { | |
| 1873 | - saveClicked = false; | |
| 1874 | - wpbcSetupWizardSetSaved(); | |
| 1875 | - if ( saveAndContinueRequested ) { | |
| 1876 | - wpbcSetupWizardMarkSaved( wpbcSetupWizardContinueAfterSave ); | |
| 1877 | - return; | |
| 1878 | - } | |
| 1879 | - wpbcSetupWizardMarkSaved(); | |
| 1880 | - } | |
| 1881 | - | |
| 1882 | - function wpbcSetupWizardRegisterSavedEvent( eventName ) { | |
| 1883 | - eventName = ( eventName || '' ).replace( /^\s+|\s+$/g, '' ); | |
| 1884 | - if ( ! eventName ) { | |
| 1885 | - return; | |
| 1886 | - } | |
| 1887 | - | |
| 1888 | - document.addEventListener( eventName, wpbcSetupWizardHandleSavedEvent, true ); | |
| 1889 | - jQuery( document ).on( eventName + '.wpbc_setup_wizard', wpbcSetupWizardHandleSavedEvent ); | |
| 1890 | - } | |
| 1891 | - | |
| 1892 | - function wpbcSetupWizardFindSaveControl() { | |
| 1893 | - var $saveControl = wpbcSetupWizardGetFirstElement( saveSelector ); | |
| 1894 | - | |
| 1895 | - if ( $saveControl.length ) { | |
| 1896 | - return $saveControl; | |
| 1897 | - } | |
| 1898 | - | |
| 1899 | - if ( ! formSelector ) { | |
| 1900 | - return jQuery(); | |
| 1901 | - } | |
| 1902 | - | |
| 1903 | - return wpbcSetupWizardGetFirstElement( | |
| 1904 | - formSelector + ' button[type="submit"],' + | |
| 1905 | - formSelector + ' input[type="submit"],' + | |
| 1906 | - formSelector + ' .wpbc_submit_button_trigger,' + | |
| 1907 | - formSelector + ' .wpbc_submit_button' | |
| 1908 | - ); | |
| 1909 | - } | |
| 1910 | - | |
| 1911 | - function wpbcSetupWizardTriggerSaveAndContinue() { | |
| 1912 | - var $saveControl = wpbcSetupWizardFindSaveControl(); | |
| 1913 | - | |
| 1914 | - if ( saveAndContinueRequested ) { | |
| 1915 | - return; | |
| 1916 | - } | |
| 1917 | - | |
| 1918 | - if ( ! $saveControl.length || $saveControl.hasClass( 'disabled' ) || 'true' === $saveControl.attr( 'aria-disabled' ) ) { | |
| 1919 | - if ( typeof wpbc_admin_show_message === 'function' ) { | |
| 1920 | - wpbc_admin_show_message( '<?php echo esc_js( __( 'Please save changes on this page before continuing setup.', 'booking' ) ); ?>', 'warning', 4000, false ); | |
| 1921 | - } | |
| 1922 | - wpbcSetupWizardPulseSaveRequiredMessage(); | |
| 1923 | - return; | |
| 1924 | - } | |
| 1925 | - | |
| 1926 | - saveAndContinueRequested = true; | |
| 1927 | - wpbcSetupWizardSaveStarted(); | |
| 1928 | - wpbcSetupWizardSetSaveAndContinueBusy( true ); | |
| 1929 | - if ( formSelector ) { | |
| 1930 | - jQuery( formSelector ).find( 'input[name="wpbc_setup_continue_after_save"]' ).val( '1' ); | |
| 1931 | - } | |
| 1932 | - $saveControl.trigger( 'click' ); | |
| 1933 | - } | |
| 2027 | + function wpbcSetupWizardGetAjaxAction( ajaxSettings ) { | |
| 2028 | + var data = ajaxSettings && ajaxSettings.data ? ajaxSettings.data : ''; | |
| 2029 | + var matches; | |
| 1934 | 2030 | |
| 2031 | + if ( ! data ) { | |
| 2032 | + return ''; | |
| 2033 | + } | |
| 2034 | + | |
| 2035 | + if ( 'string' === typeof data ) { | |
| 2036 | + matches = data.match( /(?:^|&)action=([^&]+)/ ); | |
| 2037 | + return matches && matches[1] ? decodeURIComponent( matches[1].replace( /\+/g, ' ' ) ) : ''; | |
| 2038 | + } | |
| 2039 | + | |
| 2040 | + if ( window.FormData && data instanceof window.FormData && 'function' === typeof data.get ) { | |
| 2041 | + return data.get( 'action' ) || ''; | |
| 2042 | + } | |
| 2043 | + | |
| 2044 | + if ( 'object' === typeof data && data.action ) { | |
| 2045 | + return data.action; | |
| 2046 | + } | |
| 2047 | + | |
| 2048 | + return ''; | |
| 2049 | + } | |
| 2050 | + | |
| 2051 | + function wpbcSetupWizardIsExpectedSaveAjax( ajaxSettings ) { | |
| 2052 | + var ajaxAction; | |
| 2053 | + | |
| 2054 | + if ( ! saveAjaxAction ) { | |
| 2055 | + return true; | |
| 2056 | + } | |
| 2057 | + | |
| 2058 | + ajaxAction = wpbcSetupWizardGetAjaxAction( ajaxSettings ); | |
| 2059 | + | |
| 2060 | + return saveAjaxAction === ajaxAction; | |
| 2061 | + } | |
| 2062 | + | |
| 2063 | + function wpbcSetupWizardHandleSavedEvent() { | |
| 2064 | + saveClicked = false; | |
| 2065 | + wpbcSetupWizardSetSaved(); | |
| 2066 | + if ( saveAndContinueRequested ) { | |
| 2067 | + wpbcSetupWizardMarkSaved( wpbcSetupWizardContinueAfterSave ); | |
| 2068 | + return; | |
| 2069 | + } | |
| 2070 | + wpbcSetupWizardMarkSaved(); | |
| 2071 | + } | |
| 2072 | + | |
| 2073 | + function wpbcSetupWizardRegisterSavedEvent( eventName ) { | |
| 2074 | + eventName = ( eventName || '' ).replace( /^\s+|\s+$/g, '' ); | |
| 2075 | + if ( ! eventName ) { | |
| 2076 | + return; | |
| 2077 | + } | |
| 2078 | + | |
| 2079 | + document.addEventListener( eventName, wpbcSetupWizardHandleSavedEvent, true ); | |
| 2080 | + jQuery( document ).on( eventName + '.wpbc_setup_wizard', wpbcSetupWizardHandleSavedEvent ); | |
| 2081 | + } | |
| 2082 | + | |
| 2083 | + function wpbcSetupWizardFindSaveControl() { | |
| 2084 | + var $saveControl = wpbcSetupWizardGetFirstElement( saveSelector ); | |
| 2085 | + | |
| 2086 | + if ( $saveControl.length ) { | |
| 2087 | + return $saveControl; | |
| 2088 | + } | |
| 2089 | + | |
| 2090 | + if ( ! formSelector ) { | |
| 2091 | + return jQuery(); | |
| 2092 | + } | |
| 2093 | + | |
| 2094 | + return wpbcSetupWizardGetFirstElement( | |
| 2095 | + formSelector + ' button[type="submit"],' + | |
| 2096 | + formSelector + ' input[type="submit"],' + | |
| 2097 | + formSelector + ' .wpbc_submit_button_trigger,' + | |
| 2098 | + formSelector + ' .wpbc_submit_button' | |
| 2099 | + ); | |
| 2100 | + } | |
| 2101 | + | |
| 2102 | + function wpbcSetupWizardTriggerSaveAndContinue() { | |
| 2103 | + var $saveControl = wpbcSetupWizardFindSaveControl(); | |
| 2104 | + | |
| 2105 | + if ( saveAndContinueRequested ) { | |
| 2106 | + return; | |
| 2107 | + } | |
| 2108 | + | |
| 2109 | + if ( ! $saveControl.length || $saveControl.hasClass( 'disabled' ) || 'true' === $saveControl.attr( 'aria-disabled' ) ) { | |
| 2110 | + if ( typeof wpbc_admin_show_message === 'function' ) { | |
| 2111 | + wpbc_admin_show_message( '<?php echo esc_js( __( 'Please save changes on this page before continuing setup.', 'booking' ) ); ?>', 'warning', 4000, false ); | |
| 2112 | + } | |
| 2113 | + wpbcSetupWizardPulseSaveRequiredMessage(); | |
| 2114 | + return; | |
| 2115 | + } | |
| 2116 | + | |
| 2117 | + saveAndContinueRequested = true; | |
| 2118 | + wpbcSetupWizardSaveStarted(); | |
| 2119 | + wpbcSetupWizardSetSaveAndContinueBusy( true ); | |
| 2120 | + if ( formSelector ) { | |
| 2121 | + jQuery( formSelector ).find( 'input[name="wpbc_setup_continue_after_save"]' ).val( '1' ); | |
| 2122 | + } | |
| 2123 | + $saveControl.trigger( 'click' ); | |
| 2124 | + } | |
| 2125 | + | |
| 1935 | 2126 | if ( 'manual_save_required' === saveBehavior ) { |
| 1936 | 2127 | window.wpbc_setup_wizard_set_current_step_saved = wpbcSetupWizardSetSaved; |
| 1937 | 2128 | window.wpbc_setup_wizard_mark_current_step_saved = wpbcSetupWizardMarkSaved; |
| 1938 | 2129 | |
| @@ -1940,14 +2131,14 @@ | ||
| 1940 | 2131 | if ( ! event || ! event.detail || ! event.detail.payload || ! step ) { |
| 1941 | 2132 | return; |
| 1942 | 2133 | } |
| 1943 | 2134 | wpbcSetupWizardSaveStarted(); |
| 1944 | - event.detail.payload.wpbc_setup = '1'; | |
| 1945 | - event.detail.payload.wpbc_setup_step = step; | |
| 1946 | - if ( saveAndContinueRequested ) { | |
| 1947 | - event.detail.payload.wpbc_setup_continue_after_save = '1'; | |
| 1948 | - } | |
| 1949 | - }, true ); | |
| 2135 | + event.detail.payload.wpbc_setup = '1'; | |
| 2136 | + event.detail.payload.wpbc_setup_step = step; | |
| 2137 | + if ( saveAndContinueRequested ) { | |
| 2138 | + event.detail.payload.wpbc_setup_continue_after_save = '1'; | |
| 2139 | + } | |
| 2140 | + }, true ); | |
| 1950 | 2141 | |
| 1951 | 2142 | saveEvents.forEach( wpbcSetupWizardRegisterSavedEvent ); |
| 1952 | 2143 | |
| 1953 | 2144 | if ( formSelector ) { |
| @@ -1961,49 +2152,49 @@ | ||
| 1961 | 2152 | } |
| 1962 | 2153 | if ( ! $form.find( 'input[name="wpbc_setup_step"]' ).length ) { |
| 1963 | 2154 | $form.append( '<input type="hidden" name="wpbc_setup_step" value="" />' ); |
| 1964 | 2155 | } |
| 1965 | - if ( ! $form.find( 'input[name="wpbc_setup"]' ).length ) { | |
| 1966 | - $form.append( '<input type="hidden" name="wpbc_setup" value="" />' ); | |
| 1967 | - } | |
| 1968 | - if ( ! $form.find( 'input[name="wpbc_setup_continue_after_save"]' ).length ) { | |
| 1969 | - $form.append( '<input type="hidden" name="wpbc_setup_continue_after_save" value="" />' ); | |
| 1970 | - } | |
| 1971 | - $form.find( 'input[name="wpbc_setup_saved_step"]' ).val( step ); | |
| 1972 | - $form.find( 'input[name="wpbc_setup_step"]' ).val( step ); | |
| 1973 | - $form.find( 'input[name="wpbc_setup"]' ).val( '1' ); | |
| 1974 | - $form.find( 'input[name="wpbc_setup_continue_after_save"]' ).val( '0' ); | |
| 1975 | - $form | |
| 1976 | - .off( 'change.wpbc_setup_wizard input.wpbc_setup_wizard', ':input' ) | |
| 1977 | - .on( 'change.wpbc_setup_wizard input.wpbc_setup_wizard', ':input', function() { | |
| 1978 | - if ( jQuery( this ).is( '[name="wpbc_setup_saved_step"],[name="wpbc_setup_step"],[name="wpbc_setup"],[name="wpbc_setup_continue_after_save"],[name="form_visible_section"]' ) ) { | |
| 1979 | - return; | |
| 1980 | - } | |
| 1981 | - wpbcSetupWizardSetUnsaved(); | |
| 1982 | - } ); | |
| 2156 | + if ( ! $form.find( 'input[name="wpbc_setup"]' ).length ) { | |
| 2157 | + $form.append( '<input type="hidden" name="wpbc_setup" value="" />' ); | |
| 2158 | + } | |
| 2159 | + if ( ! $form.find( 'input[name="wpbc_setup_continue_after_save"]' ).length ) { | |
| 2160 | + $form.append( '<input type="hidden" name="wpbc_setup_continue_after_save" value="" />' ); | |
| 2161 | + } | |
| 2162 | + $form.find( 'input[name="wpbc_setup_saved_step"]' ).val( step ); | |
| 2163 | + $form.find( 'input[name="wpbc_setup_step"]' ).val( step ); | |
| 2164 | + $form.find( 'input[name="wpbc_setup"]' ).val( '1' ); | |
| 2165 | + $form.find( 'input[name="wpbc_setup_continue_after_save"]' ).val( '0' ); | |
| 1983 | 2166 | $form |
| 2167 | + .off( 'change.wpbc_setup_wizard input.wpbc_setup_wizard', ':input' ) | |
| 2168 | + .on( 'change.wpbc_setup_wizard input.wpbc_setup_wizard', ':input', function() { | |
| 2169 | + if ( jQuery( this ).is( '[name="wpbc_setup_saved_step"],[name="wpbc_setup_step"],[name="wpbc_setup"],[name="wpbc_setup_continue_after_save"],[name="form_visible_section"]' ) ) { | |
| 2170 | + return; | |
| 2171 | + } | |
| 2172 | + wpbcSetupWizardSetUnsaved(); | |
| 2173 | + } ); | |
| 2174 | + $form | |
| 1984 | 2175 | .off( 'submit.wpbc_setup_wizard' ) |
| 1985 | 2176 | .on( 'submit.wpbc_setup_wizard', function() { |
| 1986 | - wpbcSetupWizardSaveStarted(); | |
| 1987 | - $form.find( 'input[name="wpbc_setup_saved_step"]' ).val( step ); | |
| 1988 | - $form.find( 'input[name="wpbc_setup_step"]' ).val( step ); | |
| 1989 | - $form.find( 'input[name="wpbc_setup"]' ).val( '1' ); | |
| 1990 | - $form.find( 'input[name="wpbc_setup_continue_after_save"]' ).val( saveAndContinueRequested ? '1' : '0' ); | |
| 1991 | - } ); | |
| 1992 | - } ); | |
| 1993 | - } | |
| 1994 | - | |
| 1995 | - $continueButton.on( 'click', function( event ) { | |
| 1996 | - if ( '1' !== $bar.attr( 'data-wpbc-setup-is-saved' ) ) { | |
| 1997 | - event.preventDefault(); | |
| 1998 | - if ( saveSelector ) { | |
| 1999 | - wpbcSetupWizardTriggerSaveAndContinue(); | |
| 2000 | - return; | |
| 2001 | - } | |
| 2002 | - if ( typeof wpbc_admin_show_message === 'function' ) { | |
| 2003 | - wpbc_admin_show_message( '<?php echo esc_js( __( 'Please save changes on this page before continuing setup.', 'booking' ) ); ?>', 'warning', 4000, false ); | |
| 2004 | - } | |
| 2005 | - wpbcSetupWizardPulseSaveRequiredMessage(); | |
| 2177 | + wpbcSetupWizardSaveStarted(); | |
| 2178 | + $form.find( 'input[name="wpbc_setup_saved_step"]' ).val( step ); | |
| 2179 | + $form.find( 'input[name="wpbc_setup_step"]' ).val( step ); | |
| 2180 | + $form.find( 'input[name="wpbc_setup"]' ).val( '1' ); | |
| 2181 | + $form.find( 'input[name="wpbc_setup_continue_after_save"]' ).val( saveAndContinueRequested ? '1' : '0' ); | |
| 2182 | + } ); | |
| 2183 | + } ); | |
| 2184 | + } | |
| 2185 | + | |
| 2186 | + $continueButton.on( 'click', function( event ) { | |
| 2187 | + if ( '1' !== $bar.attr( 'data-wpbc-setup-is-saved' ) ) { | |
| 2188 | + event.preventDefault(); | |
| 2189 | + if ( saveSelector ) { | |
| 2190 | + wpbcSetupWizardTriggerSaveAndContinue(); | |
| 2191 | + return; | |
| 2192 | + } | |
| 2193 | + if ( typeof wpbc_admin_show_message === 'function' ) { | |
| 2194 | + wpbc_admin_show_message( '<?php echo esc_js( __( 'Please save changes on this page before continuing setup.', 'booking' ) ); ?>', 'warning', 4000, false ); | |
| 2195 | + } | |
| 2196 | + wpbcSetupWizardPulseSaveRequiredMessage(); | |
| 2006 | 2197 | } |
| 2007 | 2198 | } ); |
| 2008 | 2199 | |
| 2009 | 2200 | if ( saveSelector ) { |
| @@ -2015,57 +2206,69 @@ | ||
| 2015 | 2206 | } |
| 2016 | 2207 | } ); |
| 2017 | 2208 | } |
| 2018 | 2209 | |
| 2019 | - jQuery( document ).ajaxComplete( function( _event, xhr, ajaxSettings ) { | |
| 2020 | - var response; | |
| 2021 | - if ( ! saveClicked ) { | |
| 2022 | - return; | |
| 2023 | - } | |
| 2024 | - if ( ! wpbcSetupWizardIsExpectedSaveAjax( ajaxSettings ) ) { | |
| 2025 | - return; | |
| 2026 | - } | |
| 2027 | - saveClicked = false; | |
| 2210 | + jQuery( document ).ajaxComplete( function( _event, xhr, ajaxSettings ) { | |
| 2211 | + var response; | |
| 2212 | + if ( ! saveClicked ) { | |
| 2213 | + return; | |
| 2214 | + } | |
| 2215 | + if ( ! wpbcSetupWizardIsExpectedSaveAjax( ajaxSettings ) ) { | |
| 2216 | + return; | |
| 2217 | + } | |
| 2218 | + saveClicked = false; | |
| 2028 | 2219 | |
| 2029 | - response = xhr && xhr.responseJSON ? xhr.responseJSON : null; | |
| 2030 | - if ( ! response && xhr && xhr.responseText ) { | |
| 2031 | - try { | |
| 2032 | - response = JSON.parse( xhr.responseText ); | |
| 2033 | - } catch ( _e ) {} | |
| 2034 | - } | |
| 2035 | - if ( response && response.data && response.data.setup_step_saved ) { | |
| 2036 | - wpbcSetupWizardSetSaved(); | |
| 2037 | - if ( saveAndContinueRequested ) { | |
| 2038 | - wpbcSetupWizardContinueAfterSave(); | |
| 2039 | - } | |
| 2040 | - } else if ( wpbcSetupWizardLooksSuccessfulResponse( response ) ) { | |
| 2041 | - if ( saveAndContinueRequested ) { | |
| 2042 | - wpbcSetupWizardMarkSaved( wpbcSetupWizardContinueAfterSave ); | |
| 2043 | - } else { | |
| 2044 | - wpbcSetupWizardMarkSaved(); | |
| 2045 | - } | |
| 2046 | - } else if ( saveAndContinueRequested ) { | |
| 2047 | - wpbcSetupWizardSetSaveAndContinueBusy( false ); | |
| 2048 | - saveAndContinueRequested = false; | |
| 2049 | - } | |
| 2050 | - } ); | |
| 2051 | - } | |
| 2220 | + response = xhr && xhr.responseJSON ? xhr.responseJSON : null; | |
| 2221 | + if ( ! response && xhr && xhr.responseText ) { | |
| 2222 | + try { | |
| 2223 | + response = JSON.parse( xhr.responseText ); | |
| 2224 | + } catch ( _e ) {} | |
| 2225 | + } | |
| 2226 | + if ( response && response.data && response.data.setup_step_saved ) { | |
| 2227 | + wpbcSetupWizardSetSaved(); | |
| 2228 | + if ( saveAndContinueRequested ) { | |
| 2229 | + wpbcSetupWizardContinueAfterSave(); | |
| 2230 | + } | |
| 2231 | + } else if ( wpbcSetupWizardLooksSuccessfulResponse( response ) ) { | |
| 2232 | + if ( saveAndContinueRequested ) { | |
| 2233 | + wpbcSetupWizardMarkSaved( wpbcSetupWizardContinueAfterSave ); | |
| 2234 | + } else { | |
| 2235 | + wpbcSetupWizardMarkSaved(); | |
| 2236 | + } | |
| 2237 | + } else if ( saveAndContinueRequested ) { | |
| 2238 | + wpbcSetupWizardSetSaveAndContinueBusy( false ); | |
| 2239 | + saveAndContinueRequested = false; | |
| 2240 | + } | |
| 2241 | + } ); | |
| 2242 | + } | |
| 2052 | 2243 | |
| 2053 | - if ( highlightDisabled ) { | |
| 2054 | - highlightSelector = ''; | |
| 2055 | - } | |
| 2056 | - | |
| 2057 | - if ( ! selector && ! scrollSelector && ! highlightSelector ) { | |
| 2058 | - return; | |
| 2059 | - } | |
| 2060 | - | |
| 2061 | - $target = highlightDisabled ? jQuery() : wpbcSetupWizardGetFirstElement( highlightSelector || selector ); | |
| 2062 | - if ( ! highlightDisabled && $target.length ) { | |
| 2063 | - wpbcSetupWizardHighlightElement( $target ); | |
| 2064 | - } | |
| 2065 | - | |
| 2066 | - setTimeout( function() { | |
| 2067 | - var $scrollTarget = wpbcSetupWizardGetFirstElement( scrollSelector || ( highlightDisabled ? selector : highlightSelector ) || selector ); | |
| 2244 | + if ( highlightDisabled ) { | |
| 2245 | + highlightSelector = ''; | |
| 2246 | + } | |
| 2247 | + | |
| 2248 | + if ( ! selector && ! scrollSelector && ! highlightSelector ) { | |
| 2249 | + return; | |
| 2250 | + } | |
| 2251 | + | |
| 2252 | + if ( ! highlightDisabled && highlightAll ) { | |
| 2253 | + try { | |
| 2254 | + $highlightTargets = jQuery( highlightSelector || selector ).filter( ':visible' ); | |
| 2255 | + } catch ( _e ) { | |
| 2256 | + $highlightTargets = jQuery(); | |
| 2257 | + } | |
| 2258 | + | |
| 2259 | + $highlightTargets.each( function() { | |
| 2260 | + wpbcSetupWizardHighlightElement( jQuery( this ) ); | |
| 2261 | + } ); | |
| 2262 | + } else if ( ! highlightDisabled ) { | |
| 2263 | + $highlightTargets = wpbcSetupWizardGetFirstElement( highlightSelector || selector ); | |
| 2264 | + wpbcSetupWizardHighlightElement( $highlightTargets ); | |
| 2265 | + } | |
| 2266 | + | |
| 2267 | + $target = $highlightTargets.first(); | |
| 2268 | + | |
| 2269 | + setTimeout( function() { | |
| 2270 | + var $scrollTarget = wpbcSetupWizardGetFirstElement( scrollSelector || ( highlightDisabled ? selector : highlightSelector ) || selector ); | |
| 2068 | 2271 | if ( ! $scrollTarget.length ) { |
| 2069 | 2272 | $scrollTarget = $target; |
| 2070 | 2273 | } |
| 2071 | 2274 | wpbcSetupWizardScrollToElement( $scrollTarget ); |