0

I'm using Sonata for a specific need in a project.

Indeed, I made a JS interface (with ExtJS) which has only one page, and every button just call an AJAX request to display something. So the page is never reloaded. The URL is like www.blob.com/blob

A button is supposed to call the Sonata Admin Interface via AJAX call. It works, the Admin Interface is displayed inside a, ExtJS container.

But then, when I click on a button inside the Admin Interface (like the add button), it redirects me to the Sonata Admin URL, like www.blob.com/admin/dashboard/list/add, etc.

So then, I want all the buttons in to the Sonata Admin Interface to use AJAX instead of refreshing pages.

I found out this answer How to use Ajax within Sonata Admin forms? which is pretty nice. But I can't barely understand it, and it seems to fit only for a specific need.

Does anyone know a solution that could be "easy" to handle. Because for the moment the only solution I see is to edit all the AdminClass and Controllers of my Bundle (~50).

Thanks, with the hope I've been clear as possible.

Community
  • 1
  • 1

1 Answers1

0

I think you can catch using Javascript all click events on links (<a> tags) with class sonata-ba-action to be handled in AJAX.

Something like:

jQuery('a.sonata-ba-action').on('click', function (e) {
    var url = jQuery(this).attr('href');

    jQuery.get(url, function (data) {
        jQuery('#yourContainer').html(data);
    });

    return false;
});
  • Hmhmh, interesting. I'll check it out, could be great if that works ! –  Jan 06 '14 at 15:11
  • Hmhmhm, seems like I did not make it work. I've tried to add a alert('ok'); in your code but nothing is displayed, so I guess the function is not triggering anything with this a.sonata-ba-action. –  Jan 06 '14 at 16:57
  • By the way, are you sure that a.sonata-ba-action is the right way to refer the contains in an object that have the sonata-ba-action class ? –  Jan 06 '14 at 17:14
  • You also have to catch all form submit buttons (I think you can use their name to do that with only Sonata Admin submit buttons). I propose you a solution but I haven't do that anymore. – Vincent Composieux Jan 07 '14 at 11:45
  • Yeah ok I get the point, but it seems really tedious to do. Your first solution looked interesting but it does not work for the moment, and don't know if it will :(. –  Jan 07 '14 at 12:26