Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/04/2017 03:46:56 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Converter: Styling updates

  • Move all admin CSS & JS into /admin/assets/
  • Introduce converter.js and refactor code out of admin_head() method
  • Move converter styling into common.css
  • Update some surrounding styling, verbiage, and mark-up to better handle errors and user feedback
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/classes/class-bbp-converter.php

    r6460 r6472  
    147147        public function admin_head() {
    148148
    149                 // For Converter Status
    150                 wp_enqueue_script( 'postbox' );
     149                // Variables
     150                $bbp        = bbpress();
     151                $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
     152                $repair_url = add_query_arg( array(
     153                        'page' => 'bbp-repair'
     154                ), admin_url() );
     155
     156                // Enqueue scripts
     157                wp_enqueue_script( 'postbox'   );
    151158                wp_enqueue_script( 'dashboard' );
    152 
    153                 // Was a conversion started?
    154                 $started = (bool) get_option( '_bbp_converter_step', false );
    155                 $halt    = defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY; ?>
    156 
    157                 <style type="text/css" media="screen">
    158                         /*<![CDATA[*/
    159 
    160                         div.bbp-converter-monitor .inside {
    161                                 margin-bottom: 0;
    162                         }
    163 
    164                         div.bbp-converter-updated,
    165                         div.bbp-converter-warning {
    166                                 padding: 5px 0 5px 5px;
    167                         }
    168 
    169                         div.bbp-converter-updated.started {
    170                                 height: 300px;
    171                                 overflow: auto;
    172                         }
    173 
    174                         div.bbp-converter-updated p {
    175                                 margin: 0;
    176                                 padding: 2px;
    177                                 float: left;
    178                                 clear: left;
    179                         }
    180 
    181                         div.bbp-converter-updated p:only-child {
    182                                 float: none;
    183                                 margin-bottom: 0;
    184                         }
    185 
    186                         div.bbp-converter-updated p.loading {
    187                                 padding: 2px 25px 2px 2px;
    188                                 background-image: url('<?php echo admin_url(); ?>images/spinner.gif');
    189                                 background-repeat: no-repeat;
    190                                 background-position: center right;
    191                         }
    192 
    193                         #bbp-converter-stop {
    194                                 display:none;
    195                         }
    196 
    197                         /*]]>*/
    198                 </style>
    199 
    200                 <script language="javascript">
    201 
    202                         var bbpconverter_halt_on_error = <?php echo ( true === $halt    ) ? 'true' : 'false'; ?>,
    203                                 bbconverter_started        = <?php echo ( true === $started ) ? 'true' : 'false'; ?>,
    204                                 bbconverter_is_running     = false,
    205                                 bbconverter_delay_time     = 0,
    206                                 bbconverter_run_timer;
    207 
    208                         function bbconverter_grab_data() {
    209                                 var values = {};
    210 
    211                                 jQuery.each(jQuery('#bbp-converter-settings').serializeArray(), function(i, field) {
    212                                         values[field.name] = field.value;
    213                                 });
    214 
    215                                 if( values['_bbp_converter_restart'] ) {
    216                                         jQuery('#_bbp_converter_restart').removeAttr("checked");
    217                                 }
    218 
    219                                 if( values['_bbp_converter_delay_time'] ) {
    220                                         bbconverter_delay_time = values['_bbp_converter_delay_time'] * 1000;
    221                                 }
    222 
    223                                 values['action']      = 'bbp_converter_process';
    224                                 values['_ajax_nonce'] = '<?php echo wp_create_nonce( 'bbp_converter_process' ); ?>';
    225 
    226                                 return values;
    227                         }
    228 
    229                         function bbconverter_start() {
    230                                 if ( false === bbconverter_is_running ) {
    231                                         bbconverter_is_running = true;
    232 
    233                                         jQuery('#bbp-converter-message').addClass('started');
    234                                         jQuery('#bbp-converter-start').hide();
    235                                         jQuery('#bbp-converter-stop').show();
    236 
    237                                         if ( true === bbconverter_started ) {
    238                                                 bbconverter_log( '<p class="loading"><?php esc_html_e( 'Continuing Import', 'bbpress' ); ?></p>' );
    239                                         } else {
    240                                                 bbconverter_log( '<p class="loading"><?php esc_html_e( 'Starting Import', 'bbpress' ); ?></p>' );
    241                                         }
    242 
    243                                         bbconverter_run();
    244                                 }
    245 
    246                                 bbconverter_started = true;
    247                         }
    248 
    249                         function bbconverter_run() {
    250                                 jQuery.post(ajaxurl, bbconverter_grab_data(), function(response) {
    251                                         if ( 'bbp_converter_db_connection_failed' === response ) {
    252                                                 bbconverter_error_db();
    253                                                 return;
    254                                         }
    255 
    256                                         var response_length = response.length - 1;
    257                                         response = response.substring(0,response_length);
    258                                         bbconverter_success(response);
    259                                 });
    260                         }
    261 
    262                         function bbconverter_stop() {
    263                                 jQuery('#bbp-converter-start')
    264                                         .val( '<?php esc_html_e( 'Continue', 'bbpress' ); ?>' )
    265                                         .show();
    266 
    267                                 jQuery('#bbp-converter-stop').hide();
    268 
    269                                 bbconverter_log( '<p><?php esc_html_e( 'Import Stopped (by User)', 'bbpress' ); ?></p>' );
    270                                 bbconverter_is_running = false;
    271 
    272                                 clearTimeout( bbconverter_run_timer );
    273                         }
    274 
    275                         function bbconverter_error_db() {
    276                                 jQuery('#bbp-converter-start')
    277                                         .val( '<?php esc_html_e( 'Start', 'bbpress' ); ?>' )
    278                                         .show();
    279 
    280                                 jQuery('#bbp-converter-stop').hide();
    281 
    282                                 bbconverter_log( '<p><?php esc_html_e( 'Database Connection Failed', 'bbpress' ); ?></p>' );
    283                                 bbconverter_is_running = false;
    284 
    285                                 clearTimeout( bbconverter_run_timer );
    286                         }
    287 
    288                         function bbconverter_error_halt() {
    289                                 jQuery('#bbp-converter-start')
    290                                         .val( '<?php esc_html_e( 'Continue', 'bbpress' ); ?>' )
    291                                         .show();
    292 
    293                                 jQuery('#bbp-converter-stop').hide();
    294 
    295                                 bbconverter_log( '<p><?php esc_html_e( 'Import Halted (Error)', 'bbpress' ); ?></p>' );
    296                                 bbconverter_is_running = false;
    297 
    298                                 clearTimeout( bbconverter_run_timer );
    299                         }
    300 
    301                         function bbconverter_success(response) {
    302                                 bbconverter_log(response);
    303 
    304                                 if ( response === '<p class="loading"><?php esc_html_e( 'Import Complete', 'bbpress' ); ?></p>' ) {
    305                                         bbconverter_success_complete();
    306 
    307                                 } else if ( bbconverter_is_running ) {
    308                                         clearTimeout( bbconverter_run_timer );
    309                                         bbconverter_run_timer = setTimeout( 'bbconverter_run()', bbconverter_delay_time );
    310 
    311                                 } else if ( true === bbpconverter_halt_on_error ) {
    312                                         if ( response.indexOf('error') > -1 ) {
    313                                                 bbconverter_error_halt();
    314                                         } else {
    315                                                 bbconverter_error_halt();
    316                                         }
    317                                 }
    318                         }
    319 
    320                         function bbconverter_success_complete() {
    321                                 jQuery('#bbp-converter-start')
    322                                         .val( '<?php esc_html_e( 'Start', 'bbpress' ); ?>' )
    323                                         .show();
    324 
    325                                 jQuery('#bbp-converter-stop').hide();
    326 
    327                                 bbconverter_log('<p><?php printf( esc_html__( 'Repair any missing information: %s', 'bbpress' ), '<a href="' . admin_url() . 'tools.php?page=bbp-repair">' . esc_html__( 'Continue', 'bbpress' ) . '</a>' ); ?></p>' );
    328 
    329                                 bbconverter_is_running = false;
    330                                 bbconverter_started    = false;
    331 
    332                                 clearTimeout( bbconverter_run_timer );
    333                         }
    334 
    335                         function bbconverter_log(text) {
    336                                 jQuery('#bbp-converter-message p').removeClass( 'loading' );
    337                                 jQuery('#bbp-converter-message').prepend( text );
    338                         }
    339 
    340                 </script>
    341 
    342                 <?php
     159                wp_enqueue_script( 'bbp-converter', $bbp->admin->js_url . 'converter' . $suffix . '.js', array( 'jquery' ), $bbp->asset_version, true );
     160
     161                // Localize JS
     162                wp_localize_script( 'bbp-converter', 'BBP_Converter', array(
     163
     164                        // Vars
     165                        'ajax_nonce' => wp_create_nonce( 'bbp_converter_process' ),
     166                        'halt'       => (bool) defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY,
     167                        'started'    => (bool) get_option( '_bbp_converter_step', false ),
     168                        'running'    => false,
     169                        'complete'   => false,
     170                        'delay'      => 0,
     171
     172                        // Strings
     173                        'strings'    => array(
     174
     175                                // Button text
     176                                'button_start'    => esc_html__( 'Start',    'bbpress' ),
     177                                'button_continue' => esc_html__( 'Continue', 'bbpress' ),
     178
     179                                // Start button clicked
     180                                'start_start'    => esc_html__( 'Starting Import',   'bbpress' ),
     181                                'start_continue' => esc_html__( 'Continuing Import', 'bbpress' ),
     182
     183                                // Import
     184                                'import_success'      => sprintf( esc_html__( 'Repair any missing information: %s', 'bbpress' ), '<a href="' . esc_url( $repair_url ) . '">' . esc_html__( 'Continue', 'bbpress' ) . '</a>' ),
     185                                'import_complete'     => esc_html__( 'Import Complete',            'bbpress' ),
     186                                'import_stopped_user' => esc_html__( 'Import Stopped (by User)',   'bbpress' ),
     187                                'import_error_db'     => esc_html__( 'Database Connection Failed', 'bbpress' ),
     188                                'import_error_halt'   => esc_html__( 'Import Halted (Error)',      'bbpress' ),
     189                        )
     190                ) );
    343191        }
    344192
    … …  
    371219        private function converter_output( $output = '' ) {
    372220
    373                 // Get the last query
    374                 $before = '<p class="loading">';
    375                 $after  = '</p>';
    376 
    377221                // Maybe include last query
    378                 $query  = get_option( '_bbp_converter_query' );
     222                $query = get_option( '_bbp_converter_query' );
    379223                if ( ! empty( $query ) ) {
    380224                        $output = $output . '<span class="query">' . esc_attr( $query ) . '</span>';
    … …  
    383227                // Maybe prepend the step
    384228                $step = ! empty( $this->step )
    385                         ? sprintf( '%s: ', $this->step )
     229                        ? sprintf( '<span class="step">%s:</span> ', $this->step )
    386230                        : '';
    387231
    388232                // Output
    389                 echo $before . $step . $output . $after;
     233                echo $step . $output;
    390234        }
    391235
    … …  
    782626                                break;
    783627
     628                        // Done
    784629                        default :
    785630                                $this->reset();
Note: See TracChangeset for help on using the changeset viewer.