joomla/joomla-platform — pull request #1470 by Chraneco (2012-08-18 23:27:02+00:00)
Title: Moving JResponse to its own package and adding JResponseJson for Ajax requests

Hi,

the handling of Ajax requests in the installer of Joomla! is imho very good and I think it's time to standardize this a bit.
This pull request introduces a new class JResponseJson which is able to simplify things with Ajax requests.

- Using the flag success the JavaScript code (whether Mootools JRequest.JSON or jQuery.getJSON) can check whether the task was successful or not and react accordingly (If the request itself failes the error event of the JavaScript API can be used).
- Then, the actual response data (if any) can be retrieved from data in the JSON object and
- optionally a main response message from message.
- Additionally all gathered messages in the JApplication message queue are also automatically sent back in messages. I'm not sure what will happen with that part because the message queue is only in the legacy application class at the moment without any replacement, but it's very useful at this point. The dependencies are checked afore.

If you have a look at the 'strings.json' controller of language override manager in the CMS you can see how it is working (it is included there already as a helper class with another name).

Another advantage is that no $app->close(); is necessary anymore if the Ajax request is done with 'format=json' because the already existing API handles the rest. Just echo the response object at the end of the task.

With this pull request the class can be added to the platform so that it can be used for any application.
For example, in the CMS it could replace the current code in the installer and the language override manager. I saw that Finder and the media manager could also be adapted for using this class. If this pull request is accepted I can standardize this in the CMS.

I'm not sure whether the unit tests are written as expected (it's the first time I coded some).