Skip to:
Content

BuddyPress.org

Changeset 12058


Ignore:
Timestamp:
05/05/2018 06:21:08 AM (18 months ago)
Author:
imath
Message:

BP Nouveau: use a JS Template for the feedbacks of the Messages UI

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/messages/index.php

    r12041 r12058  
    1313<div class="bp-messages-feedback"></div>
    1414<div class="bp-messages-content"></div>
     15
     16<script type="text/html" id="tmpl-bp-messages-feedback">
     17    <div class="bp-feedback {{data.type}}">
     18        <span class="bp-icon" aria-hidden="true"></span>
     19        <p>{{{data.message}}}</p>
     20    </div>
     21</script>
    1522
    1623<script type="text/html" id="tmpl-bp-messages-form">
  • trunk/src/bp-templates/bp-nouveau/includes/messages/ajax.php

    r12053 r12058  
    108108function bp_nouveau_ajax_messages_send_reply() {
    109109    $response = array(
    110         'feedback' => '<div class="bp-feedback error"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'There was a problem sending your reply. Please try again.', 'buddypress' ) . '</p></div>',
     110        'feedback' => __( 'There was a problem sending your reply. Please try again.', 'buddypress' ),
    111111        'type'     => 'error',
    112112    );
     
    187187    wp_send_json_success( array(
    188188        'messages' => array( $reply ),
    189         'feedback' => '<div class="bp-feedback success"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Your reply was sent successfully', 'buddypress' ) . '</p></div>',
     189        'feedback' => __( 'Your reply was sent successfully', 'buddypress' ),
    190190        'type'     => 'success',
    191191    ) );
     
    200200    if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'bp_nouveau_messages' ) ) {
    201201        wp_send_json_error( array(
    202             'feedback' => '<div class="bp-feedback error"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Unauthorized request.', 'buddypress' ) . '</p></div>',
     202            'feedback' => __( 'Unauthorized request.', 'buddypress' ),
    203203            'type'     => 'error'
    204204        ) );
     
    215215    if ( ! bp_has_message_threads( bp_ajax_querystring( 'messages' ) ) ) {
    216216        wp_send_json_error( array(
    217             'feedback' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Sorry, no messages were found.', 'buddypress' ) . '</p></div>',
     217            'feedback' => __( 'Sorry, no messages were found.', 'buddypress' ),
    218218            'type'     => 'info'
    219219        ) );
     
    342342    if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'bp_nouveau_messages' ) ) {
    343343        wp_send_json_error( array(
    344             'feedback' => '<div class="bp-feedback error"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Unauthorized request.', 'buddypress' ) . '</p></div>',
     344            'feedback' => __( 'Unauthorized request.', 'buddypress' ),
    345345            'type'     => 'error'
    346346        ) );
     
    348348
    349349    $response = array(
    350         'feedback' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Sorry, no messages were found.', 'buddypress' ) . '</p></div>',
     350        'feedback' => __( 'Sorry, no messages were found.', 'buddypress' ),
    351351        'type'     => 'info'
    352352    );
     
    435435function bp_nouveau_ajax_delete_thread_messages() {
    436436    $response = array(
    437         'feedback' => '<div class="bp-feedback error"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'There was a problem deleting your message(s). Please try again.', 'buddypress' ) . '</p></div>',
     437        'feedback' => __( 'There was a problem deleting your message(s). Please try again.', 'buddypress' ),
    438438        'type'     => 'error',
    439439    );
     
    458458
    459459    wp_send_json_success( array(
    460         'feedback' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Message(s) deleted', 'buddypress' ) . '</p></div>',
     460        'feedback' => __( 'Message(s) deleted', 'buddypress' ),
    461461        'type'     => 'success',
    462462    ) );
     
    480480
    481481    $response = array(
    482         'feedback' => '<div class="bp-feedback error"><span class="bp-icon" aria-hidden="true"></span><p>' . esc_html( $error_message ) . '</p></div>',
     482        'feedback' => esc_html( $error_message ),
    483483        'type'     => 'error',
    484484    );
     
    556556
    557557    wp_send_json_success( array(
    558         'feedback' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . esc_html( $success_message ) . '</p></div>',
     558        'feedback' => esc_html( $success_message ),
    559559        'type'     => 'success',
    560560        'messages' => $messages,
     
    579579    if ( 'unread' === $action ) {
    580580        $response = array(
    581             'feedback' => '<div class="bp-feedback error"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'There was a problem marking your message(s) as unread. Please try again.', 'buddypress' ) . '</p></div>',
     581            'feedback' => __( 'There was a problem marking your message(s) as unread. Please try again.', 'buddypress' ),
    582582            'type'     => 'error',
    583583        );
     
    597597
    598598    if ( 'unread' === $action ) {
    599         $response['feedback'] = '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Message(s) marked as unread.', 'buddypress' ) . '</p></div>';
     599        $response['feedback'] = __( 'Message(s) marked as unread.', 'buddypress' );
    600600    } else {
    601         $response['feedback'] = '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Message(s) marked as read.', 'buddypress' ) . '</p></div>';
     601        $response['feedback'] = __( 'Message(s) marked as read.', 'buddypress' );
    602602    }
    603603
  • trunk/src/bp-templates/bp-nouveau/includes/messages/functions.php

    r12054 r12058  
    9999            'send' => wp_create_nonce( 'messages_send_message' ),
    100100        ),
    101         'loading' => '<div class="bp-feedback info"><span class="bp-icon" aria-hidden="true"></span><p>' . __( 'Loading messages. Please wait.', 'buddypress' ) . '</p></div>',
     101        'loading' => __( 'Loading messages. Please wait.', 'buddypress' ),
    102102        'bulk_actions' => bp_nouveau_messages_get_bulk_actions(),
    103103    );
  • trunk/src/bp-templates/bp-nouveau/js/buddypress-messages.js

    r12053 r12058  
    453453        tagName: 'div',
    454454        className: 'bp-messages bp-user-messages-feedback',
     455        template  : bp.template( 'bp-messages-feedback' ),
    455456
    456457        initialize: function() {
    457             this.value = this.options.value;
    458 
    459             if ( this.options.type ) {
    460                 this.el.className += ' ' + this.options.type;
    461             }
    462         },
    463 
    464         render: function() {
    465             this.$el.html( this.value );
    466             return this;
     458            this.model = new Backbone.Model( {
     459                type: this.options.type || 'info',
     460                message: this.options.value
     461            } );
    467462        }
    468463    } );
Note: See TracChangeset for help on using the changeset viewer.