joomla/joomla-platform — pull request #1596 by Chraneco (2012-10-11 13:25:17+00:00)
Title: Moving JResponse to its own package and adding JResponseJson

Hi,

this pull request is a replacement for #1470.

It 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.

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).