Cor Bosman wrote:
Hi all, im working on a plugin that needs to do some ajax calls. It's all working, but im wondering if this is the right way to do it..
[...]
Up to here it was pretty straightforward. But i was fiddling a bit to get the ajax return correct. It's returning a JSON reply with an exec field that can execute a JS function. I ended up doing this in my js file, otherwise the function couldnt be found:
rcube_webmail.prototype.xs4all_greenlist_add_greenlist_row = function() { ..... }
This seems to be working, but i just want to make sure this is the correct way to handle this, before I end up having to change this plugin later on.
Hi Cor
It looks like we've overseen something when we implemented the API. To be honest, your use case is not yet respected in the current version of the API.
You're absolutely right, the only way to make use of the handy $OUTPUT->command('...') command is to add the callback function to the rcube_webmail prototype. Not a very nice solution.
One solution would be to pass the callback function reference to rcmail.http_post() but then your function gets the entire response and you cannot use $OUTPUT->command('...') on the server side.
Another way to solve this would be to send $OUTPUT->command('plugin.somecommand') and the client will then trigger an event. The client part of the plugin will have to register an event listener for 'plugin.somecommand'. This would be the callback function for the asynchronous request. To make things easier we would limit the number of arguments to one. Then it'll perfectly fit into the event-system of the RoundCube client.
What do you think, any other ideas?
~Thomas _______________________________________________ List info: http://lists.roundcube.net/dev/