getPickListFilterCriteria(),zend framework and $_GET request

Hi there,

When i use the following code (last code box) it sends a get request:

GET /skills_dev/data/skill/?category_id=57

This is fine but the problem is for Zend Framework to understand the request it has to be formatted like so:

GET /skills_dev/data/skill/category_id/57/

If there anyway I can format how the $_GET request is sent with getPickListFilterCriteria? Hope this makes sense :slight_smile:

editorProperties:{
     getPickListFilterCriteria : function () {
          var category = this.grid.getEditedCell(this.rowNum, "skill_category_name");
					
          return {category_id:category};
				 }
	}
},

The RestDataSource is as close as you get and it doesn’t dynamically generate the URL as you want. I have derived a RestfulDataSource that does this but I haven’t completed it as a standalone release as of yet - error handling is minimal. I have only used the JSON mode as well.

I based the URL handling on the URI template proposal and an implementation from here. I did have to make some modifications to handle 0 values.

Be aware that there are some tricks to handling PUT and POST operations with actual JSON messages. You can find earlier discussions in the wish list forum.

If you are interested in testing my work-in-progress, let me know.

dave

Dave - that project sounds great - have you also made a stab at implementing queuing for REST?

eholmstrom - on the actual mechanics of putting together the correct URL, you want to override dataSource.transformResponse and replace the actionURL with a URL derived by adding the category_id, which you’ll find in dsRequest.data.category_id in this case.

Isomorphic - No I haven’t looked deeply at queuing. It was not obvious how to tie into that mechanism.

For URL translation, I overrode getDataURL as:

    getDataURL: function(dsRequest) {
        var type = dsRequest.operationType;

        var uriTemplate = this.getDataUriTemplate(type);
        if (uriTemplate != null) {
            var uri;
            if (isc.isAn.Array(dsRequest.originalData) || (dsRequest.originalData.Class && dsRequest.originalData.Class == "Array"))
                uri = uriTemplate.expand(dsRequest.originalData[0]);
            else
                uri = uriTemplate.expand(dsRequest.originalData);

            // Remove any trailing spaces (escaped)
            while (uri.endsWith("%20"))
                uri = uri.substring(0, uri.length - 3);
            return uri;
        }
        return this.Super("getDataURL", arguments);
    },

This lets me create a URL based on the template and data/criteria of the request. In transformRequest() I remove the fetch criteria that was included in the template so it isn’t replicated. For searches criteria is still used on the templated URI.

I posted a link to my RestfulDataSource in another thread but I would like to get further information on supporting queuing if it is available.

Thanks!
dave

To do queuing for a RestDataSource you essentially want to combine the techniques shown for Google Gears integration discussed here with the techniques for dealing with XML documents that populate multiple components, discussed here.

The actual DataSource will be marked clientOnly:true and hence will not make a network request dsRequests are performed. To avoid components receiving a response from the client-only request, remove the callback from within transformRequest. Then just hold onto all dsRequests until you decide to send the queue.

Use a second DataSource, or multiple DataSources describing a compound request format, to serialize all DSRequests into a single XML message, which can be posted via direct use of the RPCManager.

Decompose the response into separate sections and form DSResponses from them, then fire the callbacks originally specified on the DSRequests, emulating what a normal DataSource would do.

Isomorphic hasn’t verified that this entire subsystem can be built without either modifying or forking core framework code, but this is the general outline of what you’d need to do to build a Restful DataSource capable of generic queuing.

Sorry about the late reply. Just for anyone else this is what i end up applying to the particullar database.

transformRequest: function (dsRequest) {
		if(dsRequest.operationType == "fetch"){
			//build url for Zend Framework
			var zend ="";
			for(var key in dsRequest.data) {
				zend = zend+key+'/'+dsRequest.data[key]+'/';
			}
			dsRequest.actionURL ="/skills_dev/data/skill/"+zend;
			//return dsRequest.data;
		}
	}
}