Currently, When you change some routes path and method,
you have to review all javascript codes which refer to these routes.
But generally, the Controller.action name less change.
So I made a tag to export routes and a javascript class
for AJAX oriented application.
I made a first version of the $.ajax function to simplify it.
For instance :
# Routes
POST /contact/{contactid}/rename Contact.rename
// In Contact.java :
public static void rename (Long contactid, String newname);
In javascript :
var contactid;
var newname;
/* With jQuery we must write : */
$.ajax({
type: "POST",
url: "/contact/"+contactid+"/rename",
data: {newname:newname},
dataType: "json",
success: function(data) {
// do something
},
error: function(data) {
// do something
}
});
/* Now with my system, you write simply : */
var myLibraryPath = "application.routes"; // for example
myLibraryPath.ajax("Contact.rename", {contactid:contactid,
newname:newname});
So you don't have to worry about the path and the method of the route
but only the controller.action name and the data to send (so you only
have to know the java method signature).
You don't see the callback function because I formalism them :
If success we trigger an event like this : $().trigger
("Contact.rename", data);
If error : "Contact.rename.error" is triggered.
But maybe I can manage a third arguments to override jquery ajax
options you want (except type, url, data and dataType).
I have some others idea to more simplify an ajax-oriented application.
Maybe we can create a module to regroup them later ?
For the moment I created a branch to share my routes javascript
exporter :
https://code.launchpad.net/~gre/play/routes_js_export
It's so experimental for the moment, but I will improve it in the
future.
Best regards,
Gaetan