Skip to:
Content

BuddyPress.org

Changeset 12060


Ignore:
Timestamp:
05/05/2018 06:48:40 AM (19 months ago)
Author:
imath
Message:

BP Nouveau: use a JS Template for the Group Invites UI feedbacks

Using a JS template avoids to transport common HTML tags inside the Ajax replies.

See #7794

Location:
trunk/src/bp-templates/bp-nouveau
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/buddypress/common/js-templates/invites/index.php

    r12059 r12060  
    2525
    2626</div>
     27
     28<script type="text/html" id="tmpl-bp-group-invites-feedback">
     29    <div class="bp-feedback {{data.type}}">
     30        <span class="bp-icon" aria-hidden="true"></span>
     31        <p>{{{data.message}}}</p>
     32    </div>
     33</script>
    2734
    2835<script type="text/html" id="tmpl-bp-invites-nav">
  • trunk/src/bp-templates/bp-nouveau/includes/groups/ajax.php

    r12024 r12060  
    254254
    255255    $response = array(
    256         'feedback' => bp_nouveau_message_markup_wrapper( esc_html__( 'There was a problem performing this action. Please try again.', 'buddypress' ), 'error' ),
     256        'feedback' => __( 'There was a problem performing this action. Please try again.', 'buddypress' ),
    257257        'type'     => 'error',
    258258    );
     
    282282
    283283    $bp->groups->invites_scope = 'members';
    284     $message = bp_nouveau_message_markup_wrapper( __( 'Select members to invite by clicking the + button. Once you\'ve made your selection, use the "Send Invites" nav item to continue.', 'buddypress' ), 'info' );
     284    $message = __( 'Select members to invite by clicking the + button. Once you\'ve made your selection, use the "Send Invites" nav item to continue.', 'buddypress' );
    285285
    286286    if ( 'friends' === $request['scope'] ) {
    287287        $request['user_id'] = bp_loggedin_user_id();
    288288        $bp->groups->invites_scope = 'friends';
    289         $message = bp_nouveau_message_markup_wrapper( __( 'Select friends to invite by clicking the + button. Once you\'ve made your selection, use the "Send Invites" nav item to continue.', 'buddypress' ), 'info' );
     289        $message = __( 'Select friends to invite by clicking the + button. Once you\'ve made your selection, use the "Send Invites" nav item to continue.', 'buddypress' );
    290290    }
    291291
     
    294294        if ( ! bp_group_has_invites( array( 'user_id' => 'any' ) ) ) {
    295295            wp_send_json_error( array(
    296                 'feedback' => bp_nouveau_message_markup_wrapper( __( 'No pending invites found.', 'buddypress' ), 'info' ),
     296                'feedback' => __( 'No pending invites found.', 'buddypress' ),
    297297                'type'     => 'info',
    298298            ) );
     
    301301        $request['is_confirmed'] = false;
    302302        $bp->groups->invites_scope = 'invited';
    303         $message = bp_nouveau_message_markup_wrapper( __( 'You can view all the group\'s pending invites from this screen.', 'buddypress' ), 'info' );
     303        $message = __( 'You can view all the group\'s pending invites from this screen.', 'buddypress' );
    304304    }
    305305
     
    308308    if ( empty( $potential_invites->users ) ) {
    309309        $error = array(
    310             'feedback' => bp_nouveau_message_markup_wrapper( __( 'No members were found. Try another filter.', 'buddypress' ), 'info' ),
     310            'feedback' => __( 'No members were found. Try another filter.', 'buddypress' ),
    311311            'type'     => 'info',
    312312        );
     
    314314        if ( 'friends' === $bp->groups->invites_scope ) {
    315315            $error = array(
    316                 'feedback' => bp_nouveau_message_markup_wrapper( __( 'All your friends are already members of this group, or have already received an invite to join this group, or have requested to join it.', 'buddypress' ), 'info' ),
     316                'feedback' => __( 'All your friends are already members of this group, or have already received an invite to join this group, or have requested to join it.', 'buddypress' ),
    317317                'type'     => 'info',
    318318            );
     
    320320            if ( 0 === (int) bp_get_total_friend_count( bp_loggedin_user_id() ) ) {
    321321                $error = array(
    322                     'feedback' => bp_nouveau_message_markup_wrapper( __( 'You have no friends!', 'buddypress' ), 'info' ),
     322                    'feedback' => __( 'You have no friends!', 'buddypress' ),
    323323                    'type'     => 'info',
    324324                );
     
    349349
    350350    $response = array(
    351         'feedback' => bp_nouveau_message_markup_wrapper( __( 'Invites could not be sent. Please try again.', 'buddypress' ), 'error' ),
     351        'feedback' => __( 'Invites could not be sent. Please try again.', 'buddypress' ),
     352        'type'     => 'error',
    352353    );
    353354
    354355    // Verify nonce
    355356    if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'groups_send_invites' ) ) {
    356         wp_send_json_error(
    357             array(
    358                 'feedback' => bp_nouveau_message_markup_wrapper( __( 'Invites could not be sent. Please try again.', 'buddypress' ), 'error' ),
    359                 'type'     => 'error',
    360             )
    361         );
     357        wp_send_json_error( $response );
    362358    }
    363359
     
    369365
    370366    if ( ! bp_groups_user_can_send_invites( $group_id ) ) {
    371         wp_send_json_error(
    372             array(
    373                 'feedback' => bp_nouveau_message_markup_wrapper( __( 'You are not allowed to send invites for this group.', 'buddypress' ), 'error' ),
    374                 'type'     => 'error',
    375             )
    376         );
     367        $response['feedback'] = __( 'You are not allowed to send invites for this group.', 'buddypress' );
     368        wp_send_json_error( $response );
    377369    }
    378370
     
    416408        wp_send_json_error(
    417409            array(
    418                 'feedback' => bp_nouveau_message_markup_wrapper( esc_html( $error_message ), 'error' ),
     410                'feedback' => $error_message,
    419411                'users'    => $errors,
    420412                'type'     => 'error',
     
    425417    wp_send_json_success(
    426418        array(
    427             'feedback' => bp_nouveau_message_markup_wrapper( __( 'Invites sent.', 'buddypress' ), 'success' ),
     419            'feedback' => __( 'Invites sent.', 'buddypress' ),
     420            'type'     => 'success',
    428421        )
    429422    );
     
    441434        wp_send_json_error(
    442435            array(
    443                 'feedback' => bp_nouveau_message_markup_wrapper( __( 'Invites could not be removed. Please try again.', 'buddypress' ), 'error' ),
     436                'feedback' => __( 'Invites could not be removed. Please try again.', 'buddypress' ),
     437                'type'     => 'error',
    444438            )
    445439        );
     
    449443        wp_send_json_error(
    450444            array(
    451                 'feedback' => bp_nouveau_message_markup_wrapper( __( 'Too late! The user is already a member of the group.', 'buddypress' ), 'warning' ),
     445                'feedback' => __( 'Too late! The user is already a member of the group.', 'buddypress' ),
     446                'type'     => 'warning',
    452447                'code'     => 1,
    453448            )
     
    459454        wp_send_json_error(
    460455            array(
    461                 'feedback' => bp_nouveau_message_markup_wrapper( __( 'Invite could not be removed successfully.', 'buddypress' ), 'error' ),
     456                'feedback' => __( 'Invite could not be removed successfully.', 'buddypress' ),
     457                'type'     => 'error',
    462458                'code'     => 0,
    463459            )
     
    467463    wp_send_json_success(
    468464        array(
    469             'feedback'    => bp_nouveau_message_markup_wrapper( __( 'No more pending invites for the group.', 'buddypress' ), 'info' ),
     465            'feedback'    => __( 'No more pending invites for the group.', 'buddypress' ),
     466            'type'        => 'info',
    470467            'has_invites' => bp_group_has_invites( array( 'user_id' => 'any' ) ),
    471468        )
  • trunk/src/bp-templates/bp-nouveau/includes/groups/functions.php

    r12059 r12060  
    147147    $params['group_invites'] = array(
    148148        'nav'                => bp_sort_by_key( $invites_nav, 'order', 'num' ),
    149         'loading'            => bp_nouveau_message_markup_wrapper( __( 'Loading members. Please wait.', 'buddypress' ), 'loading' ),
    150         'invites_form'       => bp_nouveau_message_markup_wrapper( __( 'Use the "Send" button to send your invite or the "Cancel" button to abort.', 'buddypress' ), 'info' ),
    151         'invites_form_reset' => bp_nouveau_message_markup_wrapper( __( 'Invites cleared. Please use one of the available tabs to select members to invite.', 'buddypress' ), 'success' ),
    152         'invites_sending'    => bp_nouveau_message_markup_wrapper( __( 'Sending the invites. Please wait.', 'buddypress' ), 'loading' ),
     149        'loading'            => __( 'Loading members. Please wait.', 'buddypress' ),
     150        'invites_form'       => __( 'Use the "Send" button to send your invite or the "Cancel" button to abort.', 'buddypress' ),
     151        'invites_form_reset' => __( 'Invites cleared. Please use one of the available tabs to select members to invite.', 'buddypress' ),
     152        'invites_sending'    => __( 'Sending the invites. Please wait.', 'buddypress' ),
    153153        'group_id'           => ! bp_get_current_group_id() ? bp_get_new_group_id() : bp_get_current_group_id(),
    154154        'is_group_create'    => bp_is_group_create(),
  • trunk/src/bp-templates/bp-nouveau/js/buddypress-group-invites.js

    r12059 r12060  
    339339        tagName   : 'div',
    340340        className : 'bp-invites-feedback',
     341        template  : bp.template( 'bp-group-invites-feedback' ),
    341342
    342343        initialize: function() {
    343             this.value = this.options.value;
    344 
    345             if ( this.options.type ) {
    346                 this.el.className += ' ' + this.options.type;
    347             }
    348         },
    349 
    350         render: function() {
    351             this.$el.html( this.value );
    352             return this;
     344            this.model = new Backbone.Model( {
     345                type: this.options.type || 'info',
     346                message: this.options.value
     347            } );
    353348        }
    354349    } );
     
    716711            $( this.el ).addClass( 'bp-hide' );
    717712
     713            bp.Nouveau.GroupInvites.displayFeedback( BP_Nouveau.group_invites.invites_sending, 'info' );
     714
    718715            this.collection.sync( 'create', _.pluck( this.collection.models, 'id' ), {
    719716                success : _.bind( this.invitesSent, this ),
     
    769766            } );
    770767
    771             bp.Nouveau.GroupInvites.displayFeedback( BP_Nouveau.group_invites.invites_form_reset, 'help' );
     768            bp.Nouveau.GroupInvites.displayFeedback( BP_Nouveau.group_invites.invites_form_reset, 'success' );
    772769        }
    773770    } );
Note: See TracChangeset for help on using the changeset viewer.