Skip to:
Content

BuddyPress.org

Changeset 12134


Ignore:
Timestamp:
05/26/2018 12:49:25 PM (8 years ago)
Author:
imath
Message:

Messages UI: Create a new Backbone view to wrap hooks caught output

This new view can be used when hooks caught output cannot be inserted into regular views. bp_before_member_messages_loop and bp_before_member_messages_loop are two good examples.

Fixes #7850 (Branch 3.0)

Location:
branches/3.0/src/bp-templates/bp-nouveau
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/src/bp-templates/bp-nouveau/buddypress/common/js-templates/messages/index.php

    r12122 r12134  
    2020        <p>{{{data.message}}}</p>
    2121    </div>
     22</script>
     23
     24<?php
     25/**
     26 * This view is used to inject hooks buffer
     27 */
     28?>
     29<script type="text/html" id="tmpl-bp-messages-hook">
     30    {{{data.extraContent}}}
    2231</script>
    2332
  • branches/3.0/src/bp-templates/bp-nouveau/includes/messages/ajax.php

    r12122 r12134  
    224224    }
    225225
    226     if ( isset( $_POST['box'] ) && 'starred' === $_POST['box'] ) {
    227         $star_filter = true;
    228 
    229         // Add the message thread filter.
     226    $bp           = buddypress();
     227    $reset_action = $bp->current_action;
     228
     229    // Override bp_current_action().
     230    if ( isset( $_POST['box'] ) ) {
     231        $bp->current_action = $_POST['box'];
     232    }
     233
     234    // Add the message thread filter.
     235    if ( 'starred' === $bp->current_action ) {
    230236        add_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' );
    231237    }
     
    233239    // Simulate the loop.
    234240    if ( ! bp_has_message_threads( bp_ajax_querystring( 'messages' ) ) ) {
     241        // Remove the bp_current_action() override.
     242        $bp->current_action = $reset_action;
     243
    235244        wp_send_json_error( array(
    236245            'feedback' => __( 'Sorry, no messages were found.', 'buddypress' ),
     
    239248    }
    240249
    241     if ( ! empty( $star_filter ) ) {
    242         // remove the message thread filter.
     250    // remove the message thread filter.
     251    if ( 'starred' === $bp->current_action ) {
    243252        remove_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_filter_starred_message_threads' );
    244253    }
     
    320329    $threads->threads = array_filter( $threads->threads );
    321330
     331    $extra_content = bp_nouveau_messages_catch_hook_content( array(
     332        'beforeLoop' => 'bp_before_member_messages_loop',
     333        'afterLoop'  => 'bp_after_member_messages_loop',
     334    ) );
     335
     336    if ( array_filter( $extra_content ) ) {
     337        $threads->extraContent = $extra_content;
     338    }
     339
     340    // Remove the bp_current_action() override.
     341    $bp->current_action = $reset_action;
     342
     343    // Return the successfull reply.
    322344    wp_send_json_success( $threads );
    323345}
  • branches/3.0/src/bp-templates/bp-nouveau/js/buddypress-messages.js

    r12116 r12134  
    355355            }
    356356
     357            if ( ! _.isUndefined( resp.extraContent ) ) {
     358                _.extend( this.options, _.pick( resp.extraContent, [
     359                    'beforeLoop',
     360                    'afterLoop'
     361                ] ) );
     362            }
     363
    357364            return resp.threads;
    358365        },
     
    467474    } );
    468475
     476    // Hook view
     477    bp.Views.Hook = bp.Nouveau.Messages.View.extend( {
     478        tagName: 'div',
     479        template  : bp.template( 'bp-messages-hook' ),
     480
     481        initialize: function() {
     482            this.model = new Backbone.Model( {
     483                extraContent: this.options.extraContent
     484            } );
     485
     486            this.el.className = 'bp-messages-hook';
     487
     488            if ( this.options.className ) {
     489                this.el.className += ' ' + this.options.className;
     490            }
     491        }
     492    } );
     493
    469494    bp.Views.messageEditor = bp.Nouveau.Messages.View.extend( {
    470495        template  : bp.template( 'bp-messages-editor' ),
     
    643668
    644669        initialize: function() {
    645             // Add the threads parent view
    646             this.views.add( new bp.Nouveau.Messages.View( { tagName: 'ul', id: 'message-threads', className: 'message-lists' } ) );
    647 
    648             // Add the preview Active Thread view
    649             this.views.add( new bp.Views.previewThread( { collection: this.collection } ) );
     670            var Views = [
     671                new bp.Nouveau.Messages.View( { tagName: 'ul', id: 'message-threads', className: 'message-lists' } ),
     672                new bp.Views.previewThread( { collection: this.collection } )
     673            ];
     674
     675            _.each( Views, function( view ) {
     676                this.views.add( view );
     677            }, this );
    650678
    651679            // Load threads for the active view
     
    663691            this.collection.fetch( {
    664692                data    : _.pick( this.options, 'box' ),
    665                 success : this.threadsFetched,
     693                success : _.bind( this.threadsFetched, this ),
    666694                error   : this.threadsFetchError
    667695            } );
     
    670698        threadsFetched: function() {
    671699            bp.Nouveau.Messages.removeFeedback();
     700
     701            // Display the bp_after_member_messages_loop hook.
     702            if ( this.collection.options.afterLoop ) {
     703                this.views.add( new bp.Views.Hook( { extraContent: this.collection.options.afterLoop, className: 'after-messages-loop' } ), { at: 1 } );
     704            }
     705
     706            // Display the bp_before_member_messages_loop hook.
     707            if ( this.collection.options.beforeLoop ) {
     708                this.views.add( new bp.Views.Hook( { extraContent: this.collection.options.beforeLoop, className: 'before-messages-loop' } ), { at: 0 } );
     709            }
    672710
    673711            // Inform the user about how to use the UI.
Note: See TracChangeset for help on using the changeset viewer.