Jx.JxJsonReaderRest

This class is used by the application to interact with the REST Web services provided by the platform. It overrides the readResponse method of Ext.data.JsonReader to convert JsonData received from the REST service to the data that can be interpreted by EXT JS.


/**
 * @class Jx.JxJsonReader
 * This is a class which should be used by apps to interract with 
 * the REST web services provided by the platform.
 */
Jx.JxJsonReaderRest = Ext.extend(Ext.data.JsonReader, {
    readResponse: function (action, response) {
        var o = {};
        if (response.status >= 200 && response.status <= 300) {
            o[this.meta.successProperty] = true;
        } else if (response.status == 403) {
            o[this.meta.successProperty] = false;
        }
        // Avoid No Content
        if (response.status !== 204) {
            var resp = (response.responseText !== undefined) ? Ext.decode(response.responseText) : response;
            if (resp) {
                for (var i in resp) {
                    o[this.meta.root] = resp[i];
                }
            }
            if (!o[this.meta.root]) {
                throw new Ext.data.JsonReader.Error('response');
            }
        }
        // instantiate response object
        var res = new Ext.data.Response({
            action: action,
            success: this.getSuccess(o),
            data: o[this.meta.root],
            message: this.getMessage(o),
            raw: o
        });
        // Need to return additional status code
        return res;
    }
});