Making WordPress.org

Changeset 2682


Ignore:
Timestamp:
03/03/2016 07:33:42 PM (11 years ago)
Author:
iandunn
Message:

WordCamp Budgets: Make Vendor Payment and Payment Method fields required.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-budgets.css

    r2633 r2682  
    5454        color: #dc3232;
    5555}
     56
     57/* Make room for the required field indicator (*) */
     58body.post-type-wcp_payment_request input.large-text,
     59body.post-type-wcp_payment_request input.regular-text,
     60body.post-type-wcp_payment_request textarea.large-text,
     61body.post-type-wcp_payment_request .meta-box-sortables select {
     62        width: 95%;
     63}
     64
     65@media screen and ( max-width: 782px ) {
     66        body.post-type-wcp_payment_request .form-table td textarea {
     67                display: inline;
     68                width: 95%;
     69        }
     70}
     71
    5672
    5773/* margins from above selector aren't applied */
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/payment-request.php

    r2676 r2682  
    180180                        plugins_url( 'javascript/payment-requests.js', __DIR__ ),
    181181                        array( 'wordcamp-budgets', 'wcb-attached-files', 'jquery' ),
    182                         2,
     182                        3,
    183183                        true
    184184                );
    … …  
    339339         * @param string $name
    340340         * @param string $description
    341          */
    342         protected function render_textarea_input( $post, $label, $name, $description = '' ) {
     341         * @param bool   $required
     342         */
     343        protected function render_textarea_input( $post, $label, $name, $description = '', $required = true ) {
    343344                $text = $this->get_field_value( $name, $post );
    344345
    … …  
    352353         * @param string $label
    353354         * @param string $name
    354          */
    355         protected function render_select_input( $post, $label, $name ) {
     355         * @param bool   $required
     356         */
     357        protected function render_select_input( $post, $label, $name, $required = true ) {
    356358                $selected = get_post_meta( $post->ID, '_camppayments_' . $name, true );
    357359                $options  = $this->get_field_value( $name, $post );
    … …  
    360362        }
    361363
    362         protected function render_country_input( $post, $label, $name ) {
     364        /**
     365         * Render a select dropdown for countries
     366         *
     367         * @param WP_Post $post
     368         * @param string  $label
     369         * @param string  $name
     370         * @param bool    $required
     371         */
     372        protected function render_country_input( $post, $label, $name, $required = true ) {
    363373                $selected = $this->get_field_value( $name, $post );
    364374                $options = WordCamp_Budgets::get_valid_countries_iso3166();
    … …  
    373383         * @param string $label
    374384         * @param string $name
    375          */
    376         protected function render_radio_input( $post, $label, $name ) {
     385         * @param bool   $required
     386         */
     387        protected function render_radio_input( $post, $label, $name, $required = true ) {
    377388                $selected = get_post_meta( $post->ID, "_{$this->meta_key_prefix}_" . $name, true );
    378389                $options  = $this->get_field_value( $name, $post );
    … …  
    387398         * @param string $label
    388399         * @param string $name
    389          */
    390         protected function render_checkbox_input( $post, $label, $name, $description = '' ) {
     400         * @param bool   $required
     401         */
     402        protected function render_checkbox_input( $post, $label, $name, $description = '', $required = true ) {
    391403                $value = $this->get_field_value( $name, $post );
    392404
    … …  
    400412         * @param string $label
    401413         * @param string $name
    402          */
    403         protected function render_text_input( $post, $label, $name, $description = '', $variant = 'text', $row_classes = array(), $readonly = false ) {
     414         * @param string $description
     415         * @param string $variant
     416         * @param array  $row_classes
     417         * @param bool   $readonly
     418         * @param bool   $required
     419         */
     420        protected function render_text_input( $post, $label, $name, $description = '', $variant = 'text', $row_classes = array(), $readonly = false, $required = true ) {
    404421                $value = $this->get_field_value( $name, $post );
    405422                array_walk( $row_classes, 'sanitize_html_class' );
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/wordcamp-budgets.php

    r2677 r2682  
    129129                        plugins_url( 'javascript/wordcamp-budgets.js', __DIR__ ),
    130130                        array( 'jquery', 'jquery-ui-datepicker', 'media-upload', 'media-views' ),
    131                         1,
     131                        2,
    132132                        true
    133133                );
    … …  
    161161                        plugins_url( 'css/wordcamp-budgets.css', __DIR__ ),
    162162                        $soft_deps,
    163                         2
     163                        3
    164164                );
    165165        }
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/payment-requests.js

    r2633 r2682  
    2424                registerEventHandlers : function() {
    2525                        var currency        = $( '#currency' );
    26                         var paymentCategory = $( '#payment_category' );
     26                        var paymentCategory = $( '#payment_category' ),
     27                                paymentDetails  = $( '#wcp_payment_details' );
    2728
    28                         $( '#wcp_payment_details' ).find( 'input[name=payment_method]' ).change( wcb.togglePaymentMethodFields );
     29                        paymentDetails.find( 'input[name=payment_method]' ).change( wcb.togglePaymentMethodFields );
     30                        paymentDetails.find( 'input[name=payment_method]:checked' ).trigger( 'change' ); // Set the initial state
     31
    2932                        paymentCategory.change( app.toggleOtherCategoryDescription );
    3033                        paymentCategory.trigger( 'change' );   // Set the initial state
     34
    3135                        currency.change( wcb.setDefaultPaymentMethod );
    3236                        currency.trigger( 'change' );   // Set the initial state
     37
    3338                        $( '#row-files' ).find( 'a.wcb-insert-media' ).click( wcb.showUploadModal );
    3439
    … …  
    5358                                if ( 'other' == $( this ).find( 'option:selected' ).val() ) {
    5459                                        $( otherCategoryDescription ).removeClass( 'hidden' );
     60                                        $( otherCategoryDescription ).find( ':input' ).prop( 'required', true );
    5561                                } else {
    5662                                        $( otherCategoryDescription ).addClass( 'hidden' );
     63                                        $( otherCategoryDescription ).find( ':input' ).prop( 'required', false );
    5764                                }
    5865
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/reimbursement-requests.js

    r2646 r2682  
    3131                registerEventHandlers : function() {
    3232                        var reason   = $( '#_wcbrr_reason'   ),
    33                                 currency = $( '#_wcbrr_currency' );
     33                                currency = $( '#_wcbrr_currency' ),
     34                                paymentMethod = $( '#row-payment-method' );
    3435
    3536                        reason.change( app.toggleOtherReasonDescription );
    … …  
    3940                        currency.trigger( 'change' );   // Set the initial state
    4041
    41                         $( '#row-payment-method' ).find( 'input[name=payment_method]' ).change( wcb.togglePaymentMethodFields );
     42                        paymentMethod.find( 'input[name=payment_method]' ).change( wcb.togglePaymentMethodFields );
     43                        paymentMethod.find( 'input[name=payment_method]:checked' ).trigger( 'change' ); // Set the initial state
     44
    4245                        $( '#wcbrr_general_information' ).find( 'a.wcb-insert-media' ).click(   wcb.showUploadModal           );
    4346                        $( '#wcbrr-add-another-expense' ).click(                                app.addNewExpense             );
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/wordcamp-budgets.js

    r2677 r2682  
    3131                togglePaymentMethodFields : function( event ) {
    3232                        var active_fields_container = '#' + $( this ).attr( 'id' ) + '_fields';
    33                         var payment_method_fields   = '.payment_method_fields';
     33                        var payment_method_fields   = '.payment_method_fields',
     34                                optionalFields          = [ 'needs_intermediary_bank' ];
    3435
    3536                        $( payment_method_fields   ).removeClass( 'active' );
    3637                        $( payment_method_fields   ).addClass( 'hidden' );
     38
     39                        $( payment_method_fields ).each( function( containerIndex, fieldContainer ) {
     40                                $( fieldContainer ).find( ':input' ).each( function( fieldIndex, inputField ) {
     41                                        $( inputField ).prop( 'required', false );
     42                                } );
     43                        } );
     44
    3745                        $( active_fields_container ).removeClass( 'hidden' );
    3846                        $( active_fields_container ).addClass( 'active' );
     47
     48                        $( active_fields_container ).find( ':input' ).each( function( index, field ) {
     49                                if ( $.inArray( $( field ).prop( 'id' ), optionalFields ) > -1 ) {
     50                                        return;
     51                                }
     52
     53                                $( field ).prop( 'required', true );
     54                        } );
     55
     56                        /*
     57                         * Also toggle intermediary bank fields, because otherwise switching to Wire from another method
     58                         * wouldn't remove `required` attributes.
     59                         */
     60                        app.toggleIntermediaryBankFields( event );
    3961
    4062                        // todo make the transition smoother
    … …  
    5577                                        if ( isWirePayment && needsIntermediaryBank ) {
    5678                                                $( row ).removeClass( 'hidden' );
     79                                                $( row ).find( ':input' ).prop( 'required', true );
    5780                                        } else {
    5881                                                $( row ).addClass( 'hidden' );
     82                                                $( row ).find( ':input' ).prop( 'required', false );
    5983                                        }
    6084                                } );
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/input-country.php

    r2494 r2682  
    55                </label>
    66        </th>
     7
    78        <td>
    8                 <select id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>">
     9                <select
     10                        id="<?php echo esc_attr( $name ); ?>"
     11                        name="<?php echo esc_attr( $name ); ?>"
     12                        <?php __checked_selected_helper( $required, true, true, 'required' ); ?>
     13                >
    914                        <option value="">(None)</option>
    1015                        <?php foreach ( $options as $value => $option_label ) : ?>
    … …  
    1419                        <?php endforeach; ?>
    1520                </select>
     21
     22                <?php
     23                        if ( $required ) {
     24                                WordCamp_Budgets::render_form_field_required_indicator();
     25                        }
     26                ?>
    1627        </td>
    1728</tr>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/input-radio.php

    r995 r2682  
    1414                                value="<?php echo esc_attr( $option ); ?>"
    1515                                <?php checked( $option, $selected ); ?>
     16                                <?php __checked_selected_helper( $required, true, true, 'required' ); ?>
    1617                                />
    1718
    … …  
    2021                        </label>
    2122                <?php endforeach; ?>
     23
     24                <?php
     25                        if ( $required ) {
     26                                WordCamp_Budgets::render_form_field_required_indicator();
     27                        }
     28                ?>
    2229        </td>
    2330</tr>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/input-select.php

    r995 r2682  
    77
    88        <td>
    9                 <select id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>">
     9                <select
     10                        id="<?php echo esc_attr( $name ); ?>"
     11                        name="<?php echo esc_attr( $name ); ?>"
     12                    <?php __checked_selected_helper( $required, true, true, 'required' ); ?>
     13                >
    1014                        <option value="null-select-one">
    1115                                <?php printf( __( '-- Select a %s --', 'wordcamporg' ), $label ); ?>
    … …  
    1923                        <?php endforeach; ?>
    2024                </select>
     25
     26                <?php
     27                        if ( $required ) {
     28                                WordCamp_Budgets::render_form_field_required_indicator();
     29                        }
     30                ?>
    2131        </td>
    2232</tr>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/input-text.php

    r2060 r2682  
    1313                        value="<?php echo esc_attr( $value ); ?>"
    1414                        <?php if ( $readonly ) { echo 'readonly="readonly"'; } ?>
     15                        <?php __checked_selected_helper( $required, true, true, 'required' ); ?>
    1516                        class="regular-text"
    1617                        />
     18
     19                <?php
     20                        if ( $required ) {
     21                                WordCamp_Budgets::render_form_field_required_indicator();
     22                        }
     23                ?>
    1724
    1825                <?php if ( ! empty( $description ) ) : ?>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/input-textarea.php

    r2416 r2682  
    77
    88        <td>
    9                 <textarea id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>" class="large-text"><?php
     9                <textarea
     10                        id="<?php echo esc_attr( $name ); ?>"
     11                        name="<?php echo esc_attr( $name ); ?>"
     12                        class="large-text"
     13                    <?php __checked_selected_helper( $required, true, true, 'required' ); ?>
     14                ><?php
    1015                        echo esc_html( $text );
    1116                ?></textarea>
     17
     18                <?php
     19                        if ( $required ) {
     20                                WordCamp_Budgets::render_form_field_required_indicator();
     21                        }
     22                ?>
    1223
    1324                <?php if ( ! empty( $description ) ) : ?>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-general.php

    r2676 r2682  
    2424        <?php $this->render_textarea_input( $post, 'Notes', 'general_notes', 'Any other details you want to share.' ); ?>
    2525</table>
     26
     27<p class="wcb-form-required">
     28        <?php _e( '* required', 'wordcamporg' ); ?>
     29</p>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-payment.php

    r2677 r2682  
    99        <table class="form-table">
    1010                <?php if ( $box['args']['show_vendor_requested_payment_method'] ) : ?>
    11                         <?php $this->render_textarea_input( $post, 'Did the vendor request a specific type of payment?', 'vendor_requested_payment_method', 'Add any relevant details' ); ?>
     11                        <?php $this->render_textarea_input( $post, 'Did the vendor request a specific type of payment?', 'vendor_requested_payment_method', 'Add any relevant details', false ); ?>
    1212                <?php endif;?>
    1313
    … …  
    7777                ); ?>
    7878
    79                 <table>
     79                <table id="intermediary_bank_fields">
    8080                        <?php $this->render_text_input( $post, 'Intermediary Bank Name',              'interm_bank_name' ); ?>
    8181                        <?php $this->render_text_input( $post, 'Intermediary Bank Street Address',    'interm_bank_street_address' ); ?>
    … …  
    104104        </div>
    105105</fieldset>
     106
     107<p class="wcb-form-required">
     108        <?php _e( '* required', 'wordcamporg' ); ?>
     109</p>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-status.php

    r2643 r2682  
    2929                        <?php if ( $post->post_status != 'auto-draft' ) : ?>
    3030                        <div class="misc-pub-section">
    31                                 <?php $this->render_text_input( $post, 'Date Vendor was Paid', 'date_vendor_paid', '', 'date', array(), $date_vendor_paid_readonly ); ?>
     31                                <?php $this->render_text_input( $post, 'Date Vendor was Paid', 'date_vendor_paid', '', 'date', array(), $date_vendor_paid_readonly, false ); ?>
    3232                        </div>
    3333
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/payment-request/metabox-vendor.php

    r2494 r2682  
    1313        ?>
    1414</table>
     15
     16<p class="wcb-form-required">
     17        <?php _e( '* required', 'wordcamporg' ); ?>
     18</p>
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/wordcamp-budgets/form-field-required-indicator.php

    r2605 r2682  
    11
    2 <span class="wcb-form-required" aria-hidden="true">
    3         <?php // translators: The symbol to indicate the form field is required ?>
    4         <?php _e( '*', 'wordcamporg' ); ?>
     2<span class="wcb-form-required">
     3        <span aria-hidden="true">
     4                <?php // translators: The symbol to indicate the form field is required ?>
     5                <?php _e( '*', 'wordcamporg' ); ?>
     6        </span>
     7
     8        <span class="screen-reader-text">
     9                <?php _e( 'required field', 'wordcamporg' ); ?>
     10        </span>
    511</span>
    6 
    7 <span class="screen-reader-text">
    8         <?php _e( 'required field', 'wordcamporg' ); ?>
    9 </span>
Note: See TracChangeset for help on using the changeset viewer.