Backend popup from the side menu

the same way i can call an ajax handler from a list controller in the backend,
i’d like to do the same from a simple sidemenu

currently we can do this:

# _list_toolbar.php
<a href="#" data-control="popup" data-handler="onCreateForm" data-request-data="create_mode: 1" class="btn btn-primary oc-icon-plus">
<?= e(trans('backend::lang.form.create')) ?>
</a>

and I’d like to call an handler from a sidemenu defined in the plugin.yaml for instance

new_course:
                label: menu.new_course
                icon: icon-plus
                url: voilaah/skillup/courses/create

but here we can only specify a url, nothing else.

How could we do this ?

Hey @chris,

You can add attributes to the navigation item and manipulate them using JavaScript.

For example:

promotions:
    label: Promotions
    url: xyz/website/promotions
    icon: icon-shopping-cart
    attributes:
        data-request: onHandler

Then, in a JavaScript file that gets loaded:

$(function () {
    $('li[data-request]').on('click', function (e) {
        e.preventDefault(); // Prevent default click behavior

        var requestHandler = $(this).attr('data-request'); // Get the request handler name

        // Trigger an AJAX request using OctoberCMS framework
        $(this).request(requestHandler);
    });
});

This is a functional example that you can adapt as needed. If necessary, you can also override the modules\backend\layouts\_submenu_items.php partial.

Hi @apinard
thanks for the suggestion.
Sounds like it is worth trying it out.

Would there be a way to get an existing controller context so I can just reuse the ajax Handler and the context (formModel etc, …) as I want show a popup with a formWidget.