Skip to:
Content
Pages
Categories
Search
Top
Bottom

Ajax problem

  • Avatar of harryko
    harryko
    Participant

    @harryko

    Hi,
    i’m trying to understand ajax in buddypress.
    I’m using a child theme of buddyboss and the last release of buddypress.
    I’m looking in the messages pages.
    i’ve the default menu :

    <div id="subnav" class="item-list-tabs" role="navigation">
    <ul>
    <li id="inbox-personal-li" class="current selected">
    <a id="inbox" href="http://localhost/proto-metronic/members/admin/messages/">Inbox</a>
    </li>
    <li id="sentbox-personal-li">
    <a id="sentbox" href="http://localhost/proto-metronic/members/admin/messages/sentbox/">Sent</a>
    </li>
    <li id="compose-personal-li">
    <a id="compose" href="http://localhost/proto-metronic/members/admin/messages/compose/">Compose</a>
    </li>
    <li id="notices-personal-li">
    <a id="notices" href="http://localhost/proto-metronic/members/admin/messages/notices/">Notices</a>
    </li>
    </ul>
    </div>

    As I understand I remove the “no-ajax” class in the div.
    So when I click on a link like inbox it send a request ajax to admin_ajax.php,
    with the action inbox_filter.
    It returns me a “0″ as answer.
    Where can I find the hook for “inbox_filter” or do you have a link or tutorial to learn how to create this functionnality?

    Thanks in advance
    HK

Viewing 7 replies - 1 through 7 (of 7 total)
  • Avatar of henrywright
    henrywright
    Participant

    @henrywright

    Hi @harryko

    I don’t understand your question or what you’re trying to achieve. Is it possible for you to explain in more detail?

    Avatar of harryko
    harryko
    Participant

    @harryko

    No problem,
    I would to use the ajax function to navigate in buddypress.
    In my messages page I would like that when a user click on “send”, it uses Ajax instead of
    go to the page.
    I remove the “no-ajax” in the div and when you click on “send” button et send an ajax request to admin-ajax.php but nothing append it just returns “0″.
    I see an ajax request with the action “sendbox_filter” but can’t find where it’s define.

    So I would like to know,
    If ajax actions are already define in buddypress and then how to use it (inbox_filter, sendbox_filter)?
    Or if i have to define my own ajax actions?

    Avatar of henrywright
    henrywright
    Participant

    @henrywright

    Take a look at buddypress/bp-templates/bp-legacy/js/buddypress.js around line 1422. There you will find the AJAX request (and response) you’re talking about along with many more AJAX actions. On top of those, you can of course create your own :)

    Avatar of harryko
    harryko
    Participant

    @harryko

    Thanks for your answer.
    One more question :
    I would like to add css class to my subnav message menu item.
    change this

    <li id="notices-personal-li">
    <a id="notices" href="http://***/members/admin/messages/notices/">Notices</a>
    </li>

    to this

    <li id="menu_subnav">
    <a id="notices" href="http://****/members/admin/messages/notices/">Notices</a>
    </li>

    I can’t find how to do..
    If you have a link

    Thanks
    HK

    Avatar of henrywright
    henrywright
    Participant

    @henrywright

    I would like to add css class to my subnav message menu item.

    Looking at your code, I think you mean change the list item’s ID?

    You can do that if you make use of BP’s template hierarchy. See this link for more info:

    http://codex.buddypress.org/themes/theme-compatibility-1-7/template-hierarchy/#overview-of-template-hierarchy-in-buddypress

    Avatar of harryko
    harryko
    Participant

    @harryko

    Yes it’s the “id”.
    Day are little bit long…
    I’m using this in a child theme.
    To load my menu I use :
    <?php bp_get_options_nav(); ?>

    But If I understand I have to create my own menu, there’s no functions to add or modify id of the menu?

    Avatar of harryko
    harryko
    Participant

    @harryko

    Here is my code, to replace the ID and add class to my menu

    function get_subnav_options() {
        global $bp;
    
        $component_index = !empty( $bp->displayed_user ) ? bp_current_component() : bp_get_root_slug( bp_current_component() );
        if ( !bp_is_single_item() ) {
            if ( !isset( $bp->bp_options_nav[$component_index] ) || count( $bp->bp_options_nav[$component_index] ) < 1 ) {
                return false;
            } else {
                $the_index = $component_index;
            }
        } else {
            if ( !isset( $bp->bp_options_nav[bp_current_item()] ) || count( $bp->bp_options_nav[bp_current_item()] ) < 1 ) {
                return false;
            } else {
                $the_index = bp_current_item();
            }
        }
    
        // Loop through each navigation item
        foreach ( (array) $bp->bp_options_nav[$the_index] as $subnav_item ) {
            if ( !$subnav_item['user_has_access'] )
                continue;
    
            // If the current action or an action variable matches the nav item id, then add a highlight CSS class.
            if ( $subnav_item['slug'] == bp_current_action() ) {
                $selected = 'active';
            } else {
                $selected = '';
            }
            // echo out the final list item
            echo apply_filters( 'bp_get_options_nav_' . $subnav_item['css_id'], '<li class="inbox '.$selected.'"><a class="btn" id="' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>', $subnav_item );
        }
    
    }

    Thanks for your Help
    HK

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.